public void FileSerialize_DeserializeTest() { var collection = new SerializerTestCollection(); var text = "asd"; var path = Path.GetTempPath(); var filename = "filename"; var s = new CollectionTestXmlSerializer(collection, text, path, filename); int val = 123; Assert.AreEqual(0, collection.Count); collection.Add(new SerializerTestItem() { Prop = val }); s.Dispose(); collection.Clear(); s = new CollectionTestXmlSerializer(collection, text, path, filename); s.Deserialize(); Assert.AreEqual(1, collection.Count); Assert.AreEqual(val, collection[0].Prop); s.ClearSerializedData(); s.Dispose(); }
public void SerializeOnCollectionChangedTest() { var collection = new SerializerTestCollection(); collection.PropertyChanged += Collection_PropertyChanged; collection.CollectionChanged += Collection_CollectionChanged; var serializer = new TestCollectionSerializer(collection); collection.Serializers.Add(serializer); //Test on Add serializer.SerializerCalled = false; serializer.DeserializerCalled = false; _notifyCollectionChangedEventArgs = null; _propertyChangedEventArgs = null; for (int i = 0; i < 10; i++) { serializer.SerializerCalled = false; serializer.DeserializerCalled = false; _notifyCollectionChangedEventArgs = null; _propertyChangedEventArgs = null; collection.Add(new SerializerTestItem { Prop = i }); Assert.IsTrue(serializer.SerializerCalled); Assert.IsFalse(serializer.DeserializerCalled); Assert.IsNotNull(_notifyCollectionChangedEventArgs); Assert.IsNull(_propertyChangedEventArgs); } //Test on RemoveAt for (int i = 0; i < 10; i++) { serializer.SerializerCalled = false; serializer.DeserializerCalled = false; _notifyCollectionChangedEventArgs = null; _propertyChangedEventArgs = null; collection.RemoveAt(0); Assert.IsTrue(serializer.SerializerCalled); Assert.IsFalse(serializer.DeserializerCalled); Assert.IsNotNull(_notifyCollectionChangedEventArgs); Assert.IsNull(_propertyChangedEventArgs); } //Test on Remove for (int i = 0; i < 10; i++) { serializer.SerializerCalled = false; serializer.DeserializerCalled = false; _notifyCollectionChangedEventArgs = null; _propertyChangedEventArgs = null; collection.Add(new SerializerTestItem { Prop = i }); Assert.IsTrue(serializer.SerializerCalled); Assert.IsFalse(serializer.DeserializerCalled); Assert.IsNotNull(_notifyCollectionChangedEventArgs); Assert.IsNull(_propertyChangedEventArgs); } for (int i = 0; i < 10; i++) { serializer.SerializerCalled = false; serializer.DeserializerCalled = false; _notifyCollectionChangedEventArgs = null; _propertyChangedEventArgs = null; collection.Remove(collection[0]); Assert.IsTrue(serializer.SerializerCalled); Assert.IsFalse(serializer.DeserializerCalled); Assert.IsNotNull(_notifyCollectionChangedEventArgs); Assert.IsNull(_propertyChangedEventArgs); } //Test on Clear for (int i = 0; i < 10; i++) { serializer.SerializerCalled = false; serializer.DeserializerCalled = false; _notifyCollectionChangedEventArgs = null; _propertyChangedEventArgs = null; collection.Add(new SerializerTestItem { Prop = i }); Assert.IsTrue(serializer.SerializerCalled); Assert.IsFalse(serializer.DeserializerCalled); Assert.IsNotNull(_notifyCollectionChangedEventArgs); Assert.IsNull(_propertyChangedEventArgs); } serializer.SerializerCalled = false; serializer.DeserializerCalled = false; _notifyCollectionChangedEventArgs = null; _propertyChangedEventArgs = null; collection.Clear(); Assert.IsTrue(serializer.SerializerCalled); Assert.IsFalse(serializer.DeserializerCalled); Assert.IsNotNull(_notifyCollectionChangedEventArgs); Assert.IsNull(_propertyChangedEventArgs); //Test on Dispose for (int i = 0; i < 10; i++) { serializer.SerializerCalled = false; serializer.DeserializerCalled = false; _notifyCollectionChangedEventArgs = null; _propertyChangedEventArgs = null; collection.Add(new SerializerTestItem { Prop = i }); Assert.IsTrue(serializer.SerializerCalled); Assert.IsFalse(serializer.DeserializerCalled); Assert.IsNotNull(_notifyCollectionChangedEventArgs); Assert.IsNull(_propertyChangedEventArgs); } serializer.SerializerCalled = false; serializer.DeserializerCalled = false; _notifyCollectionChangedEventArgs = null; _propertyChangedEventArgs = null; collection.Dispose(); Assert.IsFalse(serializer.SerializerCalled); Assert.IsFalse(serializer.DeserializerCalled); Assert.IsNull(_notifyCollectionChangedEventArgs); Assert.IsNull(_propertyChangedEventArgs); }
public void SerializeDeserializeTest() { var collection = new SerializerTestCollection(); collection.PropertyChanged += Collection_PropertyChanged; collection.CollectionChanged += Collection_CollectionChanged; for (int i = 0; i < 10; i++) { collection.Add(new SerializerTestItem { Prop = i }); } var serializer = new TestCollectionSerializer(collection); var collectionLen = collection.Count; serializer.SerializerCalled = false; serializer.DeserializerCalled = false; _notifyCollectionChangedEventArgs = null; _propertyChangedEventArgs = null; collection.Serializers.Add(serializer); //Test Empty deserialize Assert.IsFalse(serializer.SerializerCalled); Assert.IsFalse(serializer.DeserializerCalled); Assert.IsNull(_notifyCollectionChangedEventArgs); Assert.IsNull(_propertyChangedEventArgs); collection.Serializers[0].Deserialize(); Assert.IsFalse(serializer.SerializerCalled); Assert.IsTrue(serializer.DeserializerCalled); Assert.AreEqual(collectionLen, collection.Count); Assert.IsNull(_notifyCollectionChangedEventArgs); Assert.IsNull(_propertyChangedEventArgs); //TestSerialize serializer.SerializerCalled = false; serializer.DeserializerCalled = false; _notifyCollectionChangedEventArgs = null; _propertyChangedEventArgs = null; collection.Serializers[0].Serialize(); Assert.IsTrue(serializer.SerializerCalled); Assert.IsFalse(serializer.DeserializerCalled); Assert.AreEqual(collectionLen, collection.Count); Assert.IsNull(_notifyCollectionChangedEventArgs); Assert.IsNull(_propertyChangedEventArgs); collection.Clear(); Assert.AreEqual(0, collection.Count); //TestDeserialize serializer.SerializerCalled = false; serializer.DeserializerCalled = false; _notifyCollectionChangedEventArgs = null; _propertyChangedEventArgs = null; collection.Serializers[0].Deserialize(); Assert.IsFalse(serializer.SerializerCalled); Assert.IsTrue(serializer.DeserializerCalled); Assert.AreEqual(collectionLen, collection.Count); Assert.IsNotNull(_notifyCollectionChangedEventArgs); Assert.IsNull(_propertyChangedEventArgs); Assert.AreEqual(10, collection.Count); for (int i = 0; i < 10; i++) { collection[i].Prop = i; } serializer.Dispose(); }