Skip to content

Commit 41060ac

Browse files
committed
Test coverage for source and target type specific member filtering by path
1 parent bf6679d commit 41060ac

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

AgileMapper.UnitTests/Configuration/WhenIgnoringMembersByFilter.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,5 +322,37 @@ public void ShouldIgnoreMembersBySourceTypeTargetTypeAndNameMatch()
322322
nonMatchingResult.Value2.ShouldBe(-2);
323323
}
324324
}
325+
326+
[Fact]
327+
public void ShouldIgnoreMembersBySourceTypeTargetTypeAndPathMatch()
328+
{
329+
using (var mapper = Mapper.CreateNew())
330+
{
331+
mapper.WhenMapping
332+
.From<PublicField<Address>>()
333+
.To<PublicProperty<Address>>()
334+
.IgnoreTargetMembersWhere(member =>
335+
member.Path.Equals("Value.Line2", StringComparison.OrdinalIgnoreCase));
336+
337+
var matchingSource = new PublicField<Address> { Value = new Address { Line1 = "Here", Line2 = "Here!" } };
338+
var nonMatchingSource = new { Value = new Address { Line1 = "There", Line2 = "There!" } };
339+
340+
var matchingResult = mapper.Map(matchingSource).ToANew<PublicProperty<Address>>();
341+
matchingResult.Value.Line1.ShouldBe("Here");
342+
matchingResult.Value.Line2.ShouldBeDefault();
343+
344+
var nonMatchingTargetResult = mapper.Map(matchingSource).ToANew<PublicField<Address>>();
345+
nonMatchingTargetResult.Value.Line1.ShouldBe("Here");
346+
nonMatchingTargetResult.Value.Line2.ShouldBe("Here!");
347+
348+
var nonMatchingSourceResult = mapper.Map(nonMatchingSource).ToANew<PublicProperty<Address>>();
349+
nonMatchingSourceResult.Value.Line1.ShouldBe("There");
350+
nonMatchingSourceResult.Value.Line2.ShouldBe("There!");
351+
352+
var nonMatchingResult = mapper.Map(nonMatchingSource).ToANew<PublicField<Address>>();
353+
nonMatchingResult.Value.Line1.ShouldBe("There");
354+
nonMatchingResult.Value.Line2.ShouldBe("There!");
355+
}
356+
}
325357
}
326358
}

0 commit comments

Comments
 (0)