diff --git a/tests/GameCult.Caching.Tests/UnionArmGuardTests.cs b/tests/GameCult.Caching.Tests/UnionArmGuardTests.cs index e6a11309..eed82076 100644 --- a/tests/GameCult.Caching.Tests/UnionArmGuardTests.cs +++ b/tests/GameCult.Caching.Tests/UnionArmGuardTests.cs @@ -357,43 +357,44 @@ namespace GameCult.Caching.Tests Assert.That(Convert.ToHexString(plainBytes), Is.EqualTo(Convert.ToHexString(MessagePackSerializer.Serialize(plain, CultDocumentMessagePackSerialization.Options)))); } - // StandardResolverAllowPrivate cannot always build a formatter (a private readonly [Key] field has no constructor to - // fill it). That is not an escape from the claim check: a resolver formatting such a type is refused like any other. + // StandardResolverAllowPrivate cannot always build a formatter (a private [Key] delegate member has none). That is not an + // escape from the claim check: a resolver formatting such a type is refused like any other. [Test] public void AFormatterThatStandardResolverAllowPrivateCannotBuildStillClaims() { - var registry = CultDocumentRegistry.ForTypes(new[] { typeof(ApRoDoc) }); - var doc = new ApRoDoc { Id = "r1", Items = { new ApRoArm { Id = "00000000000c" } } }; + var registry = CultDocumentRegistry.ForTypes(new[] { typeof(ApHookDoc) }); + var doc = new ApHookDoc { Id = "r1", Items = { new ApHookArm { Id = "00000000000c" } } }; - var thrown = Assert.Throws(() => CultDocumentMessagePackSerialization.SerializeUntyped(doc, typeof(ApRoDoc), registry))!; + var thrown = Assert.Throws(() => CultDocumentMessagePackSerialization.SerializeUntyped(doc, typeof(ApHookDoc), registry))!; - Assert.That(thrown.Message, Does.Contain(nameof(ListClaimResolver)).And.Contain(nameof(ApRoArm))); + Assert.That(thrown.Message, Does.Contain(nameof(ListClaimResolver)).And.Contain(nameof(ApHookArm))); } [MessagePackObject] - public sealed class ApRoArm + public sealed class ApHookArm { [Key(0)] [CultElementId] public string Id = string.Empty; - [Key(1)] private readonly int fixedValue = 3; - [IgnoreMember] public int FixedValue => fixedValue; +#pragma warning disable CS0169, CS0649 + [Key(1)] private Action? hook; +#pragma warning restore CS0169, CS0649 } - [CultDocument("tests.ap_ro_doc", "tests.ap_ro_doc.v1")] + [CultDocument("tests.ap_hook_doc", "tests.ap_hook_doc.v1")] [MessagePackObject] - public sealed class ApRoDoc + public sealed class ApHookDoc { [Key(0)] [CultName] public string Id = string.Empty; - [Key(1)] public List Items = new(); + [Key(1)] public List Items = new(); } - private sealed class ApRoFormatter : IMessagePackFormatter + private sealed class ApHookFormatter : IMessagePackFormatter { - public void Serialize(ref MessagePackWriter writer, ApRoArm value, MessagePackSerializerOptions options) => writer.WriteNil(); + public void Serialize(ref MessagePackWriter writer, ApHookArm value, MessagePackSerializerOptions options) => writer.WriteNil(); - public ApRoArm Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) + public ApHookArm Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { reader.Skip(); - return new ApRoArm(); + return new ApHookArm(); } } @@ -497,7 +498,7 @@ namespace GameCult.Caching.Tests if (typeof(T) == typeof(List)) return (IMessagePackFormatter)(object)new ValuesFormatter(); if (typeof(T) == typeof(List)) return (IMessagePackFormatter)(object)new PointsFormatter(); if (typeof(T) == typeof(FbArm)) return global::MessagePack.Resolvers.StandardResolver.Instance.GetFormatter(); - if (typeof(T) == typeof(ApRoArm)) return (IMessagePackFormatter)(object)new ApRoFormatter(); + if (typeof(T) == typeof(ApHookArm)) return (IMessagePackFormatter)(object)new ApHookFormatter(); if (typeof(T) == typeof(ApArm) || typeof(T) == typeof(ApDoc) || typeof(T) == typeof(List) || typeof(T) == typeof(ApPlainArm) || typeof(T) == typeof(ApPlainDoc) || typeof(T) == typeof(List)) return global::MessagePack.Resolvers.StandardResolverAllowPrivate.Instance.GetFormatter();