public void TestSerializeObjectsTree() { var model = new ModelContainer(); SimpleModelObject.CurrentModelContainer = model; var array1 = new TestObjectArray(); var array2 = new TestObjectArray(); var obj1 = new TestObject { Getal = 1 }; var obj2 = new TestObject { Getal = 2 }; var obj3 = new TestObject { Getal = 3 }; var obj4 = new TestObject { Getal = 4 }; var obj5 = new TestObject { Getal = 5 }; array1.Objects.Add(obj1); array2.Objects.Add(obj2); array2.Objects.Add(obj3); obj3.Object = obj4; obj4.Object = obj4; obj5.Object = obj5; var strm = new MemoryStream(); var writer = new StreamWriter(strm); var serializer = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer()); serializer.QueueForSerialization(array2); serializer.Serialize(writer); writer.Flush(); strm.Position = 0; var str = getStringFromStream(strm); }
public void TestSerializeArray() { var array = new TestObjectArray(); array.Objects = new List <TestObject>(); array.Objects.Add(object1); array.Objects.Add(object2); var s = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer()); var strm = new MemoryStream(); var writer = new StreamWriter(strm); s.Serialize(model, writer); var deserialized = new Data.ModelContainer(); writer.Flush(); strm.Position = 0; // For testing string serialized = getStringFromStream(strm); SimpleModelObject.CurrentModelContainer = deserialized; s = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer()); s.Deserialize(new StreamReader(strm)); Assert.AreEqual(model.Objects.Count, deserialized.Objects.Count); Assert.AreEqual(model.Objects[0].ToString(), deserialized.Objects[0].ToString()); Assert.AreEqual(model.Objects[1].ToString(), deserialized.Objects[1].ToString()); Assert.AreEqual(model.Objects[2].ToString(), deserialized.Objects[2].ToString()); }