Skip to content

Commit 9e7f0aa

Browse files
authored
Merge pull request #905 from gbirchmeier/rebase-893-update-unit-test-framework
[Rebase #893] Upgrade the unit testing framework to the latest version and remove obsolete Assert methods
2 parents b5febfa + 538225e commit 9e7f0aa

32 files changed

+627
-623
lines changed

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup .NET
2020
uses: actions/setup-dotnet@v3
2121
with:
22-
dotnet-version: 6.0.x
22+
dotnet-version: 8.0.x
2323
- name: Restore dependencies
2424
run: dotnet restore
2525
- name: Build

AcceptanceTest/AcceptanceTest.csproj

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
12-
<PackageReference Include="NUnit" Version="3.13.3" />
13-
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
14-
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
15-
<PackageReference Include="coverlet.collector" Version="3.2.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
12+
<PackageReference Include="NUnit" Version="4.2.2" />
13+
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
14+
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
</PackageReference>
18+
<PackageReference Include="coverlet.collector" Version="6.0.2">
19+
<PrivateAssets>all</PrivateAssets>
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21+
</PackageReference>
1622
</ItemGroup>
1723

1824
<ItemGroup>

AcceptanceTest/ReflectorClient.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public ReflectorClient(IPEndPoint endPoint)
3939

4040
public void Expect(string expectedMessage)
4141
{
42-
Assert.IsNotNull(_socket);
42+
Assert.That(_socket, Is.Not.Null);
4343

4444
string actualMessage;
4545
while (!_parser.ReadFixMessage(out actualMessage))
@@ -107,7 +107,7 @@ void AssertAtIndex(int mismatchIndex)
107107
public void Initiate(string initiateMessage)
108108
{
109109
string decoratedMessage = Decorate(initiateMessage);
110-
Assert.IsNotNull(_socket);
110+
Assert.That(_socket, Is.Not.Null);
111111
_socket.Send(Encoding.Latin1.GetBytes(decoratedMessage));
112112
}
113113

@@ -180,25 +180,25 @@ static byte Checksum(string message)
180180

181181
public void InitiateConnect()
182182
{
183-
Assert.IsNull(_socket);
183+
Assert.That(_socket, Is.Null);
184184

185185
_socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
186186
_socket.Connect(_endPoint);
187187
}
188188

189189
public void InitiateDisconnect()
190190
{
191-
Assert.IsNotNull(_socket);
191+
Assert.That(_socket, Is.Not.Null);
192192

193193
ShutdownSocket();
194194
}
195195

196196
public void ExpectDisconnect()
197197
{
198-
Assert.IsNotNull(_socket);
198+
Assert.That(_socket, Is.Not.Null);
199199

200200
int bytesRead = _socket.Receive(_readBuffer);
201-
Assert.AreEqual(0, bytesRead);
201+
Assert.That(bytesRead, Is.EqualTo(0));
202202

203203
ShutdownSocket();
204204
}

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ What's New
4444
* also deprecate a AcceptorSocketDescriptor ctor due to unused param
4545
* #900 - correct CompositeLog to use IFactory.CreateNonSessionLog when appropriate (gbirchmeier)
4646
* #891 - make NonSessionLog implement IDisposable and fix the IOException (VAllens)
47+
* #893 - Upgrade the unit testing framework to the latest version and remove obsolete Assert methods (VAllens)
4748

4849
### v1.12.0
4950

UnitTests/DDFieldTests.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,29 @@ public void CtorEnum()
1818

1919
DDField ddf = new DDField(5, "Foo", enums, "STRING");
2020

21-
Assert.AreEqual(ddf.Tag, 5);
22-
Assert.AreEqual(ddf.Name, "Foo");
23-
Assert.AreEqual(ddf.EnumDict, enums);
24-
Assert.AreEqual(ddf.FixFldType, "STRING");
25-
Assert.AreEqual(ddf.FieldType, typeof(QuickFix.Fields.StringField));
21+
Assert.That(5, Is.EqualTo(ddf.Tag));
22+
Assert.That("Foo", Is.EqualTo(ddf.Name));
23+
Assert.That(enums, Is.EqualTo(ddf.EnumDict));
24+
Assert.That("STRING", Is.EqualTo(ddf.FixFldType));
25+
Assert.That(typeof(QuickFix.Fields.StringField), Is.EqualTo(ddf.FieldType));
2626

27-
Assert.IsFalse(ddf.IsMultipleValueFieldWithEnums);
28-
Assert.IsTrue(ddf.HasEnums());
27+
Assert.That(ddf.IsMultipleValueFieldWithEnums, Is.False);
28+
Assert.That(ddf.HasEnums(), Is.True);
2929
}
3030

3131
[Test]
3232
public void CtorMultipleValueFieldWithEnums()
3333
{
3434
DDField ddf = new DDField(111, "MultiX", new Dictionary<string, string>(), "MULTIPLEVALUESTRING");
3535

36-
Assert.AreEqual(ddf.Tag, 111);
37-
Assert.AreEqual(ddf.Name, "MultiX");
38-
Assert.AreEqual(ddf.EnumDict.Count, 0);
39-
Assert.AreEqual(ddf.FixFldType, "MULTIPLEVALUESTRING");
40-
Assert.AreEqual(ddf.FieldType, typeof(QuickFix.Fields.StringField));
36+
Assert.That(111, Is.EqualTo(ddf.Tag));
37+
Assert.That("MultiX", Is.EqualTo(ddf.Name));
38+
Assert.That(0, Is.EqualTo(ddf.EnumDict.Count));
39+
Assert.That("MULTIPLEVALUESTRING", Is.EqualTo(ddf.FixFldType));
40+
Assert.That(typeof(QuickFix.Fields.StringField), Is.EqualTo(ddf.FieldType));
4141

42-
Assert.IsTrue(ddf.IsMultipleValueFieldWithEnums);
43-
Assert.IsFalse(ddf.HasEnums());
42+
Assert.That(ddf.IsMultipleValueFieldWithEnums, Is.True);
43+
Assert.That(ddf.HasEnums(), Is.False);
4444
}
4545
}
4646
}

