public void Test()
        {
            var c = new SerializerTestCollection();

            Assert.AreEqual(0, c.Serializers.Count);
            var f = new TestSerializationFactory(c);

            Assert.AreEqual(1, c.Serializers.Count);
            Assert.IsInstanceOfType(c.Serializers[0], typeof(TestCollectionSerializer));

            var i = new SerializerTestItem();

            Assert.AreEqual(0, i.Serializers.Count);
            c.Add(i);
            Assert.AreEqual(1, i.Serializers.Count);
            Assert.IsInstanceOfType(i.Serializers[0], typeof(TestItemSerializer));
            TestItemSerializer s = (TestItemSerializer)i.Serializers[0];

            c.Remove(i);
            Assert.IsTrue(s.IsDisposed);
            Assert.AreEqual(0, i.Serializers.Count);

            i = new SerializerTestItem();
            c.Add(i);
            Assert.AreEqual(1, i.Serializers.Count);
            Assert.IsInstanceOfType(i.Serializers[0], typeof(TestItemSerializer));
            s = (TestItemSerializer)i.Serializers[0];

            f.Dispose();
            Assert.IsTrue(s.IsDisposed);
        }
        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);
        }