1+ namespace AgileObjects . AgileMapper . UnitTests
2+ {
3+ using System . Collections . Generic ;
4+ using System . Collections . ObjectModel ;
5+ using Shouldly ;
6+ using TestClasses ;
7+ using Xunit ;
8+
9+ public class WhenViewingDictionaryMappingPlans
10+ {
11+ [ Fact ]
12+ public void ShouldShowATargetObjectMappingPlan ( )
13+ {
14+ var plan = Mapper
15+ . GetPlanFor < Dictionary < string , string > > ( )
16+ . ToANew < CustomerViewModel > ( ) ;
17+
18+ plan . ShouldContain ( "Dictionary<string, string> sourceDictionary_String_String" ) ;
19+ plan . ShouldContain ( "idKey = sourceDictionary_String_String.Keys.FirstOrDefault(key => key.Equals(\" Id\" " ) ;
20+ plan . ShouldContain ( "id = sourceDictionary_String_String[idKey]" ) ;
21+ plan . ShouldContain ( "customerViewModel.Id =" ) ;
22+ plan . ShouldContain ( "Guid.TryParse(id" ) ;
23+ }
24+
25+ [ Fact ]
26+ public void ShouldShowATargetComplexTypeCollectionMappingPlan ( )
27+ {
28+ var plan = Mapper
29+ . GetPlanFor < Dictionary < string , object > > ( )
30+ . ToANew < Collection < Address > > ( ) ;
31+
32+ plan . ShouldContain ( "targetKey = \" [\" + i + \" ]\" " ) ;
33+ plan . ShouldContain ( "elementKeyExists = sourceDictionary_String_Object.ContainsKey(targetKey)" ) ;
34+ plan . ShouldContain ( "var line1Key = \" [\" + i + \" ].Line1\" " ) ;
35+ plan . ShouldContain ( "line1 = sourceDictionary_String_Object[line1Key]" ) ;
36+ plan . ShouldContain ( "address.Line1 = line1.ToString()" ) ;
37+ }
38+
39+ [ Fact ]
40+ public void ShouldShowASourceObjectMappingPlan ( )
41+ {
42+ var plan = Mapper
43+ . GetPlanFor < MysteryCustomer > ( )
44+ . ToANew < Dictionary < string , object > > ( ) ;
45+
46+ plan . ShouldContain ( "dictionary_String_Object = new Dictionary<string, object>()" ) ;
47+ plan . ShouldContain ( "dictionary_String_Object[\" Name\" ] = sourceMysteryCustomer.Name" ) ;
48+ plan . ShouldContain ( "dictionary_String_Object[\" Address.Line1\" ] = sourceMysteryCustomer.Address.Line1;" ) ;
49+ }
50+
51+ [ Fact ]
52+ public void ShouldShowASourceComplexTypeEnumerableMappingPlan ( )
53+ {
54+ var plan = Mapper
55+ . GetPlanFor < IEnumerable < CustomerViewModel > > ( )
56+ . ToANew < Dictionary < string , string > > ( ) ;
57+
58+ plan . ShouldContain ( "sourceMysteryCustomerViewModel = enumerator.Current as MysteryCustomerViewModel" ) ;
59+ plan . ShouldContain ( "dictionary_String_String[\" [\" + i + \" ].Report\" ] = sourceMysteryCustomerViewModel.Report" ) ;
60+ plan . ShouldContain ( "dictionary_String_String[\" [\" + i + \" ].AddressLine1\" ] = enumerator.Current.AddressLine1" ) ;
61+ }
62+
63+ }
64+ }
0 commit comments