public void TestMethod1() { Mapper.Register(Mapping <TestA, TestB> .Auto()); var a = new TestA(); var b = new TestB(); a.MyPropertyA = 1; b.MyPropertyA = 2; Mapper.Map(a, b); Assert.AreEqual(1, a.MyPropertyA); Assert.AreEqual(1, b.MyPropertyA); }
public void IgnoredProperties() { var mapping = Mapping <TestA, TestB> .Auto(cfg => cfg.Ignore(x => x.MyPropertyA)); var a = new TestA() { MyPropertyA = 11, MyPropertyB = 25 }; var b = new TestB(); mapping.Map(a, b); Assert.AreEqual(0, b.MyPropertyA); Assert.AreEqual(25, b.MyPropertyB); }
public void FullAuto() { var mapping = Mapping <TestA, TestA> .Auto(); var a = new TestA() { IntTest = 12 }; a.TestB = new TestB { StringTest = "Hello world", ARef = a }; var b = mapping.Clone(a); Assert.AreEqual(12, b.IntTest); Assert.AreEqual("Hello world", b.TestB.StringTest); }
public void AutoWithOverriddenMembers() { var mapping = Mapping <TestA, TestB> .Auto(cfg => cfg .Bind(x => x.MyPropertyA, x => x.MyPropertyB) .Bind(x => x.MyPropertyB, x => x.MyPropertyA)); var a = new TestA() { MyPropertyA = 1, MyPropertyB = 2, MyPropertyC = 3 }; var b = new TestB(); mapping.Map(a, b); Assert.AreEqual(2, b.MyPropertyA); Assert.AreEqual(1, b.MyPropertyB); Assert.AreEqual(3, b.MyPropertyC); }