Пример #1
0
        public void ShouldThorErrorOnRegisteringSameType()
        {
            var registry = new TypeMapperRegistry();

            var mapper = new TypeMapper <ClassW2Properties, ClassW4Properties>();

            registry.Register <ClassW2Properties, ClassW4Properties>(mapper);

            registry.Register <ClassW2Properties, ClassW4Properties>();
        }
Пример #2
0
        public void ShouldNotResolveNotRegisteredType()
        {
            var registry = new TypeMapperRegistry();
            var source   = new ClassW2Properties {
                Prop = 1, Prop2 = 2
            };

            var propertiesMapper = registry.Register <ClassW2Properties, ClassW4Properties>();

            propertiesMapper.InjectPropertyValue(properties => properties.Prop3, 3);

            registry.Resolve(source, typeof(ClassWithSourceCtor));
        }
Пример #3
0
        public void ShouldMapInjectedProperties()
        {
            var registry = new TypeMapperRegistry();
            var source   = new ClassW2Properties {
                Prop = 1, Prop2 = 2
            };

            var propertiesMapper = registry.Register <ClassW2Properties, ClassW4Properties>();

            propertiesMapper.InjectPropertyValue(properties => properties.Prop3, 3);

            ClassW4Properties dest = registry.Resolve(source, typeof(ClassW4Properties)) as ClassW4Properties;

            Assert.IsNotNull(dest);
            Assert.IsTrue(dest.Prop == 1);
            Assert.IsTrue(dest.Prop3 == 3);
        }
Пример #4
0
        public void ShouldMapIdenticallyNamedTypeProperties()
        {
            var registry = new TypeMapperRegistry();
            var source   = new ClassW2Properties {
                Prop = 1, Prop2 = 2
            };

            var mapper = new TypeMapper <ClassW2Properties, ClassW4Properties>();

            registry.Register <ClassW2Properties, ClassW4Properties>(mapper);

            var dest = registry.Resolve <ClassW4Properties>(source);

            Assert.IsNotNull(dest);
            Assert.IsTrue(dest.Prop == 1);
            Assert.IsTrue(dest.Prop2 == 2);
        }
Пример #5
0
        public void ShouldResolveDestTypeDescendants()
        {
            var registry = new TypeMapperRegistry();
            var source   = new ClassW2Properties {
                Prop = 1, Prop2 = 2
            };

            var mapper = new TypeMapper <ClassW2Properties, ClassW4PropertiesDescendant1>();

            registry.Register <ClassW2Properties, ClassW4PropertiesDescendant1>(mapper);
            registry.Register <ClassW2Properties, ClassW4PropertiesDescendant2>();
            registry.Register <ClassW2Properties, ClassW4Properties>();

            var dest = registry.ResolveDescendants <ClassW4Properties>(source);

            Assert.IsNotNull(dest);
            Assert.IsTrue(dest.Count() == 3);
            Assert.IsTrue(dest.All(properties => properties.Prop2 == 2));
            Assert.IsTrue(dest.All(properties => properties.Prop == 1));
        }