Path: redb/redb.Tests.Integration/Tests/Unit/SchemeHashCalculatorTests.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/Unit/SchemeHashCalculatorTests.cs
----
using redb.Core.Models.Entities;
using redb.Core.Utils;
namespace redb.Tests.Integration.Tests.Unit;
///
/// The scheme structure hash drives every cache invalidation (metadata cache, structure tree, Pro
/// registry): a marker that changes what the builders emit must change the hash. V4 added two such
/// markers - the unique-key flag (UNIQUE §4.10) and the lazy-reference marker (LAZY §6).
///
public class SchemeHashCalculatorTests
{
private static Guid HashOf(bool? unique, bool? lazy) =>
SchemeHashCalculator.ComputeSchemeStructureHash(new List
{
new() { Id = 1, IdScheme = 7, IdType = RedbTypeIds.String, Name = "Code", Order = 1, Unique = unique, Lazy = lazy },
new() { Id = 2, IdScheme = 7, IdType = RedbTypeIds.Object, Name = "Next", Order = 2 },
});
[Fact]
public void UniqueFlag_IsPartOfTheHash()
{
HashOf(true, null).Should().NotBe(HashOf(false, null), "a key appearing or disappearing must invalidate the caches");
HashOf(true, null).Should().NotBe(HashOf(null, null));
}
[Fact]
public void LazyMarker_IsPartOfTheHash()
{
HashOf(null, true).Should().NotBe(HashOf(null, false), "virtual appearing or disappearing must invalidate the caches");
HashOf(null, true).Should().NotBe(HashOf(null, null));
}
[Fact]
public void SameStructures_SameHash()
{
HashOf(true, true).Should().Be(HashOf(true, true));
}
}