public void TestSerialize() { Memento.SampleClass cls = new Memento.SampleClass(40, "Memento"); Memento.XMLSampleClass state = new Memento.XMLSampleClass(); cls.GetState(state); XmlSerializer s = new XmlSerializer(typeof(Memento.XMLSampleClass)); TextWriter w = new StreamWriter(@"c:\sampleclass.xml"); s.Serialize(w, state); w.Close(); }
public void TestDeserialize() { Memento.SampleClass cls = new Memento.SampleClass(); Memento.XMLSampleClass state = new Memento.XMLSampleClass(); XmlSerializer s = new XmlSerializer(typeof(Memento.XMLSampleClass)); TextReader r = new StreamReader(@"c:\sampleclass.xml"); state = (Memento.XMLSampleClass)s.Deserialize(r); r.Close(); cls.SetState(state); Assert.AreEqual(40, cls.Value); }