public void FlattenFatherSonGrandsonDtoWithDestinationOk() { //SETUP Mapper.Register <Father, FlattenFatherSonGrandsonDto>() .Flatten(); Mapper.Compile(CompilationTypes.Destination); //ATTEMPT var dto = new FlattenFatherSonGrandsonDto { MyInt = 29387465, MyString = "whjqegfqwjehfg" }; var father = Father.CreateOne(); Mapper.Map(father, dto); //VERIFY Assert.AreEqual("Father", dto.MyString); //This is mapped by the normal ExpressMapper Assert.AreEqual(1, dto.MyInt); //This is mapped by the normal ExpressMapper Assert.AreEqual("Son", dto.SonMyString); Assert.AreEqual(2, dto.SonMyInt); Assert.AreEqual("Grandson", dto.SonGrandsonMyString); Assert.AreEqual(3, dto.SonGrandsonMyInt); }
public void FlattenFatherSonGrandsonDtoIgnoreSonMyStringOk() { //SETUP Mapper.Register <Father, FlattenFatherSonGrandsonDto>() .Ignore(dest => dest.SonMyString) .Flatten(); Mapper.Compile(CompilationTypes.Source); //ATTEMPT var dto = Mapper.Map <Father, FlattenFatherSonGrandsonDto>(Father.CreateOne()); //VERIFY Assert.AreEqual("Father", dto.MyString); Assert.AreEqual(null, dto.SonMyString); Assert.AreEqual("Grandson", dto.SonGrandsonMyString); }
public void FlattenFatherSonGrandsonDtoOverrideSonGrandsonMyStringOk() { //SETUP Mapper.Register <Father, FlattenFatherSonGrandsonDto>() .Member(dest => dest.SonGrandsonMyString, src => src.MyString) .Flatten(); Mapper.Compile(CompilationTypes.Source); //ATTEMPT var father = Father.CreateOne(); var dto = Mapper.Map <Father, FlattenFatherSonGrandsonDto>(father); //VERIFY Assert.AreEqual("Father", dto.MyString); Assert.AreEqual("Son", dto.SonMyString); Assert.AreEqual("Father", dto.SonGrandsonMyString); }
public void FlattenFatherSonGrandsonLowerCaseDtoCaseSensativeOk() { //SETUP Mapper.Register <Father, FlattenFatherSonGrandsonLowerCaseDto>() .CaseSensitive(true) .Flatten(); Mapper.Compile(CompilationTypes.Source); //ATTEMPT var dto = Mapper.Map <Father, FlattenFatherSonGrandsonLowerCaseDto>(Father.CreateOne()); //VERIFY Assert.AreEqual(null, dto.mystring); //This is mapped by the normal ExpressMapper Assert.AreEqual(0, dto.myInt); //This is mapped by the normal ExpressMapper Assert.AreEqual(null, dto.sonMyString); Assert.AreEqual(0, dto.Sonmyint); Assert.AreEqual(null, dto.SongrandsonmYstring); Assert.AreEqual(null, dto.sonGrandsonMyInt); }
public void FlattenFatherSonGrandsonDtoCaseSensativeOk() { //SETUP Mapper.Register <Father, FlattenFatherSonGrandsonDto>().CaseSensitive(true) .Flatten(); Mapper.Compile(CompilationTypes.Source); //ATTEMPT var father = Father.CreateOne(); var dto = Mapper.Map <Father, FlattenFatherSonGrandsonDto>(father); //VERIFY Assert.AreEqual("Father", dto.MyString); //This is mapped by the normal ExpressMapper Assert.AreEqual(1, dto.MyInt); //This is mapped by the normal ExpressMapper Assert.AreEqual("Son", dto.SonMyString); Assert.AreEqual(2, dto.SonMyInt); Assert.AreEqual("Grandson", dto.SonGrandsonMyString); Assert.AreEqual(3, dto.SonGrandsonMyInt); }
public void FlattenFatherSonDtoForGrandsonDtoForgetFlattenSimpleClassOk() { //SETUP //Mapper.Register<Grandson, FlattenSimpleClass>(); //If you don't supply the mapping it does not happen Mapper.Register <Father, FlattenFatherSonDtoForGrandsonDto>() .Flatten(); Mapper.Compile(CompilationTypes.Source); //ATTEMPT var father = Father.CreateOne(); var dto = Mapper.Map <Father, FlattenFatherSonDtoForGrandsonDto>(father); //VERIFY Assert.AreEqual("Father", dto.MyString); //This is mapped by the normal ExpressMapper Assert.AreEqual(1, dto.MyInt); //This is mapped by the normal ExpressMapper Assert.AreEqual("Son", dto.SonMyString); Assert.AreEqual(2, dto.SonMyInt); Assert.AreEqual(null, dto.SonGrandson); }
protected override void Setup() { Context.Set <Father>().Add(Father.CreateOne(1)); //Father->Son->Grandson var fatherWithoutGrandson = Father.CreateOne(2); fatherWithoutGrandson.Son.Grandson = null; Context.Set <Father>().Add(fatherWithoutGrandson); //Father->Son Context.Set <FatherSons>().Add(FatherSons.CreateOne()); //FatherSons->5 Sons Context.SaveChanges(); Mapper.Register <Father, FlattenFatherSonGrandsonDto>().Flatten(); Mapper.Register <FatherSons, FlattenFatherSonsCountDto>().Flatten(); Mapper.Register <Grandson, FlattenSimpleClass>(); Mapper.Register <Father, FlattenFatherSonDtoForGrandsonDto>() .Flatten(); Mapper.Compile(CompilationTypes.Source); }