Path: redb/redb.Tests.Integration/Tests/Unit/WalkerPropertyRuleTests.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/WalkerPropertyRuleTests.cs ---- using System.Reflection; using redb.Core.Attributes; using redb.Core.Models.Contracts; using redb.Core.Models.Entities; using redb.Core.Pro.Materialization; using redb.Core.Providers; using redb.Core.Utils; namespace redb.Tests.Integration.Tests.Unit; /// /// The /// scheme and the save take every public instance property except and read it without /// a catch - a throwing getter fails the save. The graph walkers of a load read [RedbIgnore] properties too and /// swallowed whatever a getter threw. Now they walk the save's property set and let a getter's exception surface. /// public class WalkerPropertyRuleTests { private sealed class Counter { public int Value; } private sealed class PropsWithIgnoredGetter { public string Label { get; set; } = "props"; [RedbIgnore] public Counter Reads { get; } = new(); [RedbIgnore] public string Technical { get { Reads.Value++; return "technical"; } } } public sealed class PropsWithThrowingGetter { public string Label { get; set; } = "props"; public int Total => throw new InvalidOperationException("computed getter"); } private static void InvokeCollectBareStubs(object node) { var method = typeof(ProLazyPropsLoader).GetMethod("CollectBareStubs", BindingFlags.NonPublic | BindingFlags.Static) ?? throw new InvalidOperationException("ProLazyPropsLoader.CollectBareStubs not found - update this test"); method.Invoke(null, new object[] { node, new Dictionary>(), new HashSet(ReferenceEqualityComparer.Instance) }); } public static IEnumerable Walkers() => [ ["loader install", (Action)(props => LazyReferenceInstaller.InstallInto(props, new NoopLoader()))], ["mark unloaded", (Action)(props => LazyReferenceInstaller.MarkUnloadedWherePropsAreNull(props))], ["dirty guard", (Action)(props => LoadedGraphInspector.HasDirtyLoadedReference(props))], ["Pro stub collector", (Action)InvokeCollectBareStubs], ]; [Theory] [MemberData(nameof(Walkers))] public void Walker_DoesNotReadRedbIgnoreProperties(string walker, Action walk) { var props = new PropsWithIgnoredGetter(); walk(props); props.Reads.Value.Should().Be(0, $"{walker}: a [RedbIgnore] property is not redb's - the scheme and the save never read it"); } [Theory] [MemberData(nameof(Walkers))] public void Walker_ThrowingGetter_Surfaces(string walker, Action walk) { var act = () => walk(new PropsWithThrowingGetter()); act.Should().Throw($"{walker}: a getter that throws fails the walk as it fails the save, it is not swallowed") .Which.GetBaseException().Should().BeOfType(); } [Fact] public void PropsHash_ThrowingGetter_Surfaces() { var act = () => RedbHash.ComputeForProps(new PropsWithThrowingGetter()); act.Should().Throw("the hash does not stand in an empty string for a getter that threw") .Which.GetBaseException().Should().BeOfType(); } private sealed class NoopLoader : ILazyPropsLoader { public TProps? LoadProps(long objectId, long schemeId) where TProps : class, new() => null; public Task LoadPropsAsync(long objectId, long schemeId, CancellationToken cancellationToken = default) where TProps : class, new() => Task.FromResult(null); public Task LoadPropsForManyAsync(List> objects, CancellationToken cancellationToken = default) where TProps : class, new() => Task.CompletedTask; public Task LoadPropsForManyAsync(List> objects, HashSet? projectedStructureIds, CancellationToken cancellationToken = default) where TProps : class, new() => Task.CompletedTask; public Task LoadPropsForManyAsync(List> objects, int? propsDepth, CancellationToken cancellationToken = default) where TProps : class, new() => Task.CompletedTask; public Task LoadPropsForManyAsync(List> objects, HashSet? projectedStructureIds, int? propsDepth, CancellationToken cancellationToken = default) where TProps : class, new() => Task.CompletedTask; } }