Skip to content

Commit 28a6fe0

Browse files
committed
Update the NUnit assertion model to the contraint model from the classic model which no longer receives updates.
- This also makes migrating to NUnit 4 easier. - This enables Verify.NUnit to be updated to 22.1.4 since it depebnds on NUnit 4.
1 parent 50be018 commit 28a6fe0

File tree

69 files changed

+1806
-1431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1806
-1431
lines changed

tests/NHapi.Base.NUnit/CommonDtTest.cs

Lines changed: 108 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,182 +11,232 @@ public class CommonDtTest
1111
public void Constructor_Sets_Value()
1212
{
1313
var commonDt = new CommonDT("20010203");
14-
Assert.AreEqual("20010203", commonDt.Value);
14+
15+
Assert.That(commonDt.Value, Is.EqualTo("20010203"));
1516
}
1617

1718
[Test]
1819
public void Value__Set_to_Null()
1920
{
20-
var commonDt = new CommonDT();
21-
commonDt.Value = null;
22-
Assert.AreEqual(null, commonDt.Value);
21+
var commonDt = new CommonDT
22+
{
23+
Value = null,
24+
};
25+
26+
Assert.That(commonDt.Value, Is.EqualTo(null));
2327
}
2428

2529
[Test]
2630
public void Value__Set_to_Empty_String()
2731
{
28-
var commonDt = new CommonDT();
29-
commonDt.Value = string.Empty;
30-
Assert.AreEqual(string.Empty, commonDt.Value);
32+
var commonDt = new CommonDT
33+
{
34+
Value = string.Empty,
35+
};
36+
37+
Assert.That(commonDt.Value, Is.EqualTo(string.Empty));
3138
}
3239

3340
[Test]
3441
public void Value__Set_to_Empty_Quoted_String()
3542
{
36-
var commonDt = new CommonDT();
37-
commonDt.Value = "\"\"";
38-
Assert.AreEqual("\"\"", commonDt.Value);
43+
var commonDt = new CommonDT
44+
{
45+
Value = "\"\"",
46+
};
47+
48+
Assert.That(commonDt.Value, Is.EqualTo("\"\""));
3949
}
4050

4151
[Test]
4252
public void Value__Set_to_Invalid_Length()
4353
{
4454
var commonDt = new CommonDT();
45-
Assert.Throws<DataTypeException>(
46-
() => commonDt.Value = "20010");
55+
Assert.That(() => commonDt.Value = "20010", Throws.TypeOf<DataTypeException>());
4756
}
4857

4958
[Test]
5059
public void Value__Set_to_Valid_Year()
5160
{
52-
var commonDt = new CommonDT();
53-
commonDt.Value = "2001";
54-
Assert.AreEqual("2001", commonDt.Value);
55-
Assert.AreEqual(2001, commonDt.Year);
61+
var commonDt = new CommonDT
62+
{
63+
Value = "2001",
64+
};
65+
66+
Assert.Multiple(() =>
67+
{
68+
Assert.That(commonDt.Value, Is.EqualTo("2001"));
69+
Assert.That(commonDt.Year, Is.EqualTo(2001));
70+
});
5671
}
5772

5873
[Test]
5974
public void Value__Set_to_Valid_Year_and_Month()
6075
{
61-
var commonDt = new CommonDT();
62-
commonDt.Value = "200102";
63-
Assert.AreEqual("200102", commonDt.Value);
64-
Assert.AreEqual(2001, commonDt.Year);
65-
Assert.AreEqual(2, commonDt.Month);
76+
var commonDt = new CommonDT
77+
{
78+
Value = "200102",
79+
};
80+
81+
Assert.Multiple(() =>
82+
{
83+
Assert.That(commonDt.Value, Is.EqualTo("200102"));
84+
Assert.That(commonDt.Year, Is.EqualTo(2001));
85+
Assert.That(commonDt.Month, Is.EqualTo(2));
86+
});
6687
}
6788

