File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
AgileMapper.UnitTests/Configuration
AgileMapper/Configuration Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff 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}
File renamed without changes.
You can’t perform that action at this time.
0 commit comments