Skip to content

Commit 092b891

Browse files
committed
Extra mapping validation test coverage
1 parent e88a9bc commit 092b891

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

AgileMapper.UnitTests/WhenValidatingMappings.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace AgileObjects.AgileMapper.UnitTests
22
{
33
using System;
4+
using System.Collections.Generic;
45
using Shouldly;
56
using TestClasses;
67
using Validation;
@@ -111,6 +112,40 @@ public void ShouldErrorIfComplexTypeMemberIsUnconstructable()
111112
}
112113
}
113114

115+
[Fact]
116+
public void ShouldNotErrorIfConstructableComplexTypeMemberHasNoMatchingSource()
117+
{
118+
using (var mapper = Mapper.CreateNew())
119+
{
120+
mapper.WhenMapping
121+
.From<CustomerViewModel>()
122+
.To<Customer>()
123+
.Ignore(c => c.Title, c => c.Address.Line2);
124+
125+
mapper.GetPlanFor<CustomerViewModel>().ToANew<Customer>();
126+
127+
Should.NotThrow(() => mapper.ThrowNowIfAnyMappingPlanIsIncomplete());
128+
}
129+
}
130+
131+
[Fact]
132+
public void ShouldErrorIfEnumerableMemberHasNonEnumerableSource()
133+
{
134+
using (var mapper = Mapper.CreateNew())
135+
{
136+
mapper
137+
.GetPlanFor<PublicField<Address>>()
138+
.ToANew<PublicProperty<ICollection<string>>>();
139+
140+
var validationEx = Should.Throw<MappingValidationException>(() =>
141+
mapper.ThrowNowIfAnyMappingPlanIsIncomplete());
142+
143+
validationEx.Message.ShouldContain("PublicField<Address> -> PublicProperty<ICollection<string>>");
144+
validationEx.Message.ShouldContain("Unmapped target members");
145+
validationEx.Message.ShouldContain("PublicProperty<ICollection<string>>.Value");
146+
}
147+
}
148+
114149
[Fact]
115150
public void ShouldShowMultipleIncompleteCachedMappingPlans()
116151
{

0 commit comments

Comments
 (0)