Skip to content

Commit 152bfc6

Browse files
committed
Test coverage for mapping nested properties to null inside collections
1 parent efbc140 commit 152bfc6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

AgileMapper.UnitTests/Configuration/WhenMappingToNull.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,29 @@ public void ShouldNotMapCollectionElementsToNull()
157157
}
158158
}
159159

160+
[Fact]
161+
public void ShouldMapCollectionElementNestedPropertiesToNull()
162+
{
163+
using (var mapper = Mapper.CreateNew())
164+
{
165+
mapper.WhenMapping
166+
.To<Address>()
167+
.If((o, a) => a.Line1 == null)
168+
.MapToNull();
169+
170+
var source = new[]
171+
{
172+
new CustomerViewModel { AddressLine1 = null },
173+
new CustomerViewModel { AddressLine1 = "Hello!" }
174+
};
175+
var result = mapper.Map(source).ToANew<IEnumerable<MysteryCustomer>>();
176+
177+
result.First().Address.ShouldBeNull();
178+
result.Second().Address.ShouldNotBeNull();
179+
result.Second().Address.Line1.ShouldBe("Hello!");
180+
}
181+
}
182+
160183
[Fact]
161184
public void ShouldErrorIfConditionsAreConfiguredForTheSameType()
162185
{

0 commit comments

Comments
 (0)