Skip to content

Commit

Permalink
Merge pull request #811 from Rob-Hague/at2
Browse files Browse the repository at this point in the history
Convert acceptance tests to a test project
  • Loading branch information
gbirchmeier authored Dec 21, 2023
2 parents bc31535 + b8b2ab6 commit 21a4e85
Show file tree
Hide file tree
Showing 55 changed files with 894 additions and 1,929 deletions.
13 changes: 13 additions & 0 deletions AcceptanceTest/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[*.cs]

# NUnit2003: Consider using Assert.That(expr, Is.True) instead of Assert.IsTrue(expr)
dotnet_diagnostic.NUnit2003.severity = silent

# NUnit2005: Consider using Assert.That(actual, Is.EqualTo(expected)) instead of Assert.AreEqual(expected, actual)
dotnet_diagnostic.NUnit2005.severity = silent

# NUnit2017: Consider using Assert.That(expr, Is.Null) instead of Assert.IsNull(expr)
dotnet_diagnostic.NUnit2017.severity = silent

# NUnit2019: Consider using Assert.That(expr, Is.Not.Null) instead of Assert.IsNotNull(expr)
dotnet_diagnostic.NUnit2019.severity = silent
1 change: 0 additions & 1 deletion AcceptanceTest/.gitignore

This file was deleted.

29 changes: 13 additions & 16 deletions AcceptanceTest/ATApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ namespace AcceptanceTest
{
public class ATApplication : MessageCracker, IApplication
{
public event System.Action StopMeEvent;
public event System.Action? StopMeEvent;

private HashSet<KeyValuePair<string, SessionID>> clOrdIDs_ = new HashSet<KeyValuePair<string, SessionID>>();
private FileLog log_;
private readonly HashSet<KeyValuePair<string, SessionID>> _clOrdIDs = new();

public ATApplication(FileLog debugLog)
public ATApplication()
{
log_ = debugLog;
}

public void OnMessage(QuickFix.FIX40.NewOrderSingle nos, SessionID sessionID)
Expand Down Expand Up @@ -92,22 +90,22 @@ public void OnMessage(QuickFix.FIX50SP2.SecurityDefinition message, SessionID se

protected void Echo(Message message, SessionID sessionID)
{
Message echo = new Message(message);
Message echo = new(message);
Session.SendToTarget(echo, sessionID);
}

protected void ProcessNOS(Message message, SessionID sessionID)
{
Message echo = new Message(message);
Message echo = new(message);

bool possResend = false;
if (message.Header.IsSetField(QuickFix.Fields.Tags.PossResend))
possResend = message.Header.GetBoolean(QuickFix.Fields.Tags.PossResend);

KeyValuePair<string, SessionID> pair = new KeyValuePair<string, SessionID>(message.GetString(QuickFix.Fields.Tags.ClOrdID), sessionID);
if (possResend && clOrdIDs_.Contains(pair))
KeyValuePair<string, SessionID> pair = new(message.GetString(QuickFix.Fields.Tags.ClOrdID), sessionID);
if (possResend && _clOrdIDs.Contains(pair))
return;
clOrdIDs_.Add(pair);
_clOrdIDs.Add(pair);

Session.SendToTarget(echo, sessionID);
}
Expand All @@ -121,7 +119,7 @@ protected void ProcessNOS(Message message, SessionID sessionID)
public void OnMessage(QuickFix.FIX50SP1.News news, SessionID sessionID) { ProcessNews(news, sessionID); }
public void OnMessage(QuickFix.FIX50SP2.News news, SessionID sessionID) { ProcessNews(news, sessionID); }

public void ProcessNews(QuickFix.Message msg, SessionID sessionID)
public void ProcessNews(Message msg, SessionID sessionID)
{
if (msg.IsSetField(QuickFix.Fields.Tags.Headline) && (msg.GetString(QuickFix.Fields.Tags.Headline) == "STOPME"))
{
Expand All @@ -144,13 +142,12 @@ public void OnCreate(SessionID sessionID)
Session session = Session.LookupSession(sessionID);

// Hey QF/N users, don't do this in a real app.
if (null != session)
session.Reset("AT Session Reset");
session?.Reset("AT Session Reset");
}

public void OnLogout(SessionID sessionID)
{
clOrdIDs_.Clear();
_clOrdIDs.Clear();
}

public void OnLogon(SessionID sessionID)
Expand All @@ -166,13 +163,13 @@ public void FromApp(Message message, SessionID sessionID)

Crack(message, sessionID);
}
catch (QuickFix.UnsupportedMessageType)
catch (UnsupportedMessageType)
{
throw;
}
catch (System.Exception e)
{
log_.OnEvent("FromApp: " + e.ToString() + " while processing msg (" + message.ToString() + ")");
Session.LookupSession(sessionID).Log.OnEvent("Exception during FromApp: " + e.ToString() + "\n while processing msg (" + message.ToString() + ")");
}
}

Expand Down
64 changes: 0 additions & 64 deletions AcceptanceTest/ATRunner.cs

This file was deleted.

22 changes: 18 additions & 4 deletions AcceptanceTest/AcceptanceTest.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0</TargetFrameworks>
<Platforms>AnyCPU;x64</Platforms>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<Nullable>enable</Nullable>
</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" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Messages\FIX40\QuickFix.FIX40.csproj" />
<ProjectReference Include="..\Messages\FIX41\QuickFix.FIX41.csproj" />
Expand All @@ -19,4 +27,10 @@
<ProjectReference Include="..\QuickFIXn\QuickFix.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="cfg\**" CopyToOutputDirectory="PreserveNewest" />
<None Include="definitions\**" CopyToOutputDirectory="PreserveNewest" />
<None Include="..\spec\**" CopyToOutputDirectory="PreserveNewest" LinkBase="spec" />
</ItemGroup>

</Project>
72 changes: 0 additions & 72 deletions AcceptanceTest/Comparator.rb

This file was deleted.

37 changes: 0 additions & 37 deletions AcceptanceTest/ComparatorTestCase.rb

This file was deleted.

27 changes: 27 additions & 0 deletions AcceptanceTest/Fix40.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NUnit.Framework;
using QuickFix;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AcceptanceTest;

public class Fix40 : TestBase
{
private const string DefinitionsBaseDirPath = "definitions/server/fix40";

protected override SessionSettings Settings => new(@"cfg/at_40.cfg");

[TestCaseSource(nameof(Definitions))]
public void Fix40Test(string definitionFileName)
{
RunTest(Path.Combine(DefinitionsBaseDirPath, definitionFileName));
}

private static IEnumerable<string> Definitions()
{
return Directory.EnumerateFiles(DefinitionsBaseDirPath, "*.def")
.Select(f => Path.GetFileName(f)!)
.OrderBy(s => s);
}
}
27 changes: 27 additions & 0 deletions AcceptanceTest/Fix41.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NUnit.Framework;
using QuickFix;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AcceptanceTest;

public class Fix41 : TestBase
{
private const string DefinitionsBaseDirPath = "definitions/server/fix41";

protected override SessionSettings Settings => new(@"cfg/at_41.cfg");

[TestCaseSource(nameof(Definitions))]
public void Fix41Test(string definitionFileName)
{
RunTest(Path.Combine(DefinitionsBaseDirPath, definitionFileName));
}

private static IEnumerable<string> Definitions()
{
return Directory.EnumerateFiles(DefinitionsBaseDirPath, "*.def")
.Select(f => Path.GetFileName(f)!)
.OrderBy(s => s);
}
}
Loading

0 comments on commit 21a4e85

Please sign in to comment.