-
-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathIgnoreAttributeTest.cs
81 lines (72 loc) · 2.2 KB
/
IgnoreAttributeTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using Riok.Mapperly.Diagnostics;
namespace Riok.Mapperly.Tests.Mapping;
public class IgnoreAttributeTest
{
private readonly string _classA = TestSourceBuilder.CSharp(
"""
class A
{
public int Value { get; set; }
[MapperIgnore]
public int Ignored { get; set; }
}
"""
);
private readonly string _classB = TestSourceBuilder.CSharp(
"""
class B
{
public int Value { get; set; }
[MapperIgnore]
public int Ignored { get; set; }
}
"""
);
[Fact]
public void ClassAttributeIgnoreMember()
{
var source = TestSourceBuilder.Mapping("A", "B", TestSourceBuilderOptions.Default, _classA, _classB);
TestHelper
.GenerateMapper(source)
.Should()
.HaveSingleMethodBody(
"""
var target = new global::B();
target.Value = source.Value;
return target;
"""
);
}
[Fact]
public void MapPropertyOverridesIgnoreMember()
{
var source = TestSourceBuilder.MapperWithBodyAndTypes(
"""
[MapProperty("Ignored", "Ignored")]
partial B Map(A source);
""",
_classA,
_classB
);
TestHelper
.GenerateMapper(source, TestHelperOptions.AllowDiagnostics)
.Should()
.HaveSingleMethodBody(
"""
var target = new global::B();
target.Value = source.Value;
target.Ignored = source.Ignored;
return target;
"""
)
.HaveDiagnostic(
DiagnosticDescriptors.IgnoredSourceMemberExplicitlyMapped,
"The source member Ignored on A is ignored, but is also mapped by the MapPropertyAttribute"
)
.HaveDiagnostic(
DiagnosticDescriptors.IgnoredTargetMemberExplicitlyMapped,
"The target member Ignored on B is ignored, but is also mapped by the MapPropertyAttribute"
)
.HaveAssertedAllDiagnostics();
}
}