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:
parent
60f963bb36
commit
686424b813
|
|
@ -124,7 +124,8 @@ public class AcBinarySerializerIIdReferenceTests
|
|||
var options = new AcBinarySerializerOptions
|
||||
{
|
||||
ReferenceHandling = mode,
|
||||
UseGeneratedCode = useSgen
|
||||
UseGeneratedCode = useSgen,
|
||||
UseMetadata = useMeta
|
||||
};
|
||||
|
||||
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($"ObjectRef count: {objectRefCount}");
|
||||
|
||||
Assert.IsNotNull(result, $"[{mode}] Deserialized result is null");
|
||||
Assert.IsNotNull(result.Parent);
|
||||
Assert.IsNotNull(result.Owner);
|
||||
|
||||
// Assert based on mode
|
||||
switch (mode)
|
||||
{
|
||||
|
|
@ -152,6 +157,8 @@ public class AcBinarySerializerIIdReferenceTests
|
|||
// IId types should have reference identity
|
||||
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, result.Items[1].ParentOrder);
|
||||
Assert.AreSame(result.Parent, result.Items[1]);
|
||||
break;
|
||||
|
||||
case ReferenceHandlingMode.All:
|
||||
|
|
@ -159,14 +166,16 @@ public class AcBinarySerializerIIdReferenceTests
|
|||
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.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
|
||||
Assert.AreSame(result.Owner.Preferences, result.Items[0].Assignee.Preferences,
|
||||
$"[{mode}] UserPreferences reference identity failed - Non-IId should work in All mode!");
|
||||
Assert.AreSame(result.Owner.Preferences, result.Items[0].Assignee.Preferences, $"[{mode}] UserPreferences reference identity failed - Non-IId should work in All mode!");
|
||||
break;
|
||||
}
|
||||
|
||||
// Data integrity - always check
|
||||
Assert.IsNotNull(result, $"[{mode}] Deserialized result is null");
|
||||
Assert.IsNotNull(result.PrimaryTag, $"[{mode}] PrimaryTag is null");
|
||||
Assert.AreEqual(1, result.PrimaryTag.Id, $"[{mode}] PrimaryTag.Id incorrect");
|
||||
Assert.AreEqual("ImportantTag", result.PrimaryTag.Name, $"[{mode}] PrimaryTag.Name incorrect");
|
||||
|
|
|
|||
|
|
@ -82,9 +82,9 @@ public sealed class AcBinarySerializerOptions : AcSerializerOptions
|
|||
/// allowing the deserializer to match properties by name between different types.
|
||||
/// Default: false (no overhead)
|
||||
/// </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>
|
||||
/// Controls how string interning is applied during serialization.
|
||||
|
|
|
|||
Loading…
Reference in New Issue