UnionArmGuardTests: the unbuildable-AllowPrivate claim test uses a private delegate member
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
70ffa2af9a
commit
8ddb8a03e1
1 changed files with 18 additions and 17 deletions
|
|
@ -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<InvalidOperationException>(() => CultDocumentMessagePackSerialization.SerializeUntyped(doc, typeof(ApRoDoc), registry))!;
|
||||
var thrown = Assert.Throws<InvalidOperationException>(() => 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<ApRoArm> Items = new();
|
||||
[Key(1)] public List<ApHookArm> Items = new();
|
||||
}
|
||||
|
||||
private sealed class ApRoFormatter : IMessagePackFormatter<ApRoArm>
|
||||
private sealed class ApHookFormatter : IMessagePackFormatter<ApHookArm>
|
||||
{
|
||||
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<LcValue>)) return (IMessagePackFormatter<T>)(object)new ValuesFormatter();
|
||||
if (typeof(T) == typeof(List<Pair>)) return (IMessagePackFormatter<T>)(object)new PointsFormatter();
|
||||
if (typeof(T) == typeof(FbArm)) return global::MessagePack.Resolvers.StandardResolver.Instance.GetFormatter<T>();
|
||||
if (typeof(T) == typeof(ApRoArm)) return (IMessagePackFormatter<T>)(object)new ApRoFormatter();
|
||||
if (typeof(T) == typeof(ApHookArm)) return (IMessagePackFormatter<T>)(object)new ApHookFormatter();
|
||||
if (typeof(T) == typeof(ApArm) || typeof(T) == typeof(ApDoc) || typeof(T) == typeof(List<ApArm>) ||
|
||||
typeof(T) == typeof(ApPlainArm) || typeof(T) == typeof(ApPlainDoc) || typeof(T) == typeof(List<ApPlainArm>))
|
||||
return global::MessagePack.Resolvers.StandardResolverAllowPrivate.Instance.GetFormatter<T>();
|
||||
|
|
|
|||
Loading…
Reference in a new issue