|
| 1 | +using NUnit.Framework; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Dynamic; |
| 5 | +using System.Linq; |
| 6 | +using System.Text; |
| 7 | + |
| 8 | +namespace Slapper.Tests |
| 9 | +{ |
| 10 | + [TestFixture] |
| 11 | + class MapUniqueChildsIdTest |
| 12 | + { |
| 13 | + public class NameValue |
| 14 | + { |
| 15 | + public int Id { get; set; } |
| 16 | + public string Name { get; set; } |
| 17 | + |
| 18 | + public IEnumerable<NameValue> Phones { get; set; } |
| 19 | + public IEnumerable<NameValue> Emails { get; set; } |
| 20 | + } |
| 21 | + |
| 22 | + [Test] |
| 23 | + public void Can_Map_DifferentsRows_to_Same_object() |
| 24 | + { |
| 25 | + dynamic dynamicCustomer = new ExpandoObject(); |
| 26 | + dynamicCustomer.Id = 1; |
| 27 | + dynamicCustomer.Name = "Clark"; |
| 28 | + dynamicCustomer.Phones_Id = 1; |
| 29 | + dynamicCustomer.Phones_Name = "88888"; |
| 30 | + dynamicCustomer.Emails_Id = "1"; |
| 31 | + dynamicCustomer.Emails_Name = "[email protected]"; |
| 32 | + |
| 33 | + dynamic dynamicCustomer2 = new ExpandoObject(); |
| 34 | + dynamicCustomer2.Id = 1; |
| 35 | + dynamicCustomer2.Name = "Clark"; |
| 36 | + dynamicCustomer2.Phones_Id = 2; |
| 37 | + dynamicCustomer2.Phones_Name = "99999"; |
| 38 | + dynamicCustomer2.Emails_Id = "2"; |
| 39 | + dynamicCustomer2.Emails_Name = "[email protected]"; |
| 40 | + |
| 41 | + var list = new List<dynamic> { dynamicCustomer, dynamicCustomer2 }; |
| 42 | + var customer = Slapper.AutoMapper.MapDynamic<NameValue>(list).FirstOrDefault(); |
| 43 | + |
| 44 | + Assert.NotNull(customer); |
| 45 | + Assert.AreNotEqual(customer.Emails.FirstOrDefault(e => e.Id == 1).Name, customer.Phones.FirstOrDefault(p => p.Id == 1).Name); |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments