Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }