Unit testing classes for serialization using the SoapFormatter

This is a testing template to validate that an object is serializable using the SoapFormatter.
 
[Test]
public void ClassIsSerializableWithSoapSerializer() {
    IFormatter formatter = new SoapFormatter();
    MemoryStream stream = new MemoryStream();
    Class original = new Class();

    //Set values on original.

    Class deserializedObject = new Class();

    formatter.Serialize(stream, original);
    stream.Seek(0, SeekOrigin.Begin);
    deserializedObject = (Class)formatter.Deserialize(stream);
    //Assert values on deserialized object are as expected.
}

Leave a comment