public void ShouldMapAllWithObject() { var now = DateTime.Now; var fooAll = new FooAll() { Property1 = 87, Property2 = "Hello", Property3 = true, Property4 = now, FooSingle = new Foo() { Property1 = 51 }, Foos = new [] { new Foo() { Property1 = 1 }, new Foo() { Property1 = 2 }, new Foo() { Property1 = 3 }, new FooX() { Property1 = 4, Property2 = 11 } } }; var mapper = CreateMapper(new ResolverMock(), builder => { builder.CreateMap <Foo, Bar>() .MapProperty(x => x.Property1, x => x.Property3); builder.CreateMap <FooX, BarX>() .MapProperty(x => x.Property2, x => x.Property4); builder.CreateMap <FooAll, BarAll>() .MapAll(); }); var barAll = mapper.Map <BarAll>(fooAll); Assert.AreEqual(87, barAll.Property1); Assert.AreEqual(now, barAll.Property4); Assert.AreEqual(1, barAll.Foos[0].Property3); Assert.AreEqual(51, barAll.FooSingle.Property3); Assert.AreEqual(2, barAll.Foos[1].Property3); Assert.AreEqual(3, barAll.Foos[2].Property3); Assert.AreEqual(4, barAll.Foos[3].Property3); Assert.AreEqual(11, ((BarX)barAll.Foos[3]).Property4); }
public void ShouldMapAllExcept() { var now = DateTime.Now; var fooAll = new FooAll() { Property1 = 59, Property2 = "Hello", Property3 = true, Property4 = now }; var mapper = CreateMapper(new ResolverMock(), builder => { builder.CreateMap <FooAll, BarAll>() .MapAll() .Ignore(x => x.FooSingle).Ignore(x => x.Foos).Ignore(x => x.Property1).Ignore(x => x.Property2); }); var barAll = mapper.Map <BarAll>(fooAll); Assert.AreEqual(0, barAll.Property1); Assert.AreEqual(null, barAll.Property2); Assert.AreEqual(true, barAll.Property3); Assert.AreEqual(now, barAll.Property4); }