6889
[Test]
6990
public void Value__Set_to_Valid_Year_and_Month_and_Day()
7091
{
71-
var commonDt = new CommonDT();
72-
commonDt.Value = "20010203";
73-
Assert.AreEqual("20010203", commonDt.Value);
74-
Assert.AreEqual(2001, commonDt.Year);
75-
Assert.AreEqual(2, commonDt.Month);
76-
Assert.AreEqual(3, commonDt.Day);
92+
var commonDt = new CommonDT
93+
{
94+
Value = "20010203",
95+
};
96+
97+
Assert.Multiple(() =>
98+
{
99+
Assert.That(commonDt.Value, Is.EqualTo("20010203"));
100+
Assert.That(commonDt.Year, Is.EqualTo(2001));
101+
Assert.That(commonDt.Month, Is.EqualTo(2));
102+
Assert.That(commonDt.Day, Is.EqualTo(3));
103+
});
77104
}
78105

79106
[Test]
80107
public void Value__Set_to_Invalid_Year()
81108
{
82109
var commonDt = new CommonDT();
83110

84-
Assert.Throws<DataTypeException>(
85-
() => commonDt.Value = "200a");
111+
Assert.That(
112+
() => commonDt.Value = "200a",
113+
Throws.TypeOf<DataTypeException>());
86114
}
87115

88116
[Test]
89117
public void Value__Set_to_Invalid_Month()
90118
{
91119
var commonDt = new CommonDT();
92120

93-
Assert.Throws<DataTypeException>(
94-
() => commonDt.Value = "20010a");
121+
Assert.That(
122+
() => commonDt.Value = "20010a",
123+
Throws.TypeOf<DataTypeException>());
95124
}
96125

97126
[Test]
98127
public void Value__Set_to_Invalid_Day()
99128
{
100129
var commonDt = new CommonDT();
101130

102-
Assert.Throws<DataTypeException>(
103-
() => commonDt.Value = "2001020a");
131+
Assert.That(
132+
() => commonDt.Value = "2001020a",
133+
Throws.TypeOf<DataTypeException>());
104134
}
105135

106136
[Test]
107137
public void YearPrecision__Set_to_Valid_Year()
108138
{
109-
var commonDt = new CommonDT();
110-
commonDt.YearPrecision = 2001;
111-
Assert.AreEqual("2001", commonDt.Value);
112-
Assert.AreEqual(2001, commonDt.Year);
113-
Assert.AreEqual(0, commonDt.Month);
114-
Assert.AreEqual(0, commonDt.Day);
139+
var commonDt = new CommonDT
140+
{
141+
YearPrecision = 2001,
142+
};
143+
144+
Assert.Multiple(() =>
145+
{
146+
Assert.That(commonDt.Value, Is.EqualTo("2001"));
147+
Assert.That(commonDt.Year, Is.EqualTo(2001));
148+
Assert.That(commonDt.Month, Is.EqualTo(0));
149+
Assert.That(commonDt.Day, Is.EqualTo(0));
150+
});
115151
}
116152

117153
[Test]
118154
public void YearPrecision__Set_to_Invalid_Year()
119155
{
120156
var commonDt = new CommonDT();
121157

122-
Assert.Throws<DataTypeException>(
123-
() => commonDt.YearPrecision = 20010);
158+
Assert.That(
159+
() => commonDt.YearPrecision = 20010,
160+
Throws.TypeOf<DataTypeException>());
124161
}
125162

126163
[Test]
127164
public void SetYearMonthPrecision_With_Valid_Year_and_Month()
128165
{
129166
var commonDt = new CommonDT();
130167
commonDt.SetYearMonthPrecision(2001, 02);
131-
Assert.AreEqual("200102", commonDt.Value);
132-
Assert.AreEqual(2001, commonDt.Year);
133-
Assert.AreEqual(2, commonDt.Month);
168+
169+
Assert.Multiple(() =>
170+
{
171+
Assert.That(commonDt.Value, Is.EqualTo("200102"));
172+
Assert.That(commonDt.Year, Is.EqualTo(2001));
173+
Assert.That(commonDt.Month, Is.EqualTo(2));
174+
});
134175
}
135176

136177
[Test]
137178
public void SetYearMonthPrecision_With_Invalid_Year()
138179
{
139180
var commonDt = new CommonDT();
140181

141-
Assert.Throws<DataTypeException>(
142-
() => commonDt.SetYearMonthPrecision(20010, 02));
182+
Assert.That(
183+
() => commonDt.SetYearMonthPrecision(20010, 02),
184+
Throws.TypeOf<DataTypeException>());
143185
}
144186