UnitTests/DataDictionaryTests.cs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ public void FieldHasValueTest()
5454
dd.LoadFIXSpec("FIX44");
5555
Assert.That(dd.FieldHasValue(QuickFix.Fields.Tags.StatusValue, "1"), Is.EqualTo(true));
5656
Assert.That(dd.FieldHasValue(QuickFix.Fields.Tags.StatusValue, "CONNECTED"), Is.EqualTo(false));
57-
Assert.False(dd.FieldsByTag[1].HasEnums());
58-
Assert.True(dd.FieldsByTag[945].HasEnums());
57+
Assert.That(dd.FieldsByTag[1].HasEnums(), Is.False);
58+
Assert.That(dd.FieldsByTag[945].HasEnums(), Is.True);
5959
}
6060

6161
[Test]
6262
public void FieldHasDescriptionTest()
6363
{
6464
DataDictionary dd = new DataDictionary();
6565
dd.LoadFIXSpec("FIX44");
66-
Assert.AreEqual(typeof (Dictionary<string, string>), dd.FieldsByTag[945].EnumDict.GetType());
66+
Assert.That(dd.FieldsByTag[945].EnumDict.GetType(), Is.EqualTo(typeof(Dictionary<string, string>)));
6767
Assert.That("COMPLETED", Is.EqualTo(dd.FieldsByTag[945].EnumDict["2"]));
68-
Assert.AreNotEqual("HEARTBEAT", dd.FieldsByTag[35].EnumDict["A"]);
68+
Assert.That(dd.FieldsByTag[35].EnumDict["A"], Is.Not.EqualTo("HEARTBEAT"));
6969
}
7070

7171
[Test]
@@ -82,8 +82,8 @@ public void ComponentSmokeTest()
8282
DataDictionary dd = new DataDictionary();
8383
dd.LoadFIXSpec("FIX44");
8484
DDMap tcr = dd.Messages["AE"];
85-
Assert.True(tcr.Fields.ContainsKey(55));
86-
Assert.False(tcr.Fields.ContainsKey(5995));
85+
Assert.That(tcr.Fields.ContainsKey(55), Is.True);
86+
Assert.That(tcr.Fields.ContainsKey(5995), Is.False);
8787
}
8888

