Update serializer defaults and enhance IId reference tests

Changed AcBinarySerializerOptions defaults: UseMetadata is now false, UseGeneratedCode is now true. Improved IId reference tests by adding UseMetadata option, new null and reference identity assertions, and refactored assertion order for clarity. These changes ensure more robust test coverage and align default serializer behavior with expected usage.
This commit is contained in:
Loretta 2026-02-26 07:20:53 +01:00
parent 60f963bb36
commit 686424b813
2 changed files with 15 additions and 6 deletions

View File

@ -124,7 +124,8 @@ public class AcBinarySerializerIIdReferenceTests
var options = new AcBinarySerializerOptions var options = new AcBinarySerializerOptions
{ {
ReferenceHandling = mode, ReferenceHandling = mode,
UseGeneratedCode = useSgen UseGeneratedCode = useSgen,
UseMetadata = useMeta
}; };
Console.WriteLine($"\n========== ReferenceHandling: {options.ReferenceHandling}, UseSgen: {options.UseGeneratedCode}, UseMeta: {options.UseMetadata} =========="); Console.WriteLine($"\n========== ReferenceHandling: {options.ReferenceHandling}, UseSgen: {options.UseGeneratedCode}, UseMeta: {options.UseMetadata} ==========");
@ -138,6 +139,10 @@ public class AcBinarySerializerIIdReferenceTests
Console.WriteLine($"Binary size: {binary.Length} bytes"); Console.WriteLine($"Binary size: {binary.Length} bytes");
Console.WriteLine($"ObjectRef count: {objectRefCount}"); Console.WriteLine($"ObjectRef count: {objectRefCount}");
Assert.IsNotNull(result, $"[{mode}] Deserialized result is null");
Assert.IsNotNull(result.Parent);
Assert.IsNotNull(result.Owner);
// Assert based on mode // Assert based on mode
switch (mode) switch (mode)
{ {
@ -152,6 +157,8 @@ public class AcBinarySerializerIIdReferenceTests
// IId types should have reference identity // IId types should have reference identity
Assert.AreSame(result.PrimaryTag, result.Items[0].Tag, $"[{mode}] Tag reference identity failed"); Assert.AreSame(result.PrimaryTag, result.Items[0].Tag, $"[{mode}] Tag reference identity failed");
Assert.AreSame(result.Owner, result.Items[0].Assignee, $"[{mode}] User reference identity failed"); Assert.AreSame(result.Owner, result.Items[0].Assignee, $"[{mode}] User reference identity failed");
Assert.AreSame(result, result.Items[1].ParentOrder);
Assert.AreSame(result.Parent, result.Items[1]);
break; break;
case ReferenceHandlingMode.All: case ReferenceHandlingMode.All:
@ -159,14 +166,16 @@ public class AcBinarySerializerIIdReferenceTests
Assert.IsTrue(objectRefCount >= 4, $"[{mode}] Expected at least 4 ObjectRefs, found {objectRefCount}"); Assert.IsTrue(objectRefCount >= 4, $"[{mode}] Expected at least 4 ObjectRefs, found {objectRefCount}");
Assert.AreSame(result.PrimaryTag, result.Items[0].Tag, $"[{mode}] Tag reference identity failed"); Assert.AreSame(result.PrimaryTag, result.Items[0].Tag, $"[{mode}] Tag reference identity failed");
Assert.AreSame(result.Owner, result.Items[0].Assignee, $"[{mode}] User reference identity failed"); Assert.AreSame(result.Owner, result.Items[0].Assignee, $"[{mode}] User reference identity failed");
Assert.AreSame(result, result.Items[1].ParentOrder);
Assert.AreSame(result.Parent, result.Items[1]);
// Non-IId should also have reference identity in All mode // Non-IId should also have reference identity in All mode
Assert.AreSame(result.Owner.Preferences, result.Items[0].Assignee.Preferences, Assert.AreSame(result.Owner.Preferences, result.Items[0].Assignee.Preferences, $"[{mode}] UserPreferences reference identity failed - Non-IId should work in All mode!");
$"[{mode}] UserPreferences reference identity failed - Non-IId should work in All mode!");
break; break;
} }
// Data integrity - always check // Data integrity - always check
Assert.IsNotNull(result, $"[{mode}] Deserialized result is null");
Assert.IsNotNull(result.PrimaryTag, $"[{mode}] PrimaryTag is null"); Assert.IsNotNull(result.PrimaryTag, $"[{mode}] PrimaryTag is null");
Assert.AreEqual(1, result.PrimaryTag.Id, $"[{mode}] PrimaryTag.Id incorrect"); Assert.AreEqual(1, result.PrimaryTag.Id, $"[{mode}] PrimaryTag.Id incorrect");
Assert.AreEqual("ImportantTag", result.PrimaryTag.Name, $"[{mode}] PrimaryTag.Name incorrect"); Assert.AreEqual("ImportantTag", result.PrimaryTag.Name, $"[{mode}] PrimaryTag.Name incorrect");

View File

@ -82,9 +82,9 @@ public sealed class AcBinarySerializerOptions : AcSerializerOptions
/// allowing the deserializer to match properties by name between different types. /// allowing the deserializer to match properties by name between different types.
/// Default: false (no overhead) /// Default: false (no overhead)
/// </summary> /// </summary>
public bool UseMetadata { get; set; } = true; public bool UseMetadata { get; set; } = false;
public bool UseGeneratedCode { get; set; } = false; public bool UseGeneratedCode { get; set; } = true;
/// <summary> /// <summary>
/// Controls how string interning is applied during serialization. /// Controls how string interning is applied during serialization.