|
| 1 | +using System.Collections.Generic; |
| 2 | +using AutoMapper.EquivalencyExpression; |
| 3 | +using FluentAssertions; |
| 4 | +using Xunit; |
| 5 | + |
| 6 | +namespace AutoMapper.Collection |
| 7 | +{ |
| 8 | + public class NotExistingTests |
| 9 | + { |
| 10 | + [Fact] |
| 11 | + public void Should_not_throw_exception_for_nonexisting_types() |
| 12 | + { |
| 13 | + var configuration = new MapperConfiguration(x => |
| 14 | + { |
| 15 | + //x.CreateMissingTypeMaps = false; |
| 16 | + x.AddCollectionMappers(); |
| 17 | + }); |
| 18 | + IMapper mapper = new Mapper(configuration); |
| 19 | + |
| 20 | + var system = new System |
| 21 | + { |
| 22 | + Name = "My First System", |
| 23 | + Contacts = new List<Contact> |
| 24 | + { |
| 25 | + new Contact |
| 26 | + { |
| 27 | + Name = "John", |
| 28 | + Emails = new List<Email>() |
| 29 | + { |
| 30 | + new Email |
| 31 | + { |
| 32 | + |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + }; |
| 38 | + |
| 39 | + mapper.Map<SystemViewModel>(system); |
| 40 | + } |
| 41 | + |
| 42 | + public class System |
| 43 | + { |
| 44 | + public int Id { get; set; } |
| 45 | + public string Name { get; set; } |
| 46 | + |
| 47 | + public ICollection<Contact> Contacts { get; set; } |
| 48 | + } |
| 49 | + |
| 50 | + public class Contact |
| 51 | + { |
| 52 | + public int Id { get; set; } |
| 53 | + public int SystemId { get; set; } |
| 54 | + public string Name { get; set; } |
| 55 | + |
| 56 | + public System System { get; set; } |
| 57 | + |
| 58 | + public ICollection<Email> Emails { get; set; } |
| 59 | + } |
| 60 | + |
| 61 | + public class Email |
| 62 | + { |
| 63 | + public int Id { get; set; } |
| 64 | + |
| 65 | + public int ContactId { get; set; } |
| 66 | + public string Address { get; set; } |
| 67 | + |
| 68 | + public Contact Contact { get; set; } |
| 69 | + } |
| 70 | + |
| 71 | + public class SystemViewModel |
| 72 | + { |
| 73 | + public int Id { get; set; } |
| 74 | + public string Name { get; set; } |
| 75 | + |
| 76 | + public ICollection<ContactViewModel> Contacts { get; set; } |
| 77 | + } |
| 78 | + |
| 79 | + public class ContactViewModel |
| 80 | + { |
| 81 | + public int Id { get; set; } |
| 82 | + public int SystemId { get; set; } |
| 83 | + public string Name { get; set; } |
| 84 | + |
| 85 | + public SystemViewModel System { get; set; } |
| 86 | + |
| 87 | + public ICollection<EmailViewModel> Emails { get; set; } |
| 88 | + } |
| 89 | + |
| 90 | + public class EmailViewModel |
| 91 | + { |
| 92 | + public int Id { get; set; } |
| 93 | + public int ContactId { get; set; } |
| 94 | + public string Address { get; set; } |
| 95 | + |
| 96 | + public ContactViewModel Contact { get; set; } |
| 97 | + } |
| 98 | + } |
| 99 | +} |
0 commit comments