Skip to content

Commit

Permalink
Merge pull request #905 from gbirchmeier/rebase-893-update-unit-test-…
Browse files Browse the repository at this point in the history
…framework

[Rebase #893] Upgrade the unit testing framework to the latest version and remove obsolete Assert methods
  • Loading branch information
gbirchmeier authored Dec 3, 2024
2 parents b5febfa + 538225e commit 9e7f0aa
Show file tree
Hide file tree
Showing 32 changed files with 627 additions and 623 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
16 changes: 11 additions & 5 deletions AcceptanceTest/AcceptanceTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions AcceptanceTest/ReflectorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ReflectorClient(IPEndPoint endPoint)

public void Expect(string expectedMessage)
{
Assert.IsNotNull(_socket);
Assert.That(_socket, Is.Not.Null);

string actualMessage;
while (!_parser.ReadFixMessage(out actualMessage))
Expand Down Expand Up @@ -107,7 +107,7 @@ void AssertAtIndex(int mismatchIndex)
public void Initiate(string initiateMessage)
{
string decoratedMessage = Decorate(initiateMessage);
Assert.IsNotNull(_socket);
Assert.That(_socket, Is.Not.Null);
_socket.Send(Encoding.Latin1.GetBytes(decoratedMessage));
}

Expand Down Expand Up @@ -180,25 +180,25 @@ static byte Checksum(string message)

public void InitiateConnect()
{
Assert.IsNull(_socket);
Assert.That(_socket, Is.Null);

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

public void InitiateDisconnect()
{
Assert.IsNotNull(_socket);
Assert.That(_socket, Is.Not.Null);

ShutdownSocket();
}

public void ExpectDisconnect()
{
Assert.IsNotNull(_socket);
Assert.That(_socket, Is.Not.Null);

int bytesRead = _socket.Receive(_readBuffer);
Assert.AreEqual(0, bytesRead);
Assert.That(bytesRead, Is.EqualTo(0));

ShutdownSocket();
}
Expand Down
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ What's New
* also deprecate a AcceptorSocketDescriptor ctor due to unused param
* #900 - correct CompositeLog to use IFactory.CreateNonSessionLog when appropriate (gbirchmeier)
* #891 - make NonSessionLog implement IDisposable and fix the IOException (VAllens)
* #893 - Upgrade the unit testing framework to the latest version and remove obsolete Assert methods (VAllens)

### v1.12.0

Expand Down
28 changes: 14 additions & 14 deletions UnitTests/DDFieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ public void CtorEnum()

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

Assert.AreEqual(ddf.Tag, 5);
Assert.AreEqual(ddf.Name, "Foo");
Assert.AreEqual(ddf.EnumDict, enums);
Assert.AreEqual(ddf.FixFldType, "STRING");
Assert.AreEqual(ddf.FieldType, typeof(QuickFix.Fields.StringField));
Assert.That(5, Is.EqualTo(ddf.Tag));
Assert.That("Foo", Is.EqualTo(ddf.Name));
Assert.That(enums, Is.EqualTo(ddf.EnumDict));
Assert.That("STRING", Is.EqualTo(ddf.FixFldType));
Assert.That(typeof(QuickFix.Fields.StringField), Is.EqualTo(ddf.FieldType));

Assert.IsFalse(ddf.IsMultipleValueFieldWithEnums);
Assert.IsTrue(ddf.HasEnums());
Assert.That(ddf.IsMultipleValueFieldWithEnums, Is.False);
Assert.That(ddf.HasEnums(), Is.True);
}

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

Assert.AreEqual(ddf.Tag, 111);
Assert.AreEqual(ddf.Name, "MultiX");
Assert.AreEqual(ddf.EnumDict.Count, 0);
Assert.AreEqual(ddf.FixFldType, "MULTIPLEVALUESTRING");
Assert.AreEqual(ddf.FieldType, typeof(QuickFix.Fields.StringField));
Assert.That(111, Is.EqualTo(ddf.Tag));
Assert.That("MultiX", Is.EqualTo(ddf.Name));
Assert.That(0, Is.EqualTo(ddf.EnumDict.Count));
Assert.That("MULTIPLEVALUESTRING", Is.EqualTo(ddf.FixFldType));
Assert.That(typeof(QuickFix.Fields.StringField), Is.EqualTo(ddf.FieldType));

Assert.IsTrue(ddf.IsMultipleValueFieldWithEnums);
Assert.IsFalse(ddf.HasEnums());
Assert.That(ddf.IsMultipleValueFieldWithEnums, Is.True);
Assert.That(ddf.HasEnums(), Is.False);
}
}
}
88 changes: 44 additions & 44 deletions UnitTests/DataDictionaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ public void FieldHasValueTest()
dd.LoadFIXSpec("FIX44");
Assert.That(dd.FieldHasValue(QuickFix.Fields.Tags.StatusValue, "1"), Is.EqualTo(true));
Assert.That(dd.FieldHasValue(QuickFix.Fields.Tags.StatusValue, "CONNECTED"), Is.EqualTo(false));
Assert.False(dd.FieldsByTag[1].HasEnums());
Assert.True(dd.FieldsByTag[945].HasEnums());
Assert.That(dd.FieldsByTag[1].HasEnums(), Is.False);
Assert.That(dd.FieldsByTag[945].HasEnums(), Is.True);
}

