forked from AutoMapper/AutoMapper.Archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceValidationWithInheritance.cs
More file actions
123 lines (101 loc) · 3.6 KB
/
Copy pathSourceValidationWithInheritance.cs
File metadata and controls
123 lines (101 loc) · 3.6 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
namespace AutoMapper.UnitTests;
public class SourceValidationWithInheritance : AutoMapperSpecBase
{
public abstract class FormElement2
{
public Guid Id { get; set; }
public int Order { get; set; }
}
public abstract class FieldControl2 : FormElement2
{
public string Label { get; set; }
public string Trailer { get; set; }
public bool Misspelled { get; set; }
}
public abstract class TextFieldControl2 : FieldControl2
{
public string DefaultValue { get; set; }
public int Size { get; set; }
}
public class TextBoxControl2 : TextFieldControl2
{
public int Rows { get; set; }
}
public abstract class FormControlBaseDTO2
{
public Guid Id { get; set; }
public int Order { get; set; }
}
public class FormElementDTO2 : FormControlBaseDTO2
{
public int ElementType { get; set; }
public string Label { get; set; }
public string Trailer { get; set; }
public string DefaultValue { get; set; }
public int Size { get; set; }
public int Rows { get; set; }
public bool Prepopulate { get; set; }
}
protected override MapperConfiguration CreateConfiguration() => new(cfg =>
{
cfg.CreateMap<FormElement2, FormElementDTO2>(MemberList.Source)
.Include<FieldControl2, FormElementDTO2>();
cfg.CreateMap<FieldControl2, FormElementDTO2>(MemberList.Source)
.ForMember(dto => dto.Prepopulate, opt => opt.MapFrom(src => src.Misspelled))
.Include<TextBoxControl2, FormElementDTO2>();
cfg.CreateMap<TextBoxControl2, FormElementDTO2>(MemberList.Source)
.ForMember(dto => dto.ElementType, opt => opt.MapFrom(src => 0));
});
[Fact]
public void Validate() => AssertConfigurationIsValid();
}
public class SourceValidationWithIgnore: AutoMapperSpecBase
{
public abstract class FormElement2
{
public Guid Id { get; set; }
public int Order { get; set; }
}
public abstract class FieldControl2 : FormElement2
{
public string Label { get; set; }
public string Trailer { get; set; }
public bool Misspelled { get; set; }
}
public abstract class TextFieldControl2 : FieldControl2
{
public string DefaultValue { get; set; }
public int Size { get; set; }
}
public class TextBoxControl2 : TextFieldControl2
{
public int Rows { get; set; }
}
public abstract class FormControlBaseDTO2
{
public Guid Id { get; set; }
public int Order { get; set; }
}
public class FormElementDTO2 : FormControlBaseDTO2
{
public int ElementType { get; set; }
public string Label { get; set; }
public string Trailer { get; set; }
public string DefaultValue { get; set; }
public int Size { get; set; }
public int Rows { get; set; }
public bool Prepopulate { get; set; }
}
protected override MapperConfiguration CreateConfiguration() => new(cfg =>
{
cfg.CreateMap<FormElement2, FormElementDTO2>(MemberList.Source)
.Include<FieldControl2, FormElementDTO2>();
cfg.CreateMap<FieldControl2, FormElementDTO2>(MemberList.Source)
.ForSourceMember(src => src.Misspelled, o=>o.DoNotValidate())
.Include<TextBoxControl2, FormElementDTO2>();
cfg.CreateMap<TextBoxControl2, FormElementDTO2>(MemberList.Source)
.ForMember(dto => dto.ElementType, opt => opt.MapFrom(src => 0));
});
[Fact]
public void Validate() => AssertConfigurationIsValid();
}