Пример #1
0
        public void AddWithExistingSerializerForSameType()
        {
            var storage = new ObjectSerializerStorage();

            var serializer = new MockSerializer(typeof(MockDerived));

            storage.Add(serializer);

            var otherSerializer = new MockSerializer(typeof(MockDerived));

            Assert.Throws <DuplicateObjectSerializerException>(() => storage.Add(otherSerializer));
        }
Пример #2
0
        public void AddClassSerializerWithMoreDerivedClassSerializersExisting()
        {
            var storage = new ObjectSerializerStorage();

            var derivedSerializer = new MockSerializer(typeof(MockDerived));

            storage.Add(derivedSerializer);

            var baseSerializer = new MockSerializer(typeof(MockBase));

            storage.Add(baseSerializer);

            Assert.IsTrue(storage.HasSerializerFor(typeof(MockDerived)));
            Assert.IsTrue(storage.HasSerializerFor(typeof(MockMoreDerived)));
            Assert.IsTrue(storage.HasSerializerFor(typeof(MockBase)));
            Assert.IsFalse(storage.HasSerializerFor(typeof(IMockBase)));
            Assert.IsFalse(storage.HasSerializerFor(typeof(IMockDerived)));
            Assert.AreSame(baseSerializer, storage.SerializerFor(typeof(MockBase)));
            Assert.AreSame(derivedSerializer, storage.SerializerFor(typeof(MockDerived)));
            Assert.AreSame(derivedSerializer, storage.SerializerFor(typeof(MockMoreDerived)));
        }
Пример #3
0
        public void Add()
        {
            var storage = new ObjectSerializerStorage();

            var serializer = new MockSerializer(typeof(MockDerived));

            storage.Add(serializer);

            Assert.IsTrue(storage.HasSerializerFor(typeof(MockDerived)));
            Assert.IsTrue(storage.HasSerializerFor(typeof(MockMoreDerived)));
            Assert.IsFalse(storage.HasSerializerFor(typeof(MockBase)));
            Assert.IsFalse(storage.HasSerializerFor(typeof(IMockBase)));
            Assert.IsFalse(storage.HasSerializerFor(typeof(IMockDerived)));
            Assert.AreSame(serializer, storage.SerializerFor(typeof(MockDerived)));
            Assert.AreSame(serializer, storage.SerializerFor(typeof(MockMoreDerived)));
        }