File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
AgileMapper.UnitTests/Configuration
AgileMapper/Configuration Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 11namespace AgileObjects . AgileMapper . UnitTests . Configuration
22{
33 using System ;
4+ using System . Collections . Generic ;
5+ using System . Linq ;
46 using AgileMapper . Configuration ;
57 using Shouldly ;
68 using TestClasses ;
@@ -130,6 +132,31 @@ public void ShouldApplyConfiguredConditionsToDerivedTypes()
130132 }
131133 }
132134
135+ [ Fact ]
136+ public void ShouldNotMapCollectionElementsToNull ( )
137+ {
138+ using ( var mapper = Mapper . CreateNew ( ) )
139+ {
140+ mapper . WhenMapping
141+ . To < Address > ( )
142+ . If ( ( o , a ) => a . Line2 == "Delete me" )
143+ . MapToNull ( ) ;
144+
145+ var source = new [ ]
146+ {
147+ new Address { Line1 = "Delete me" } ,
148+ new Address { Line2 = "Delete me" }
149+ } ;
150+ var result = mapper . Map ( source ) . ToANew < ICollection < Address > > ( ) ;
151+
152+ result . First ( ) . ShouldNotBeNull ( ) ;
153+ result . First ( ) . Line1 . ShouldBe ( "Delete me" ) ;
154+
155+ result . Second ( ) . ShouldNotBeNull ( ) ;
156+ result . Second ( ) . Line2 . ShouldBe ( "Delete me" ) ;
157+ }
158+ }
159+
133160 [ Fact ]
134161 public void ShouldErrorIfConditionsAreConfiguredForTheSameType ( )
135162 {
Original file line number Diff line number Diff line change @@ -22,6 +22,16 @@ public override bool ConflictsWith(UserConfiguredItemBase otherConfiguredItem)
2222 return otherCondition . _targetType == _targetType ;
2323 }
2424
25+ public override bool AppliesTo ( IBasicMapperData mapperData )
26+ {
27+ if ( mapperData . TargetMemberIsEnumerableElement ( ) )
28+ {
29+ return false ;
30+ }
31+
32+ return base . AppliesTo ( mapperData ) ;
33+ }
34+
2535 protected override Expression GetConditionOrNull ( IMemberMapperData mapperData , CallbackPosition position )
2636 {
2737 mapperData . Context . UsesMappingDataObjectAsParameter =
You can’t perform that action at this time.
0 commit comments