Skip to content

Commit bf6679d

Browse files
committed
Test coverage for source and target type specific member filtering by name
1 parent 80e5019 commit bf6679d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

AgileMapper.UnitTests/Configuration/WhenIgnoringMembersByFilter.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,5 +291,36 @@ public void ShouldIgnoreSetMethodsBySourceTypeTargetTypeAndMethodInfoMatcher()
291291
nonMatchingResult.Value.ShouldBe(111);
292292
}
293293
}
294+
295+
[Fact]
296+
public void ShouldIgnoreMembersBySourceTypeTargetTypeAndNameMatch()
297+
{
298+
using (var mapper = Mapper.CreateNew())
299+
{
300+
mapper.WhenMapping
301+
.From<PublicTwoFields<int, int>>()
302+
.To<PublicTwoFields<int, int>>()
303+
.IgnoreTargetMembersWhere(member => member.Name.Contains("Value1"));
304+
305+
var matchingSource = new PublicTwoFields<int, int> { Value1 = 1, Value2 = 2 };
306+
var nonMatchingSource = new { Value1 = -1, Value2 = -2 };
307+
308+
var matchingResult = mapper.Map(matchingSource).ToANew<PublicTwoFields<int, int>>();
309+
matchingResult.Value1.ShouldBeDefault();
310+
matchingResult.Value2.ShouldBe(2);
311+
312+
var nonMatchingTargetResult = mapper.Map(matchingSource).ToANew<PublicTwoParamCtor<int, int>>();
313+
nonMatchingTargetResult.Value1.ShouldBe(1);
314+
nonMatchingTargetResult.Value2.ShouldBe(2);
315+
316+
var nonMatchingSourceResult = mapper.Map(nonMatchingSource).ToANew<PublicTwoFields<int, int>>();
317+
nonMatchingSourceResult.Value1.ShouldBe(-1);
318+
nonMatchingSourceResult.Value2.ShouldBe(-2);
319+
320+
var nonMatchingResult = mapper.Map(nonMatchingSource).ToANew<PublicTwoParamCtor<int, int>>();
321+
nonMatchingResult.Value1.ShouldBe(-1);
322+
nonMatchingResult.Value2.ShouldBe(-2);
323+
}
324+
}
294325
}
295326
}

0 commit comments

Comments
 (0)