Skip to content

Commit cd6e31d

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

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

AgileMapper.UnitTests/Configuration/WhenIgnoringMembersByFilter.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,5 +354,57 @@ public void ShouldIgnoreMembersBySourceTypeTargetTypeAndPathMatch()
354354
nonMatchingResult.Value.Line2.ShouldBe("There!");
355355
}
356356
}
357+
358+
[Fact]
359+
public void ShouldIgnoreMembersBySourceTypeTargetTypeAndAttribute()
360+
{
361+
using (var mapper = Mapper.CreateNew())
362+
{
363+
mapper.WhenMapping
364+
.From<PublicTwoFields<int, int>>()
365+
.To<AttributeHelper>()
366+
.IgnoreTargetMembersWhere(member => member.HasAttribute<IgnoreMeAttribute>());
367+
368+
var matchingSource = new PublicTwoFields<int, int> { Value1 = 10, Value2 = 20 };
369+
var nonMatchingSource = new { Value1 = "11", Value2 = "21" };
370+
371+
var matchingResult = mapper.Map(matchingSource).ToANew<AttributeHelper>();
372+
matchingResult.Value1.ShouldBeDefault();
373+
matchingResult.Value2.ShouldBe("20");
374+
375+
var nonMatchingTargetResult = mapper.Map(matchingSource).ToANew<PublicTwoFields<string, string>>();
376+
nonMatchingTargetResult.Value1.ShouldBe("10");
377+
nonMatchingTargetResult.Value2.ShouldBe("20");
378+
379+
var nonMatchingSourceResult = mapper.Map(nonMatchingSource).ToANew<AttributeHelper>();
380+
nonMatchingSourceResult.Value1.ShouldBe("11");
381+
nonMatchingSourceResult.Value2.ShouldBe("21");
382+
383+
var nonMatchingResult = mapper.Map(nonMatchingSource).ToANew<PublicTwoFields<string, string>>();
384+
nonMatchingResult.Value1.ShouldBe("11");
385+
nonMatchingResult.Value2.ShouldBe("21");
386+
}
387+
}
388+
389+
#region Helper Classes
390+
391+
public class AttributeHelper
392+
{
393+
public AttributeHelper([IgnoreMe]string value2)
394+
{
395+
Value2 = value2;
396+
}
397+
398+
[IgnoreMe]
399+
public string Value1 { get; set; }
400+
401+
public string Value2 { get; }
402+
}
403+
404+
public sealed class IgnoreMeAttribute : Attribute
405+
{
406+
}
407+
408+
#endregion
357409
}
358410
}

0 commit comments

Comments
 (0)