145187
[Test]
146188
public void SetYearMonthPrecision_With_Invalid_Month()
147189
{
148190
var commonDt = new CommonDT();
149191

150-
Assert.Throws<DataTypeException>(
151-
() => commonDt.SetYearMonthPrecision(2001, 13));
192+
Assert.That(
193+
() => commonDt.SetYearMonthPrecision(2001, 13),
194+
Throws.TypeOf<DataTypeException>());
152195
}
153196

154197
[Test]
155198
public void SetYearMonthDayPrecision_With_Valid_Year_and_Month_and_Day()
156199
{
157200
var commonDt = new CommonDT();
158201
commonDt.SetYearMonthDayPrecision(2001, 2, 3);
159-
Assert.AreEqual("20010203", commonDt.Value);
160-
Assert.AreEqual(2001, commonDt.Year);
161-
Assert.AreEqual(2, commonDt.Month);
162-
Assert.AreEqual(3, commonDt.Day);
202+
203+
Assert.Multiple(() =>
204+
{
205+
Assert.That(commonDt.Value, Is.EqualTo("20010203"));
206+
Assert.That(commonDt.Year, Is.EqualTo(2001));
207+
Assert.That(commonDt.Month, Is.EqualTo(2));
208+
Assert.That(commonDt.Day, Is.EqualTo(3));
209+
});
163210
}
164211

165212
[Test]
166213
public void SetYearMonthDayPrecision_With_Invalid_Year()
167214
{
168215
var commonDt = new CommonDT();
169216

170-
Assert.Throws<DataTypeException>(
171-
() => commonDt.SetYearMonthDayPrecision(20010, 2, 3));
217+
Assert.That(
218+
() => commonDt.SetYearMonthDayPrecision(20010, 2, 3),
219+
Throws.TypeOf<DataTypeException>());
172220
}
173221

174222
[Test]
175223
public void SetYearMonthDayPrecision_With_Invalid_Month()
176224
{
177225
var commonDt = new CommonDT();
178226

179-
Assert.Throws<DataTypeException>(
180-
() => commonDt.SetYearMonthDayPrecision(2001, 13, 3));
227+
Assert.That(
228+
() => commonDt.SetYearMonthDayPrecision(2001, 13, 3),
229+
Throws.TypeOf<DataTypeException>());
181230
}
182231

183232
[Test]
184233
public void SetYearMonthDayPrecision_With_Invalid_Day()
185234
{
186235
var commonDt = new CommonDT();
187236

188-
Assert.Throws<DataTypeException>(
189-
() => commonDt.SetYearMonthDayPrecision(2001, 2, 29));
237+
Assert.That(
238+
() => commonDt.SetYearMonthDayPrecision(2001, 2, 29),
239+
Throws.TypeOf<DataTypeException>());
190240
}
191241
}
192242
}

tests/NHapi.Base.NUnit/DataTypeUtilTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void GetGMTOffset_PST()
3333
TimeZoneInfo.FindSystemTimeZoneById(timeZone),
3434
new DateTime(2014, 12, 1));
3535

36-
Assert.AreEqual(-800, offset);
36+
Assert.That(offset, Is.EqualTo(-800));
3737
}
3838

3939
[Test]
@@ -45,7 +45,7 @@ public void GetGMTOffset_PDT()
4545
TimeZoneInfo.FindSystemTimeZoneById(timeZone),
4646
new DateTime(2014, 10, 1));
4747

48-
Assert.AreEqual(-700, offset);
48+
Assert.That(offset, Is.EqualTo(-700));
4949
}
5050

5151
[Test]
@@ -57,7 +57,7 @@ public void GetGMTOffset_For_TimeZone_With_Non_Zero_Minutes()
5757
TimeZoneInfo.FindSystemTimeZoneById(timeZone),
5858
new DateTime(2014, 11, 1));
5959

60-
Assert.AreEqual(630, offset);
60+
Assert.That(offset, Is.EqualTo(630));
6161
}
6262

6363
[Test]
@@ -69,7 +69,7 @@ public void GetGMTOffset_For_TimeZone_With_Offset_Greater_Than_12()
6969
TimeZoneInfo.FindSystemTimeZoneById(timeZone),
7070
new DateTime(2014, 11, 1));
7171

72-
Assert.AreEqual(1400, offset);
72+
Assert.That(offset, Is.EqualTo(1400));
7373
}
7474

7575
private string GetAppropriateTimeZoneId(string timeZoneId)

0 commit comments

Comments
 (0)