[Test]
public void FieldHasDescriptionTest()
{
DataDictionary dd = new DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.AreEqual(typeof (Dictionary<string, string>), dd.FieldsByTag[945].EnumDict.GetType());
Assert.That(dd.FieldsByTag[945].EnumDict.GetType(), Is.EqualTo(typeof(Dictionary<string, string>)));
Assert.That("COMPLETED", Is.EqualTo(dd.FieldsByTag[945].EnumDict["2"]));
Assert.AreNotEqual("HEARTBEAT", dd.FieldsByTag[35].EnumDict["A"]);
Assert.That(dd.FieldsByTag[35].EnumDict["A"], Is.Not.EqualTo("HEARTBEAT"));
}

[Test]
Expand All @@ -82,8 +82,8 @@ public void ComponentSmokeTest()
DataDictionary dd = new DataDictionary();
dd.LoadFIXSpec("FIX44");
DDMap tcr = dd.Messages["AE"];
Assert.True(tcr.Fields.ContainsKey(55));
Assert.False(tcr.Fields.ContainsKey(5995));
Assert.That(tcr.Fields.ContainsKey(55), Is.True);
Assert.That(tcr.Fields.ContainsKey(5995), Is.False);
}

[Test]
Expand All @@ -92,9 +92,9 @@ public void GroupTest()
DataDictionary dd = new DataDictionary();
dd.LoadFIXSpec("FIX44");
DDMap tcrr = dd.Messages["AD"];
Assert.True(tcrr.IsGroup(711));
Assert.True(tcrr.IsField(711)); // No Field also a field
Assert.True(tcrr.GetGroup(711).IsField(311));
Assert.That(tcrr.IsGroup(711), Is.True);
Assert.That(tcrr.IsField(711), Is.True); // No Field also a field
Assert.That(tcrr.GetGroup(711).IsField(311), Is.True);
Assert.That(tcrr.Groups[711].Fields[311].Name, Is.EqualTo("UnderlyingSymbol"));
Assert.That(tcrr.Groups[711].Delim, Is.EqualTo(311));
DDMap tcr = dd.Messages["AE"];
Expand All @@ -108,9 +108,9 @@ public void NestedGroupTest()
dd.LoadFIXSpec("FIX44");
DDMap msgJ = dd.Messages["J"];

Assert.True(msgJ.IsGroup(73));
Assert.False(msgJ.IsGroup(756));
Assert.True(msgJ.GetGroup(73).IsGroup(756));
Assert.That(msgJ.IsGroup(73), Is.True);
Assert.That(msgJ.IsGroup(756), Is.False);
Assert.That(msgJ.GetGroup(73).IsGroup(756), Is.True);
}

[Test]
Expand All @@ -119,12 +119,12 @@ public void GroupBeginsGroupTest()
DataDictionary dd = new DataDictionary();
dd.LoadTestFIXSpec("group_begins_group");
DDMap msg = dd.Messages["magic"];
Assert.True(msg.IsGroup(6660)); // NoMagics group
Assert.True(msg.GetGroup(6660).IsGroup(7770)); // NoMagics/NoRabbits
Assert.True(msg.GetGroup(6660).IsField(6661)); // NoMagics/MagicWord
Assert.True(msg.GetGroup(6660).GetGroup(7770).IsField(7711)); // NoMagics/NoRabbits/RabbitName
Assert.AreEqual(7770, msg.GetGroup(6660).Delim); // NoMagics delim is NoRabbits counter
Assert.AreEqual(7711, msg.GetGroup(6660).GetGroup(7770).Delim); // NoRabbits delim is RabbitName
Assert.That(msg.IsGroup(6660), Is.True); // NoMagics group
Assert.That(msg.GetGroup(6660).IsGroup(7770), Is.True); // NoMagics/NoRabbits
Assert.That(msg.GetGroup(6660).IsField(6661), Is.True); // NoMagics/MagicWord
Assert.That(msg.GetGroup(6660).GetGroup(7770).IsField(7711), Is.True); // NoMagics/NoRabbits/RabbitName
Assert.That(msg.GetGroup(6660).Delim, Is.EqualTo(7770)); // NoMagics delim is NoRabbits counter
Assert.That(msg.GetGroup(6660).GetGroup(7770).Delim, Is.EqualTo(7711)); // NoRabbits delim is RabbitName
}

[Test]
Expand All @@ -133,27 +133,27 @@ public void HeaderGroupTest()
DataDictionary dd = new DataDictionary();
dd.LoadFIXSpec("FIX44");
DDMap headerMap = dd.Header;
Assert.True(headerMap.IsGroup(627));
Assert.That(headerMap.IsGroup(627), Is.True);
DDGrp grpMap = headerMap.GetGroup(627);
Assert.True(dd.Header.GetGroup(627).IsField(628));
Assert.True(grpMap.IsField(628));
Assert.That(dd.Header.GetGroup(627).IsField(628), Is.True);
Assert.That(grpMap.IsField(628), Is.True);
}

