How to unit test if my object is really serializable?

后端 未结 7 1202
情书的邮戳
情书的邮戳 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:42

    I have this in some unit test here at job:

    MyComplexObject dto = new MyComplexObject();
    MemoryStream mem = new MemoryStream();
    BinaryFormatter b = new BinaryFormatter();
    try
    {
        b.Serialize(mem, dto);
    }
    catch (Exception ex)
    {
        Assert.Fail(ex.Message);
    }
    

    Might help you... maybe other method can be better but this one works well.

    0 讨论(0)
提交回复
热议问题