コード例 #1
0
        private static ICoffeeMapper CreateMapperWithExampleMapping()
        {
            ClassMappingInstructionHolder mappingInstructions = new ClassMappingInstructionHolder();

            mappingInstructions.AddMapping <ExampleClass1, ExampleClass2>();
            ICoffeeMapper mapper = new CoffeeMapper(mappingInstructions);

            return(mapper);
        }
コード例 #2
0
        public void ClassMappingAutoDiscoversBasicPropertyFromIntToLong()
        {
            ClassMappingInstructionHolder mappingInstructions = new ClassMappingInstructionHolder();

            mappingInstructions.AddMapping <ExampleClassWithIntProperty, ExampleClassWithLongProperty>();
            ICoffeeMapper mapper = new CoffeeMapper(mappingInstructions);
            ExampleClassWithIntProperty  exampleObject1 = GetExampleObjectWithIntProperty();
            ExampleClassWithLongProperty result         = mapper.Map <ExampleClassWithLongProperty>(exampleObject1);

            Assert.AreEqual(exampleObject1.A, result.A);
        }
コード例 #3
0
        public void ClassMappingAutoDiscoversBasicPropertyWithMismatchTypes()
        {
            ClassMappingInstructionHolder mappingInstructions = new ClassMappingInstructionHolder();

            mappingInstructions.AddMapping <ExampleClass1, ExampleClassWithIntProperty>(new ClassMappingInstructionOptions {
                AutoAddPropertiesWithSameName = true
            });
            ICoffeeMapper mapper               = new CoffeeMapper(mappingInstructions);
            ExampleClass1 exampleObject1       = GetObject1();
            ExampleClassWithIntProperty result = mapper.Map <ExampleClassWithIntProperty>(exampleObject1);

            Assert.AreEqual(exampleObject1.A, result.A);
        }
コード例 #4
0
        public void ClassMappingWithoutAutoDiscoversBasicProperty()
        {
            ClassMappingInstructionHolder mappingInstructions = new ClassMappingInstructionHolder();

            mappingInstructions.AddMapping <ExampleClass1, ExampleClass2>(new ClassMappingInstructionOptions {
                AutoAddPropertiesWithSameName = false
            });
            ICoffeeMapper mapper         = new CoffeeMapper(mappingInstructions);
            ExampleClass1 exampleObject1 = GetObject1();
            ExampleClass2 result         = mapper.Map <ExampleClass2>(exampleObject1);

            Assert.AreEqual(null, result.A);
        }