8989
[Test]
@@ -92,9 +92,9 @@ public void GroupTest()
9292
DataDictionary dd = new DataDictionary();
9393
dd.LoadFIXSpec("FIX44");
9494
DDMap tcrr = dd.Messages["AD"];
95-
Assert.True(tcrr.IsGroup(711));
96-
Assert.True(tcrr.IsField(711)); // No Field also a field
97-
Assert.True(tcrr.GetGroup(711).IsField(311));
95+
Assert.That(tcrr.IsGroup(711), Is.True);
96+
Assert.That(tcrr.IsField(711), Is.True); // No Field also a field
97+
Assert.That(tcrr.GetGroup(711).IsField(311), Is.True);
9898
Assert.That(tcrr.Groups[711].Fields[311].Name, Is.EqualTo("UnderlyingSymbol"));
9999
Assert.That(tcrr.Groups[711].Delim, Is.EqualTo(311));
100100
DDMap tcr = dd.Messages["AE"];
@@ -108,9 +108,9 @@ public void NestedGroupTest()
108108
dd.LoadFIXSpec("FIX44");
109109
DDMap msgJ = dd.Messages["J"];
110110

111-
Assert.True(msgJ.IsGroup(73));
112-
Assert.False(msgJ.IsGroup(756));
113-
Assert.True(msgJ.GetGroup(73).IsGroup(756));
111+
Assert.That(msgJ.IsGroup(73), Is.True);
112+
Assert.That(msgJ.IsGroup(756), Is.False);
113+
Assert.That(msgJ.GetGroup(73).IsGroup(756), Is.True);
114114
}
115115

116116
[Test]
@@ -119,12 +119,12 @@ public void GroupBeginsGroupTest()
119119
DataDictionary dd = new DataDictionary();
120120
dd.LoadTestFIXSpec("group_begins_group");
121121
DDMap msg = dd.Messages["magic"];
122-
Assert.True(msg.IsGroup(6660)); // NoMagics group
123-
Assert.True(msg.GetGroup(6660).IsGroup(7770)); // NoMagics/NoRabbits
124-
Assert.True(msg.GetGroup(6660).IsField(6661)); // NoMagics/MagicWord
125-
Assert.True(msg.GetGroup(6660).GetGroup(7770).IsField(7711)); // NoMagics/NoRabbits/RabbitName
126-
Assert.AreEqual(7770, msg.GetGroup(6660).Delim); // NoMagics delim is NoRabbits counter
127-
Assert.AreEqual(7711, msg.GetGroup(6660).GetGroup(7770).Delim); // NoRabbits delim is RabbitName
122+
Assert.That(msg.IsGroup(6660), Is.True); // NoMagics group
123+
Assert.That(msg.GetGroup(6660).IsGroup(7770), Is.True); // NoMagics/NoRabbits
124+
Assert.That(msg.GetGroup(6660).IsField(6661), Is.True); // NoMagics/MagicWord
125+
Assert.That(msg.GetGroup(6660).GetGroup(7770).IsField(7711), Is.True); // NoMagics/NoRabbits/RabbitName
126+
Assert.That(msg.GetGroup(6660).Delim, Is.EqualTo(7770)); // NoMagics delim is NoRabbits counter
127+
Assert.That(msg.GetGroup(6660).GetGroup(7770).Delim, Is.EqualTo(7711)); // NoRabbits delim is RabbitName
128128
}
129129

130130
[Test]
@@ -133,27 +133,27 @@ public void HeaderGroupTest()
133133
DataDictionary dd = new DataDictionary();
134134
dd.LoadFIXSpec("FIX44");
135135
DDMap headerMap = dd.Header;
136-
Assert.True(headerMap.IsGroup(627));
136+
Assert.That(headerMap.IsGroup(627), Is.True);
137137
DDGrp grpMap = headerMap.GetGroup(627);
138-
Assert.True(dd.Header.GetGroup(627).IsField(628));
139-
Assert.True(grpMap.IsField(628));
138+
Assert.That(dd.Header.GetGroup(627).IsField(628), Is.True);
139+
Assert.That(grpMap.IsField(628), Is.True);
140140
}
141141

142142
[Test]
143143
public void ReqFldTest()
144144
{
145145
DataDictionary dd = new DataDictionary();
146146
dd.LoadFIXSpec("FIX44");
147-
Assert.True(dd.Messages["AE"].ReqFields.Contains(571));
148-
Assert.False(dd.Messages["AE"].ReqFields.Contains(828));
147+
Assert.That(dd.Messages["AE"].ReqFields.Contains(571), Is.True);
148+
Assert.That(dd.Messages["AE"].ReqFields.Contains(828), Is.False);
149149
}
150150

