public void TestMappingTwoToOne()
        {
            // Arrange
            IMapper mapper = new Mapper.Mapper();

            mapper.Register <Class1From, Class2From, ClassTo>((p, q) => new ClassTo
            {
                ValueInt    = p.ValueInt,
                ValueString = p.ValueString + q.ValueString,
                ValueDouble = q.ValueDouble
            });

            var classFrom1 = new Class1From
            {
                ValueInt    = ConstValueInt,
                ValueString = ConstValueString1
            };

            var classFrom2 = new Class2From
            {
                ValueDouble = ConstValueDouble,
                ValueString = ConstValueString2
            };

            // Act
            ClassTo classTo = mapper.Map <Class1From, Class2From, ClassTo>(classFrom1, classFrom2);

            // Assert
            Assert.IsNotNull(classTo);
            Assert.AreEqual(classTo.ValueInt, 3);
            Assert.AreEqual(classTo.ValueDouble, ConstValueDouble);
            Assert.AreEqual(classTo.ValueString, ConstValueString1 + ConstValueString2);
        }
Exemple #2
0
        public void TestMappingTwoToOne()
        {
            // Arrange
            IMapper mapper = new Mapper.Mapper();
            mapper.Register<Class1From, Class2From, ClassTo>((p, q) => new ClassTo
                {
                    ValueInt = p.ValueInt,
                    ValueString = p.ValueString + q.ValueString,
                    ValueDouble = q.ValueDouble
                });

            var classFrom1 = new Class1From
                {
                    ValueInt = ConstValueInt,
                    ValueString = ConstValueString1
                };

            var classFrom2 = new Class2From
                {
                    ValueDouble = ConstValueDouble,
                    ValueString = ConstValueString2
                };

            // Act
            ClassTo classTo = mapper.Map<Class1From, Class2From, ClassTo>(classFrom1, classFrom2);

            // Assert
            Assert.IsNotNull(classTo);
            Assert.AreEqual(classTo.ValueInt, 3);
            Assert.AreEqual(classTo.ValueDouble, ConstValueDouble);
            Assert.AreEqual(classTo.ValueString, ConstValueString1 + ConstValueString2);
        }