From 5ea97b44a7e0bcc6122e66c765968ce99ca53a1d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 23 Oct 2026 04:14:02 +0200 Subject: [PATCH] CachelessSingleFileTests: WriteDocument plans ids by the declared type (S9) Co-Authored-By: Claude Sonnet 5.5 --- .../CachelessSingleFileTests.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/GameCult.Caching.Tests/CachelessSingleFileTests.cs b/tests/GameCult.Caching.Tests/CachelessSingleFileTests.cs index defcc133..60ca7970 100644 --- a/tests/GameCult.Caching.Tests/CachelessSingleFileTests.cs +++ b/tests/GameCult.Caching.Tests/CachelessSingleFileTests.cs @@ -233,6 +233,19 @@ namespace GameCult.Caching.Tests Assert.That(snapshot.Records.Single().Payload, Is.EqualTo(CultDocumentMessagePackSerialization.SerializeUntyped(new IdBase { Name = "n" }, typeof(IdBase), registry))); } + // The id plan comes from the declared type too: an unset id that only the derived type holds is not the stored document's, so + // it is not minted into the caller's object. + [Test] + public void WriteDocumentMintsIdsOfTheDeclaredTypeNotTheRuntimeType() + { + var registry = CultDocumentRegistry.ForTypes(new[] { typeof(IdBase) }); + var derived = new IdDerived { Name = "n", Reels = { new IdReel { Label = "r" } } }; + + new SingleFileMessagePackBackingStore(_path).WriteDocument(new CultRecordKey("d"), derived, registry: registry); + + Assert.That(derived.Reels.Single().Id, Is.Null.Or.Empty, "an id outside the declared type is left unset"); + } + // No call leaves its registry on the store: after a write, a refused write and WriteRecord, the store holds none. [Test] public void NoCacheCallLeavesARegistryOnTheStore()