151151
[Test]
152152
public void HeaderTest()
153153
{
154154
DataDictionary dd = new DataDictionary();
155155
dd.LoadFIXSpec("FIX44");
156-
Assert.True(dd.Header.ReqFields.Contains(9));
156+
Assert.That(dd.Header.ReqFields.Contains(9), Is.True);
157157
Assert.That(dd.Header.Fields.Count, Is.EqualTo(27));
158158
}
159159

@@ -162,7 +162,7 @@ public void TrailerTest()
162162
{
163163
DataDictionary dd = new DataDictionary();
164164
dd.LoadFIXSpec("FIX44");
165-
Assert.True(dd.Trailer.ReqFields.Contains(10));
165+
Assert.That(dd.Trailer.ReqFields.Contains(10), Is.True);
166166
Assert.That(dd.Trailer.Fields.Count, Is.EqualTo(3));
167167
}
168168

@@ -315,8 +315,8 @@ public void CheckGroupCountTest()
315315

316316
//verify that FromString didn't correct the counter
317317
//HEY YOU, READ THIS NOW: if these fail, first check if MessageTests::FromString_DoNotCorrectCounter() passes
318-
Assert.AreEqual("386=3", n.NoTradingSessions.ToStringField());
319-
StringAssert.Contains("386=3", n.ConstructString());
318+
Assert.That(n.NoTradingSessions.ToStringField(), Is.EqualTo("386=3"));
319+
Assert.That(n.ConstructString(), Does.Contain("386=3"));
320320

321321
Assert.Throws<RepeatingGroupCountMismatch>(delegate { dd.CheckGroupCount(n.NoTradingSessions, n, "D"); });
322322
}
@@ -337,22 +337,22 @@ public void ComponentFieldsRequirements()
337337
dd.LoadFIXSpec("FIX44");
338338

339339
// AD => Instrument component (optional) => 55 (Symbol)
340-
Assert.False(dd.Messages["AD"].ReqFields.Contains(55));
340+
Assert.That(dd.Messages["AD"].ReqFields.Contains(55), Is.False);
341341
// 7 => Instrument component (required) => 55 (Symbol)
342-
Assert.True(dd.Messages["7"].ReqFields.Contains(55));
342+
Assert.That(dd.Messages["7"].ReqFields.Contains(55), Is.True);
343343
}
344344

345345
[Test]
346346
public void Issue134_RequiredIsOptional()
347347
{
348348
DataDictionary dd = new DataDictionary();
349349
dd.LoadTestFIXSpec("required_is_optional");
350-
Assert.True(dd.Messages["magic"].ReqFields.Contains(1111)); //base required field
351-
Assert.False(dd.Messages["magic"].ReqFields.Contains(5555)); //base optional field
352-
Assert.False(dd.Messages["magic"].ReqFields.Contains(5556)); //component optional field
350+
Assert.That(dd.Messages["magic"].ReqFields.Contains(1111), Is.True); //base required field
351+
Assert.That(dd.Messages["magic"].ReqFields.Contains(5555), Is.False); //base optional field
352+
Assert.That(dd.Messages["magic"].ReqFields.Contains(5556), Is.False); //component optional field
353353

354-
Assert.False(dd.Messages["magic"].Groups[6660].Required); // group isn't required
355-
Assert.False(dd.Messages["magic"].Groups[6660].ReqFields.Contains(6662)); // group optional field
354+
Assert.That(dd.Messages["magic"].Groups[6660].Required, Is.False); // group isn't required
355+
Assert.That(dd.Messages["magic"].Groups[6660].ReqFields.Contains(6662), Is.False); // group optional field
356356
}
357357

358358
[Test] // Issue #493
@@ -364,13 +364,13 @@ public void ParseThroughComments()
364364
// The fact that it doesn't throw is sufficient, but we'll do some other checks anyway.
365365

366366
DDMap logon = dd.GetMapForMessage("A")!;
367-
Assert.True(logon.IsField(108)); // HeartBtInt
368-
Assert.True(logon.IsField(9000)); // CustomField
367+
Assert.That(logon.IsField(108), Is.True); // HeartBtInt
368+
Assert.That(logon.IsField(9000), Is.True); // CustomField
369369

