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.
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s