Skip to content

Commit 71a73da

Browse files
committed
Test coverage for restricting map-to-null conditions by source type
1 parent 020ee85 commit 71a73da

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

AgileMapper.Net40/AgileMapper.Net40.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
<Compile Include="..\VersionInfo.cs">
5353
<Link>Properties\VersionInfo.cs</Link>
5454
</Compile>
55-
<Compile Include="Configuration\MapToNullCondition.cs" />
5655
<Compile Include="Properties\AssemblyInfo.Net40.cs" />
5756
</ItemGroup>
5857
<ItemGroup>

AgileMapper.UnitTests/Configuration/WhenMappingToNull.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,37 @@ public void ShouldApplyAUserConfiguredCondition()
2222
result.Address.ShouldBeNull();
2323
}
2424
}
25+
26+
[Fact]
27+
public void ShouldRestrictAConfiguredMapToNullConditionBySourceType()
28+
{
29+
using (var mapper = Mapper.CreateNew())
30+
{
31+
mapper.WhenMapping
32+
.From<CustomerViewModel>()
33+
.To<Address>()
34+
.If((o, a) => a.Line1 == "Null!")
35+
.MapToNull();
36+
37+
var nonMatchingSource = new Customer
38+
{
39+
Name = "Jen",
40+
Address = new Address { Line1 = "Null!" }
41+
};
42+
var nonMatchingResult = mapper.Map(nonMatchingSource).ToANew<Customer>();
43+
44+
nonMatchingResult.Address.ShouldNotBeNull();
45+
nonMatchingResult.Address.Line1.ShouldBe("Null!");
46+
47+
var matchingSource = new CustomerViewModel
48+
{
49+
Name = "Frank",
50+
AddressLine1 = "Null!"
51+
};
52+
var matchingResult = mapper.Map(matchingSource).ToANew<Customer>();
53+
54+
matchingResult.Address.ShouldBeNull();
55+
}
56+
}
2557
}
2658
}

0 commit comments

Comments
 (0)