Skip to content

Commit b5e6f11

Browse files
committed
Test coverage for dictionary mapping plans
1 parent 6481a3a commit b5e6f11

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

AgileMapper.UnitTests/AgileMapper.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
<Compile Include="WhenMappingToNewDictionaryMembers.cs" />
132132
<Compile Include="WhenMappingToNewDictionaries.cs" />
133133
<Compile Include="WhenUsingPartialTrust.cs" />
134+
<Compile Include="WhenViewingDictionaryMappingPlans.cs" />
134135
<Compile Include="WhenViewingMappingPlans.cs" />
135136
<Compile Include="Reflection\WhenAccessingTypeInformation.cs" />
136137
<Compile Include="SimpleTypeConversion\WhenConvertingToDoubles.cs" />
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)