public void ShouldMapToNewISet() { var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistryOverride.AllMappers()); config.CreateMap <SourceWithIEnumerable, TargetWithISet>() .ForMember(dest => dest.Stuff, opt => opt.MapFrom(src => src.Stuff.Select(s => s.Value))); config.AssertConfigurationIsValid(); var engine = new MappingEngine(config); var source = new SourceWithIEnumerable { Stuff = new[] { new TypeWithStringProperty { Value = "Microphone" }, new TypeWithStringProperty { Value = "Check" }, new TypeWithStringProperty { Value = "1, 2" }, new TypeWithStringProperty { Value = "What is this?" } } }; var target = engine.Map <SourceWithIEnumerable, TargetWithISet>(source); }
public void should_inherit_base_aftermap() { // arrange var source = new Class { Prop = "test" }; var configurationProvider = new ConfigurationStore(new TypeMapFactory(), MapperRegistryOverride.AllMappers()); configurationProvider .CreateMap <BaseClass, BaseDto>() .AfterMap((s, d) => d.DifferentProp = s.Prop) .Include <Class, Dto>(); configurationProvider.CreateMap <Class, Dto>(); var mappingEngine = new MappingEngine(configurationProvider); // act var dest = mappingEngine.Map <Class, Dto>(source); // assert "test".ShouldEqual(dest.DifferentProp); }
public void ShouldMapOneToTwo() { var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistryOverride.AllMappers()); config.CreateMap <One, Two>(); config.CreateMap <IEnumerable <string>, IEnumerable <Item> >().ConvertUsing <StringToItemConverter>(); config.AssertConfigurationIsValid(); var engine = new MappingEngine(config); var one = new One { Stuff = new List <string> { "hi", "", "mom" } }; var two = engine.Map <One, Two>(one); two.ShouldNotBeNull(); two.Stuff.Count().ShouldEqual(2); }