public void Should_replace_destination_list() { Mapper.CreateMap <MasterDto, MasterWithList>(); Mapper.CreateMap <DetailDto, Detail>(); var dto = new MasterDto { Id = 1, Details = new[] { new DetailDto { Id = 2 }, new DetailDto { Id = 3 }, } }; var master = new MasterWithList(); IList <Detail> originalCollection = master.Details; Mapper.Map(dto, master); Assert.That(master.Details, Is.Not.SameAs(originalCollection)); }
public void Should_keep_and_fill_destination_list() { Mapper.CreateMap <MasterDto, MasterWithList>() .ForMember(d => d.Details, o => o.UseDestinationValue()); Mapper.CreateMap <DetailDto, Detail>(); var dto = new MasterDto { Id = 1, Details = new[] { new DetailDto { Id = 2 }, new DetailDto { Id = 3 }, } }; var master = new MasterWithList(); IList <Detail> originalCollection = master.Details; Mapper.Map(dto, master); Assert.That(master.Details, Is.SameAs(originalCollection)); Assert.That(master.Details.Count, Is.EqualTo(originalCollection.Count)); }
public void Should_not_replace_destination_list() { Mapper.CreateMap <MasterDto, MasterWithList>(); Mapper.CreateMap <DetailDto, Detail>(); var dto = new MasterDto { Id = 1, Details = new[] { new DetailDto { Id = 2 }, new DetailDto { Id = 3 }, } }; var master = new MasterWithList(); var originalCollection = master.Details; Mapper.Map(dto, master); originalCollection.ShouldBeSameAs(master.Details); }
public void Should_not_replace_destination_list() { var config = new MapperConfiguration(cfg => { cfg.CreateMap <MasterDto, MasterWithList>() .ForMember(d => d.Details, opt => opt.UseDestinationValue()); cfg.CreateMap <DetailDto, Detail>(); }); var dto = new MasterDto { Id = 1, Details = new[] { new DetailDto { Id = 2 }, new DetailDto { Id = 3 }, } }; var master = new MasterWithList(); IList <Detail> originalCollection = master.Details; config.CreateMapper().Map(dto, master); originalCollection.ShouldBeSameAs(master.Details); }
public void Should_keep_and_fill_destination_list() { Mapper.CreateMap <MasterDto, MasterWithList>() .ForMember(d => d.Details, o => o.UseDestinationValue()); Mapper.CreateMap <DetailDto, Detail>(); var dto = new MasterDto { Id = 1, Details = new[] { new DetailDto { Id = 2 }, new DetailDto { Id = 3 }, } }; var master = new MasterWithList(); var originalCollection = master.Details; Mapper.Map(dto, master); originalCollection.ShouldBeSameAs(master.Details); originalCollection.Count.ShouldBe(master.Details.Count); }