public void Should_replace_destination_collection() { Mapper.CreateMap <MasterDto, MasterWithCollection>(); Mapper.CreateMap <DetailDto, Detail>(); var dto = new MasterDto { Id = 1, Details = new[] { new DetailDto { Id = 2 }, new DetailDto { Id = 3 }, } }; var master = new MasterWithCollection(new List <Detail>()); ICollection <Detail> originalCollection = master.Details; Mapper.Map(dto, master); Assert.That(master.Details, Is.Not.SameAs(originalCollection)); }
public void Should_keep_and_fill_destination_collection_when_collection_is_implemented_as_list() { Mapper.CreateMap <MasterDto, MasterWithCollection>() .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 MasterWithCollection(new List <Detail>()); ICollection <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_keep_and_fill_destination_collection_when_collection_is_implemented_as_set_with_aftermap() { Mapper.CreateMap <MasterDto, MasterWithCollection>() .ForMember(d => d.Details, o => o.Ignore()) .AfterMap((s, d) => FillCollection(s, d, ss => ss.Details, dd => dd.Details)); Mapper.CreateMap <DetailDto, Detail>(); var dto = new MasterDto { Id = 1, Details = new[] { new DetailDto { Id = 2 }, new DetailDto { Id = 3 }, } }; var master = new MasterWithCollection(new HashSet <Detail>()); ICollection <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_collection() { var config = new MapperConfiguration(cfg => { cfg.CreateMap <MasterDto, MasterWithCollection>() .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 MasterWithCollection(new List <Detail>()); ICollection <Detail> originalCollection = master.Details; config.CreateMapper().Map(dto, master); originalCollection.ShouldBeSameAs(master.Details); }
public void Should_keep_and_fill_destination_collection_when_collection_is_implemented_as_set_with_aftermap() { var config = new MapperConfiguration(cfg => { cfg.CreateMap <MasterDto, MasterWithCollection>() .ForMember(d => d.Details, o => o.Ignore()) .AfterMap((s, d) => FillCollection(s, d, ss => ss.Details, dd => dd.Details)); cfg.CreateMap <DetailDto, Detail>(); }); var dto = new MasterDto { Id = 1, Details = new[] { new DetailDto { Id = 2 }, new DetailDto { Id = 3 }, } }; var master = new MasterWithCollection(new HashSet <Detail>()); ICollection <Detail> originalCollection = master.Details; mapper = config.CreateMapper(); mapper.Map(dto, master); originalCollection.ShouldBeSameAs(master.Details); originalCollection.Count.ShouldEqual(master.Details.Count); }
public void Should_keep_and_fill_destination_collection_when_collection_is_implemented_as_list() { var config = new MapperConfiguration(cfg => { cfg.CreateMap <MasterDto, MasterWithCollection>() .ForMember(d => d.Details, o => o.UseDestinationValue()); cfg.CreateMap <DetailDto, Detail>(); }); var dto = new MasterDto { Id = 1, Details = new[] { new DetailDto { Id = 2 }, new DetailDto { Id = 3 }, } }; var master = new MasterWithCollection(new List <Detail>()); ICollection <Detail> originalCollection = master.Details; config.CreateMapper().Map(dto, master); originalCollection.ShouldBeSameAs(master.Details); originalCollection.Count.ShouldEqual(master.Details.Count); }
public void Should_not_replace_destination_collection() { Mapper.CreateMap <MasterDto, MasterWithCollection>(); Mapper.CreateMap <DetailDto, Detail>(); var dto = new MasterDto { Id = 1, Details = new[] { new DetailDto { Id = 2 }, new DetailDto { Id = 3 }, } }; var master = new MasterWithCollection(new List <Detail>()); var originalCollection = master.Details; Mapper.Map(dto, master); originalCollection.ShouldBeSameAs(master.Details); }
public void Should_keep_and_fill_destination_collection_when_collection_is_implemented_as_set() { Mapper.CreateMap <MasterDto, MasterWithCollection>() .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 MasterWithCollection(new HashSet <Detail>()); var originalCollection = master.Details; Mapper.Map(dto, master); originalCollection.ShouldBeSameAs(master.Details); originalCollection.Count.ShouldBe(master.Details.Count); }