コード例 #1
0
        public void Map_ListIsMappedProperty_Success()
        {
            var config = new HappyConfig(cfg =>
            {
                cfg.CreateMap <Src, Dest>();
                cfg.CreateMap <SrcWrap, DestWrap>();
            });

            config.AssertConfigurationIsValid();
            var mapper = config.CompileMapper();

            var srcList = new List <Src>();

            srcList.Add(new Src {
                Value1 = 1
            });

            List <Dest> destList = new List <Dest>();

            destList.Add(new Dest());

            SrcWrap srcWrap = new SrcWrap {
                P1 = srcList
            };
            DestWrap destWrap = new DestWrap {
                P1 = destList
            };

            mapper.Map(srcWrap, destWrap);

            Assert.AreEqual(srcWrap.P1[0].Value1, destWrap.P1[0].Value1);
        }
コード例 #2
0
        public void Mapper_MapNullDestList_CreatesList()
        {
            var config = new HappyConfig(cfg =>
            {
                cfg.CreateMap <SrcWrap, DestWrap>();
                cfg.CreateMap <SrcChild, DestChild>();
            });
            var mapper = config.CompileMapper();

            var src = new SrcWrap {
                List = new List <SrcChild> {
                    new SrcChild {
                        P1 = 1
                    }
                }
            };
            var dest = new DestWrap();

            Assert.IsNull(dest.List);

            mapper.Map(src, dest);

            Assert.IsTrue(dest.List.Count > 0);
        }