Ejemplo n.º 1
0
        public void Should_map_the_existing_array_elements_over()
        {
            var sourceList = new List <SourceObject>();
            var destList   = new List <DestObject>();

            var config = new MapperConfiguration(cfg => cfg.CreateMap <SourceObject, DestObject>());

            config.AssertConfigurationIsValid();

            var source1 = new SourceObject {
                Id = 1,
            };

            sourceList.Add(source1);

            var source2 = new SourceObject {
                Id = 2,
            };

            sourceList.Add(source2);

            source1.AddChild(source2); // This causes the problem

            config.CreateMapper().Map(sourceList, destList);

            destList.Count.ShouldBe(2);
            destList[0].Children.Count.ShouldBe(1);
            destList[0].Children[0].ShouldBeSameAs(destList[1]);
        }
Ejemplo n.º 2
0
            public void Should_map_the_existing_array_elements_over()
            {
                var sourceList = new List<SourceObject>();
                var destList = new List<DestObject>();

                var config = new MapperConfiguration(cfg => cfg.CreateMap<SourceObject, DestObject>().PreserveReferences());
                config.AssertConfigurationIsValid();

                var source1 = new SourceObject
                {
                    Id = 1,
                };
                sourceList.Add(source1);

                var source2 = new SourceObject
                {
                    Id = 2,
                };
                sourceList.Add(source2);

                source1.AddChild(source2); // This causes the problem

                config.CreateMapper().Map(sourceList, destList);

                destList.Count.ShouldEqual(2);
                destList[0].Children.Count.ShouldEqual(1);
                destList[0].Children[0].ShouldBeSameAs(destList[1]);
            }