コード例 #1
0
        public void Example()
        {
            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap<ContainsASrc, ContainsADest>();

                cfg.CreateMap<ASrc, ADest>()
                    .Include<BSrc, BDest>()
                    .Include<CSrc, CDest>();

                cfg.CreateMap<BSrc, BDest>()
                    .Include<CSrc, CDest>();

                cfg.CreateMap<CSrc, CDest>();
            });

            var expectedCSrc = new CSrc() {StringA = "A", StringB = "B", StringC = "C"};
            var expectedBSrc = new BSrc() {StringA = "A", StringB = "B"};

            var expectedContCSrc = new ContainsASrc() {A = expectedCSrc};
            var expectedContBSrc = new ContainsASrc() {A = expectedBSrc};

            var actualContCDest = Mapper.Map<ContainsASrc, ContainsADest>(expectedContCSrc);
            var actualContBDest = Mapper.Map<ContainsASrc, ContainsADest>(expectedContBSrc); // THROWS

            Mapper.AssertConfigurationIsValid();
            actualContBDest.ShouldNotBeNull();
            actualContCDest.ShouldNotBeNull();
        }
コード例 #2
0
        public void Example()
        {
            var config = new MapperConfiguration(
                cfg =>
            {
                cfg.CreateMap <ContainsASrc, ContainsADest>();

                cfg.CreateMap <ASrc, ADest>().Include <BSrc, BDest>().Include <CSrc, CDest>();

                cfg.CreateMap <BSrc, BDest>().Include <CSrc, CDest>();

                cfg.CreateMap <CSrc, CDest>();
            }
                );

            var expectedCSrc = new CSrc()
            {
                StringA = "A",
                StringB = "B",
                StringC = "C"
            };
            var expectedBSrc = new BSrc()
            {
                StringA = "A", StringB = "B"
            };

            var expectedContCSrc = new ContainsASrc()
            {
                A = expectedCSrc
            };
            var expectedContBSrc = new ContainsASrc()
            {
                A = expectedBSrc
            };

            var mapper          = config.CreateMapper();
            var actualContCDest = mapper.Map <ContainsASrc, ContainsADest>(expectedContCSrc);
            var actualContBDest = mapper.Map <ContainsASrc, ContainsADest>(expectedContBSrc); // THROWS

            config.AssertConfigurationIsValid();
            actualContBDest.ShouldNotBeNull();
            actualContCDest.ShouldNotBeNull();
        }
コード例 #3
0
        public void Example()
        {
            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <ContainsASrc, ContainsADest>();

                cfg.CreateMap <ASrc, ADest>()
                .Include <BSrc, BDest>()
                .Include <CSrc, CDest>();

                cfg.CreateMap <BSrc, BDest>()
                .Include <CSrc, CDest>();

                cfg.CreateMap <CSrc, CDest>();
            });

            var expectedCSrc = new CSrc()
            {
                StringA = "A", StringB = "B", StringC = "C"
            };
            var expectedBSrc = new BSrc()
            {
                StringA = "A", StringB = "B"
            };

            var expectedContCSrc = new ContainsASrc()
            {
                A = expectedCSrc
            };
            var expectedContBSrc = new ContainsASrc()
            {
                A = expectedBSrc
            };

            var actualContCDest = Mapper.Map <ContainsASrc, ContainsADest>(expectedContCSrc);
            var actualContBDest = Mapper.Map <ContainsASrc, ContainsADest>(expectedContBSrc); // THROWS

            Mapper.AssertConfigurationIsValid();
            Assert.IsNotNull(actualContBDest);
            Assert.IsNotNull(actualContCDest);
        }