Example #1
0
            public void can_customize_collection_element_mapping()
            {
                var source = new SourceBrandCollection
                {
                    Brands = new List <SourceBrand> {
                        new SourceBrand {
                            Name = "Nike"
                        },
                        new SourceBrand {
                            Name = "Puma"
                        }
                    }
                };

                var mapper = new DefaultObjectMapper();

                mapper.GetMapper = (sourceType, targetType) =>
                {
                    if (sourceType == typeof(SourceBrand))
                    {
                        return(new BrandMapper());
                    }

                    return(mapper);
                };

                var context = new MappingContext(new LocalApiContext(new ApiContext(), null));

                context.Includes.Add("Brands");

                var target = mapper.Map(source, new TargetBrandCollection(), typeof(SourceBrandCollection), typeof(TargetBrandCollection), null, context) as TargetBrandCollection;

                Assert.Equal(2, target.Brands.Count);
                Assert.Equal("Nike (Customized)", target.Brands.First().Name);
                Assert.Equal("Puma (Customized)", target.Brands.Skip(1).First().Name);
            }
            public void can_customize_collection_element_mapping()
            {
                var source = new SourceBrandCollection
                {
                    Brands = new List<SourceBrand> {
                        new SourceBrand { Name = "Nike" },
                        new SourceBrand { Name = "Puma" }
                    }
                };

                var mapper = new DefaultObjectMapper();
                mapper.GetMapper = (sourceType, targetType) =>
                {
                    if (sourceType == typeof(SourceBrand))
                    {
                        return new BrandMapper();
                    }

                    return mapper;
                };

                var context = new MappingContext(new LocalApiContext(new ApiContext(), null));
                context.Includes.Add("Brands");

                var target = mapper.Map(source, new TargetBrandCollection(), typeof(SourceBrandCollection), typeof(TargetBrandCollection), null, context) as TargetBrandCollection;

                Assert.Equal(2, target.Brands.Count);
                Assert.Equal("Nike (Customized)", target.Brands.First().Name);
                Assert.Equal("Puma (Customized)", target.Brands.Skip(1).First().Name);
            }