370370
DDMap news = dd.GetMapForMessage("B")!;
371-
Assert.True(news.IsField(148)); // Headline
372-
Assert.True(news.IsGroup(33)); // LinesOfText
373-
Assert.True(news.GetGroup(33).IsField(355)); // EncodedText
371+
Assert.That(news.IsField(148), Is.True); // Headline
372+
Assert.That(news.IsGroup(33), Is.True); // LinesOfText
373+
Assert.That(news.GetGroup(33).IsField(355), Is.True); // EncodedText
374374
}
375375

376376
private static XmlNode MakeNode(string xmlString)
@@ -388,22 +388,22 @@ private static XmlNode MakeNode(string xmlString)
388388
public void VerifyChildNodeAndReturnNameAtt() {
389389
XmlNode parentNode = MakeNode("<parentnode name='Daddy'/>");
390390

391-
Assert.AreEqual("qty", DataDictionary.VerifyChildNodeAndReturnNameAtt(
392-
MakeNode("<sometag name='qty'/>"), parentNode));
391+
Assert.That(DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("<sometag name='qty'/>"), parentNode),
392+
Is.EqualTo("qty"));
393393

394394
DictionaryParseException dpx = Assert.Throws<DictionaryParseException>(
395395
delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("foo"), parentNode); })!;
396-
Assert.AreEqual("Malformed data dictionary: Found text-only node containing 'foo'", dpx.Message);
396+
Assert.That(dpx.Message, Is.EqualTo("Malformed data dictionary: Found text-only node containing 'foo'"));
397397

398398
dpx = Assert.Throws<DictionaryParseException>(
399399
delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("<field>qty</field>"), parentNode); })!;
400-
Assert.AreEqual("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/Daddy'", dpx.Message);
400+
Assert.That(dpx.Message, Is.EqualTo("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/Daddy'"));
401401

402402
// alt error message, where parent has no name
403403
parentNode = MakeNode("<parentnode/>");
404404
dpx = Assert.Throws<DictionaryParseException>(
405405
delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("<field>qty</field>"), parentNode); })!;
406-
Assert.AreEqual("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/parentnode'", dpx.Message);
406+
Assert.That(dpx.Message, Is.EqualTo("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/parentnode'"));
407407
}
408408
}
409409
}

UnitTests/DataDictionary_ValidateTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void UnsupportedVersionTest() {
1515

1616
var ex = Assert.Throws<UnsupportedVersion>(delegate {
1717
DataDictionary.Validate(new Message(), dd, dd, "foobar", "X"); });
18-
StringAssert.Contains("Incorrect BeginString (foobar)", ex!.Message);
18+
Assert.That(ex!.Message, Does.Contain("Incorrect BeginString (foobar)"));
1919
}
2020

2121
[Test]
@@ -41,7 +41,7 @@ public void TagOutOfOrderTest() {
4141

4242
var ex = Assert.Throws<TagOutOfOrder>(delegate {
4343
DataDictionary.Validate(msg, dd, dd, "FIX.4.4", "B"); });
44-
StringAssert.Contains("Tag specified out of required order", ex!.Message);
44+
Assert.That(ex!.Message, Does.Contain("Tag specified out of required order"));
4545
}
4646

4747
[Test]
@@ -105,9 +105,9 @@ public void ValidateGroupBeginsGroup()
105105
Group rabbitGroup = new Group(7770, 7711, new[] { 7711, 7722 });
106106
magicGroup.GetGroup(2, rabbitGroup);
107107

108-
Assert.AreEqual("abracadabra", magicGroup.GetString(6661));
109-
Assert.AreEqual("Floppy", rabbitGroup.GetString(7711));
110-
Assert.AreEqual("white", rabbitGroup.GetString(7712));
108+
Assert.That(magicGroup.GetString(6661), Is.EqualTo("abracadabra"));
109+
Assert.That(rabbitGroup.GetString(7711), Is.EqualTo("Floppy"));
110+
Assert.That(rabbitGroup.GetString(7712), Is.EqualTo("white"));
111111
}
112112

113113
[Test]
@@ -273,7 +273,7 @@ public void RequiredComponentRequiredField()
273273

274274
var ex = Assert.Throws<RequiredTagMissing>(() =>
275275
DataDictionary.Validate(message, dd, dd, beginString, msgType));
276-
Assert.AreEqual(55, ex!.Field);
276+
Assert.That(ex!.Field, Is.EqualTo(55));
277277
}
278278

279279
[Test] // Issue #66

0 commit comments

Comments
 (0)