public void MapModel_WithCustomMappingForOtherProperty_ShouldMap() { var config = new MapperConfiguration(cfg => { cfg .CreateMap <MyCustomLinkedSource, MyCustomDto>() .MapLinkedSource() .ForMember(destination => destination.SelfUrl, opt => opt.MapFrom(src => "http://blah.com/" + src.Model.Id)); }); config.AssertConfigurationIsValid(); var mapper = config.CreateMapper(); var source = new MyCustomLinkedSource { Model = CreateMyCustomModel(1), }; var actual = mapper.Map <MyCustomDto>(source); Assert.Equal("http://blah.com/" + source.Model.Id, actual.SelfUrl); }
public void MapModel_WithCustomMappingForModelProperty_ShouldMap() { var config = new MapperConfiguration(cfg => { cfg .CreateMap <MyCustomLinkedSource, MyCustomDto>() .MapLinkedSource() .ForMember(destination => destination.Title, opt => opt.MapFrom(src => src.Model.Title + " TEST")) .ForMember(destination => destination.SelfUrl, opt => opt.Ignore()); }); config.AssertConfigurationIsValid(); var mapper = config.CreateMapper(); var source = new MyCustomLinkedSource { Model = CreateMyCustomModel(1), }; var actual = mapper.Map <MyCustomDto>(source); Assert.Equal(source.Model.Title + " TEST", actual.Title); }