-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathEnumTest.cs
155 lines (127 loc) · 4.33 KB
/
EnumTest.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Tynamix.ObjectFiller.Test
{
[TestClass]
public class EnumTest
{
[TestMethod]
public void Must_support_enums_out_of_the_box()
{
var filler = new Filler<MyClass>();
filler.Setup()
.OnProperty(x => x.Manual).Use(() => ManualSetupEnum.B)
.OnProperty(x => x.Ignored).IgnoreIt();
for (int n = 0; n < 1000; n++)
{
var c = filler.Create();
Assert.IsTrue(
c.Standard == StandardEnum.A ||
c.Standard == StandardEnum.B ||
c.Standard == StandardEnum.C);
Assert.IsTrue(
c.Numbered == NumberedEnum.A ||
c.Numbered == NumberedEnum.B ||
c.Numbered == NumberedEnum.C);
Assert.IsTrue(
c.Flags == FlagsEnum.A ||
c.Flags == FlagsEnum.B ||
c.Flags == FlagsEnum.C);
Assert.IsTrue((int)c.Nasty == 0);
Assert.IsTrue(c.Manual == ManualSetupEnum.B);
Assert.IsTrue((int)c.Ignored == 0);
}
}
[TestMethod]
public void Must_support_class_with_enums_as_ctor_out_of_the_box()
{
var filler = new Filler<MyClassWithCstr>();
filler.Setup().OnProperty(x => x.Manual).Use(() => ManualSetupEnum.B);
for (int n = 0; n < 1000; n++)
{
var c = filler.Create();
Assert.IsTrue(
c.Standard == StandardEnum.A ||
c.Standard == StandardEnum.B ||
c.Standard == StandardEnum.C);
Assert.IsTrue(
c.Numbered == NumberedEnum.A ||
c.Numbered == NumberedEnum.B ||
c.Numbered == NumberedEnum.C);
Assert.IsTrue(
c.Flags == FlagsEnum.A ||
c.Flags == FlagsEnum.B ||
c.Flags == FlagsEnum.C);
Assert.IsTrue((int)c.Nasty == 0);
Assert.IsTrue(c.Manual == ManualSetupEnum.B);
}
}
[TestMethod]
public void FillNullableEnum()
{
var filler = new Filler<ClassWithNullableEnum>();
var c = filler.Create();
Assert.IsTrue(
c.NullableEnum == StandardEnum.A ||
c.NullableEnum == StandardEnum.B ||
c.NullableEnum == StandardEnum.C);
}
public enum StandardEnum
{
A, B, C
}
public enum NumberedEnum
{
A = 1, B = 3, C = 5
}
[Flags]
public enum FlagsEnum
{
A = 0x01,
B = 0x02,
C = A | B,
}
[Flags]
public enum NastyEmptyEnum
{
}
public enum ManualSetupEnum
{
A, B, C
}
public enum IgnoredEnum
{
A, B, C
}
public class MyClass
{
public StandardEnum Standard { get; set; }
public NumberedEnum Numbered { get; set; }
public FlagsEnum Flags { get; set; }
public NastyEmptyEnum Nasty { get; set; }
public ManualSetupEnum Manual { get; set; }
public IgnoredEnum Ignored { get; set; }
}
public class MyClassWithCstr
{
public MyClassWithCstr(StandardEnum standard, NumberedEnum numbered, FlagsEnum flags, ManualSetupEnum manual, IgnoredEnum ignored)
{
this.Standard = standard;
this.Numbered = numbered;
this.Flags = flags;
this.Manual = manual;
this.Ignored = ignored;
}
public StandardEnum Standard { get; set; }
public NumberedEnum Numbered { get; set; }
public FlagsEnum Flags { get; set; }
public NastyEmptyEnum Nasty { get; set; }
public ManualSetupEnum Manual { get; set; }
public IgnoredEnum Ignored { get; set; }
}
public class ClassWithNullableEnum
{
public StandardEnum? NullableEnum { get; set; }
}
}
}