|
| 1 | +using System.Collections.Generic; |
| 2 | +using AutoMapper.EquivalencyExpression; |
| 3 | +using FluentAssertions; |
| 4 | +using Xunit; |
| 5 | + |
| 6 | +namespace AutoMapper.Collection |
| 7 | +{ |
| 8 | + public class NullableIdTests |
| 9 | + { |
| 10 | + [Fact] |
| 11 | + public void Should_Work_With_Null_Id() |
| 12 | + { |
| 13 | + Mapper.Reset(); |
| 14 | + Mapper.Initialize(x => |
| 15 | + { |
| 16 | + x.AddCollectionMappers(); |
| 17 | + x.CreateMap<ThingWithStringIdDto, ThingWithStringId>().EqualityComparison((dto, entity) => dto.ID == entity.ID); |
| 18 | + }); |
| 19 | + |
| 20 | + var original = new List<ThingWithStringId> |
| 21 | + { |
| 22 | + new ThingWithStringId { ID = "1", Title = "test0" }, |
| 23 | + new ThingWithStringId { ID = "2", Title = "test2" }, |
| 24 | + }; |
| 25 | + |
| 26 | + var dtos = new List<ThingWithStringIdDto> |
| 27 | + { |
| 28 | + new ThingWithStringIdDto { ID = "1", Title = "test0" }, |
| 29 | + new ThingWithStringIdDto { ID = "2", Title = "test2" }, |
| 30 | + new ThingWithStringIdDto { Title = "test3" } |
| 31 | + }; |
| 32 | + |
| 33 | + Mapper.Map(dtos, original); |
| 34 | + |
| 35 | + original.Should().HaveSameCount(dtos); |
| 36 | + } |
| 37 | + |
| 38 | + public class ThingWithStringId |
| 39 | + { |
| 40 | + public string ID { get; set; } |
| 41 | + public string Title { get; set; } |
| 42 | + public override string ToString() { return Title; } |
| 43 | + } |
| 44 | + |
| 45 | + public class ThingWithStringIdDto |
| 46 | + { |
| 47 | + public string ID { get; set; } |
| 48 | + public string Title { get; set; } |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments