Unit testing classes for serialization using the XmlSerializer

This is a testing template to validate that an object is serializable using the XmlSerializer.
public void ClassIsSerializableWithXmlSerializer() {
    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer();
    MemoryStream stream = new MemoryStream();
    Class original = new Class();
    //Set values on original.
    Class deserializedObject = new Class();
    serializer.Serialize(stream, original);
    stream.Seek(0, SeekOrigin.Begin);
    deserializedObject = (Class)serializer.Deserialize(stream);
    //Assert values on deserialized object are as expected.

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