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
|
/// - StockTakingItem has Product navigation property
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestMethod]
|
[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
|
var parent = new CircularParent
|
||||||
{
|
{
|
||||||
|
|
@ -58,6 +62,10 @@ public class AcBinarySerializerCircularReferenceTests
|
||||||
|
|
||||||
var option = AcBinarySerializerOptions.Default;
|
var option = AcBinarySerializerOptions.Default;
|
||||||
option.ReferenceHandling = ReferenceHandlingMode.All;
|
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 binary = parent.ToBinary(option);
|
||||||
var result = binary.BinaryTo<CircularParent>();
|
var result = binary.BinaryTo<CircularParent>();
|
||||||
|
|
@ -83,7 +91,11 @@ public class AcBinarySerializerCircularReferenceTests
|
||||||
/// Test list of parents with circular references.
|
/// Test list of parents with circular references.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestMethod]
|
[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 =>
|
var parents = Enumerable.Range(1, 5).Select(p =>
|
||||||
{
|
{
|
||||||
|
|
@ -132,6 +144,10 @@ public class AcBinarySerializerCircularReferenceTests
|
||||||
|
|
||||||
var option = AcBinarySerializerOptions.Default;
|
var option = AcBinarySerializerOptions.Default;
|
||||||
option.ReferenceHandling = ReferenceHandlingMode.All;
|
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 binary = parents.ToBinary(option);
|
||||||
var result = binary.BinaryTo<List<CircularParent>>();
|
var result = binary.BinaryTo<List<CircularParent>>();
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,11 @@ public class AcBinarySerializerIIdReferenceTests
|
||||||
/// Tests all ReferenceHandling modes: None, OnlyId, All
|
/// Tests all ReferenceHandling modes: None, OnlyId, All
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestMethod]
|
[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[]
|
var modes = new[]
|
||||||
{
|
{
|
||||||
|
|
@ -93,8 +97,6 @@ public class AcBinarySerializerIIdReferenceTests
|
||||||
|
|
||||||
foreach (var mode in modes)
|
foreach (var mode in modes)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"\n========== ReferenceHandling: {mode} ==========");
|
|
||||||
|
|
||||||
// Arrange: SAME instance used multiple times
|
// Arrange: SAME instance used multiple times
|
||||||
var userPreferences = new UserPreferences();
|
var userPreferences = new UserPreferences();
|
||||||
var sharedTag = new SharedTag { Id = 1, Name = "ImportantTag", Color = "#FF0000" };
|
var sharedTag = new SharedTag { Id = 1, Name = "ImportantTag", Color = "#FF0000" };
|
||||||
|
|
@ -119,7 +121,13 @@ public class AcBinarySerializerIIdReferenceTests
|
||||||
|
|
||||||
order.Items[1].ParentOrder = order;
|
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
|
// Act
|
||||||
var binary = AcBinarySerializer.Serialize(order, options);
|
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.
|
/// 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; } = false;
|
public bool UseMetadata { get; set; } = true;
|
||||||
|
|
||||||
public bool UseGeneratedCode { get; set; } = true;
|
public bool UseGeneratedCode { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Controls how string interning is applied during serialization.
|
/// Controls how string interning is applied during serialization.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue