How to unit test if my object is really serializable?

后端 未结 7 1219
情书的邮戳
情书的邮戳 2020-12-03 00:45

I am using C# 2.0 with Nunit Test. I have some object that needs to be serialized. These objects are quite complex (inheritance at different levels and contains a lot of obj

7条回答
  •  误落风尘
    2020-12-03 01:26

    Probably a bit late in the day, but if you are using the FluentAssertions library, then it has custom assertions for XML serialization, binary serialization, and data contract serialization.

    theObject.Should().BeXmlSerializable();
    theObject.Should().BeBinarySerializable();
    theObject.Should().BeDataContractSerializable();
    
    theObject.Should().BeBinarySerializable(
        options => options.Excluding(s => s.SomeNonSerializableProperty));
    

提交回复
热议问题