71 lines
2.7 KiB
C#
71 lines
2.7 KiB
C#
using AyCode.Core.Serializers.Binaries;
|
|
using AyCode.Core.Tests.TestModels;
|
|
|
|
namespace AyCode.Core.Tests.Serialization;
|
|
|
|
[TestClass]
|
|
public class AcBinarySerializerSGenNullComplexPropertyTests
|
|
{
|
|
[TestMethod]
|
|
[DataRow(true, true)]
|
|
[DataRow(true, false)]
|
|
[DataRow(false, false)]
|
|
[DataRow(false, true)]
|
|
public void Serialize_SGenComplexPropertyNull_DoesNotThrow_AndRoundTripsAsNull(bool useSgen, bool fastMode)
|
|
{
|
|
var model = new SGenNullComplexParent
|
|
{
|
|
Id = 7,
|
|
Customer = null!,
|
|
Note = "regression"
|
|
};
|
|
|
|
var options = fastMode ? AcBinarySerializerOptions.FastMode: AcBinarySerializerOptions.Default;
|
|
options.UseGeneratedCode = useSgen;
|
|
|
|
var bytes = AcBinarySerializer.Serialize(model, options);
|
|
var roundTrip = AcBinaryDeserializer.Deserialize<SGenNullComplexParent>(bytes, options);
|
|
|
|
Assert.IsNotNull(roundTrip);
|
|
Assert.AreEqual(model.Id, roundTrip.Id);
|
|
Assert.AreEqual(model.Note, roundTrip.Note);
|
|
Assert.IsNull(roundTrip.Customer,
|
|
"complex reference property must round-trip as null when source was null " +
|
|
"(regression for SGen WriteObjectGenerated fallback else-branch null-check)");
|
|
|
|
Assert.IsTrue(System.Array.IndexOf(bytes, (byte)BinaryTypeCode.PropertySkip) >= 0,
|
|
"writer must emit PropertySkip marker on the null Customer slot " +
|
|
"(deeper verification: confirms the fix took the PropertySkip path, " +
|
|
"not an unrelated null-safe code path)");
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow(true, true)]
|
|
[DataRow(true, false)]
|
|
[DataRow(false, false)]
|
|
[DataRow(false, true)]
|
|
public void Serialize_SGenComplexPropertyNonNull_RoundTripsCorrectly(bool useSgen, bool fastMode)
|
|
{
|
|
var model = new SGenNullComplexParent
|
|
{
|
|
Id = 13,
|
|
Customer = new NonGeneratedComplexCustomer { Id = 42, Name = "child" },
|
|
Note = "positive"
|
|
};
|
|
|
|
var options = fastMode ? AcBinarySerializerOptions.FastMode: AcBinarySerializerOptions.Default;
|
|
options.UseGeneratedCode = useSgen;
|
|
|
|
var bytes = AcBinarySerializer.Serialize(model, options);
|
|
var roundTrip = AcBinaryDeserializer.Deserialize<SGenNullComplexParent>(bytes, options);
|
|
|
|
Assert.IsNotNull(roundTrip);
|
|
Assert.AreEqual(model.Id, roundTrip.Id);
|
|
Assert.AreEqual(model.Note, roundTrip.Note);
|
|
Assert.IsNotNull(roundTrip.Customer,
|
|
"non-null complex reference property must round-trip (null-check fix must not break the non-null path)");
|
|
Assert.AreEqual(model.Customer.Id, roundTrip.Customer.Id);
|
|
Assert.AreEqual(model.Customer.Name, roundTrip.Customer.Name);
|
|
}
|
|
}
|