[Test]
public void ReqFldTest()
{
DataDictionary dd = new DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.True(dd.Messages["AE"].ReqFields.Contains(571));
Assert.False(dd.Messages["AE"].ReqFields.Contains(828));
Assert.That(dd.Messages["AE"].ReqFields.Contains(571), Is.True);
Assert.That(dd.Messages["AE"].ReqFields.Contains(828), Is.False);
}

[Test]
public void HeaderTest()
{
DataDictionary dd = new DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.True(dd.Header.ReqFields.Contains(9));
Assert.That(dd.Header.ReqFields.Contains(9), Is.True);
Assert.That(dd.Header.Fields.Count, Is.EqualTo(27));
}

Expand All @@ -162,7 +162,7 @@ public void TrailerTest()
{
DataDictionary dd = new DataDictionary();
dd.LoadFIXSpec("FIX44");
Assert.True(dd.Trailer.ReqFields.Contains(10));
Assert.That(dd.Trailer.ReqFields.Contains(10), Is.True);
Assert.That(dd.Trailer.Fields.Count, Is.EqualTo(3));
}

Expand Down Expand Up @@ -315,8 +315,8 @@ public void CheckGroupCountTest()

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

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

// AD => Instrument component (optional) => 55 (Symbol)
Assert.False(dd.Messages["AD"].ReqFields.Contains(55));
Assert.That(dd.Messages["AD"].ReqFields.Contains(55), Is.False);
// 7 => Instrument component (required) => 55 (Symbol)
Assert.True(dd.Messages["7"].ReqFields.Contains(55));
Assert.That(dd.Messages["7"].ReqFields.Contains(55), Is.True);
}

[Test]
public void Issue134_RequiredIsOptional()
{
DataDictionary dd = new DataDictionary();
dd.LoadTestFIXSpec("required_is_optional");
Assert.True(dd.Messages["magic"].ReqFields.Contains(1111)); //base required field
Assert.False(dd.Messages["magic"].ReqFields.Contains(5555)); //base optional field
Assert.False(dd.Messages["magic"].ReqFields.Contains(5556)); //component optional field
Assert.That(dd.Messages["magic"].ReqFields.Contains(1111), Is.True); //base required field
Assert.That(dd.Messages["magic"].ReqFields.Contains(5555), Is.False); //base optional field
Assert.That(dd.Messages["magic"].ReqFields.Contains(5556), Is.False); //component optional field

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

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

DDMap logon = dd.GetMapForMessage("A")!;
Assert.True(logon.IsField(108)); // HeartBtInt
Assert.True(logon.IsField(9000)); // CustomField
Assert.That(logon.IsField(108), Is.True); // HeartBtInt
Assert.That(logon.IsField(9000), Is.True); // CustomField

DDMap news = dd.GetMapForMessage("B")!;
Assert.True(news.IsField(148)); // Headline
Assert.True(news.IsGroup(33)); // LinesOfText
Assert.True(news.GetGroup(33).IsField(355)); // EncodedText
Assert.That(news.IsField(148), Is.True); // Headline
Assert.That(news.IsGroup(33), Is.True); // LinesOfText
Assert.That(news.GetGroup(33).IsField(355), Is.True); // EncodedText
}

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

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

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

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

// alt error message, where parent has no name
parentNode = MakeNode("<parentnode/>");
dpx = Assert.Throws<DictionaryParseException>(
delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("<field>qty</field>"), parentNode); })!;
Assert.AreEqual("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/parentnode'", dpx.Message);
Assert.That(dpx.Message, Is.EqualTo("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/parentnode'"));
}
}
}
12 changes: 6 additions & 6 deletions UnitTests/DataDictionary_ValidateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void UnsupportedVersionTest() {

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

[Test]
Expand All @@ -41,7 +41,7 @@ public void TagOutOfOrderTest() {

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

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

Assert.AreEqual("abracadabra", magicGroup.GetString(6661));
Assert.AreEqual("Floppy", rabbitGroup.GetString(7711));
Assert.AreEqual("white", rabbitGroup.GetString(7712));
Assert.That(magicGroup.GetString(6661), Is.EqualTo("abracadabra"));
Assert.That(rabbitGroup.GetString(7711), Is.EqualTo("Floppy"));
Assert.That(rabbitGroup.GetString(7712), Is.EqualTo("white"));
}

[Test]
Expand Down Expand Up @@ -273,7 +273,7 @@ public void RequiredComponentRequiredField()

var ex = Assert.Throws<RequiredTagMissing>(() =>
DataDictionary.Validate(message, dd, dd, beginString, msgType));
Assert.AreEqual(55, ex!.Field);
Assert.That(ex!.Field, Is.EqualTo(55));
}

[Test] // Issue #66
Expand Down
Loading

0 comments on commit 9e7f0aa

Please sign in to comment.