Update serializer tests for param options; swap option defaults
Refactor test methods to use [DataRow] for parameterized testing of UseSgen and UseMeta combinations. Dynamically set AcBinarySerializerOptions in tests and add diagnostic output. Swap default values in AcBinarySerializerOptions: UseMetadata is now true, UseGeneratedCode is now false. This affects default serializer behavior across tests and usages.
This commit is contained in:
parent
03e5cd9f29
commit
60f963bb36
|
|
@ -19,7 +19,11 @@ public class AcBinarySerializerCircularReferenceTests
|
|||
/// - StockTakingItem has Product navigation property
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void Deserialize_CircularReference_ParentChildBackReference()
|
||||
[DataRow(true, true)]
|
||||
[DataRow(false, true)]
|
||||
[DataRow(true, false)]
|
||||
[DataRow(false, false)]
|
||||
public void Deserialize_CircularReference_ParentChildBackReference(bool useSgen, bool useMeta)
|
||||
{
|
||||
var parent = new CircularParent
|
||||
{
|
||||
|
|
@ -58,6 +62,10 @@ public class AcBinarySerializerCircularReferenceTests
|
|||
|
||||
var option = AcBinarySerializerOptions.Default;
|
||||
option.ReferenceHandling = ReferenceHandlingMode.All;
|
||||
option.UseGeneratedCode = useSgen;
|
||||
option.UseMetadata = useMeta;
|
||||
|
||||
Console.WriteLine($"\n========== ReferenceHandling: {option.ReferenceHandling}, UseSgen: {option.UseGeneratedCode}, UseMeta: {option.UseMetadata} ==========");
|
||||
|
||||
var binary = parent.ToBinary(option);
|
||||
var result = binary.BinaryTo<CircularParent>();
|
||||
|
|
@ -83,7 +91,11 @@ public class AcBinarySerializerCircularReferenceTests
|
|||
/// Test list of parents with circular references.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void Deserialize_ListOfCircularReferences_AllItemsCorrect()
|
||||
[DataRow(true, true)]
|
||||
[DataRow(false, true)]
|
||||
[DataRow(true, false)]
|
||||
[DataRow(false, false)]
|
||||
public void Deserialize_ListOfCircularReferences_AllItemsCorrect(bool useSgen, bool useMeta)
|
||||
{
|
||||
var parents = Enumerable.Range(1, 5).Select(p =>
|
||||
{
|
||||
|
|
@ -132,6 +144,10 @@ public class AcBinarySerializerCircularReferenceTests
|
|||
|
||||
var option = AcBinarySerializerOptions.Default;
|
||||
option.ReferenceHandling = ReferenceHandlingMode.All;
|
||||
option.UseGeneratedCode = useSgen;
|
||||
option.UseMetadata = useMeta;
|
||||
|
||||
Console.WriteLine($"\n========== ReferenceHandling: {option.ReferenceHandling}, UseSgen: {option.UseGeneratedCode}, UseMeta: {option.UseMetadata} ==========");
|
||||
|
||||
var binary = parents.ToBinary(option);
|
||||
var result = binary.BinaryTo<List<CircularParent>>();
|
||||
|
|
|
|||
|
|
@ -82,7 +82,11 @@ public class AcBinarySerializerIIdReferenceTests
|
|||
/// Tests all ReferenceHandling modes: None, OnlyId, All
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void SameInstance_SerializeAndDeserialize()
|
||||
[DataRow(true, true)]
|
||||
[DataRow(false, true)]
|
||||
[DataRow(true, false)]
|
||||
[DataRow(false, false)]
|
||||
public void SameInstance_SerializeAndDeserialize(bool useSgen, bool useMeta)
|
||||
{
|
||||
var modes = new[]
|
||||
{
|
||||
|
|
@ -93,8 +97,6 @@ public class AcBinarySerializerIIdReferenceTests
|
|||
|
||||
foreach (var mode in modes)
|
||||
{
|
||||
Console.WriteLine($"\n========== ReferenceHandling: {mode} ==========");
|
||||
|
||||
// Arrange: SAME instance used multiple times
|
||||
var userPreferences = new UserPreferences();
|
||||
var sharedTag = new SharedTag { Id = 1, Name = "ImportantTag", Color = "#FF0000" };
|
||||
|
|
@ -119,7 +121,13 @@ public class AcBinarySerializerIIdReferenceTests
|
|||
|
||||
order.Items[1].ParentOrder = order;
|
||||
|
||||
var options = new AcBinarySerializerOptions { ReferenceHandling = mode };
|
||||
var options = new AcBinarySerializerOptions
|
||||
{
|
||||
ReferenceHandling = mode,
|
||||
UseGeneratedCode = useSgen
|
||||
};
|
||||
|
||||
Console.WriteLine($"\n========== ReferenceHandling: {options.ReferenceHandling}, UseSgen: {options.UseGeneratedCode}, UseMeta: {options.UseMetadata} ==========");
|
||||
|
||||
// Act
|
||||
var binary = AcBinarySerializer.Serialize(order, options);
|
||||
|
|
|
|||
|
|
@ -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; } = false;
|
||||
public bool UseMetadata { get; set; } = true;
|
||||
|
||||
public bool UseGeneratedCode { get; set; } = true;
|
||||
public bool UseGeneratedCode { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Controls how string interning is applied during serialization.
|
||||
|
|
|
|||
Loading…
Reference in New Issue