diff --git a/QuickFIXn/AcceptorSocketDescriptor.cs b/QuickFIXn/AcceptorSocketDescriptor.cs index 2349b44d9..527ea062b 100644 --- a/QuickFIXn/AcceptorSocketDescriptor.cs +++ b/QuickFIXn/AcceptorSocketDescriptor.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Net; using QuickFix.Logger; @@ -14,13 +15,20 @@ internal class AcceptorSocketDescriptor public AcceptorSocketDescriptor( IPEndPoint socketEndPoint, SocketSettings socketSettings, - SettingsDictionary sessionDict, NonSessionLog nonSessionLog) { Address = socketEndPoint; - SocketReactor = new ThreadedSocketReactor(Address, socketSettings, sessionDict, this, nonSessionLog); + SocketReactor = new ThreadedSocketReactor(Address, socketSettings, this, nonSessionLog); } + [Obsolete("Param 'sessionDict' is unused. Use the alt constructor without it.")] + public AcceptorSocketDescriptor( + IPEndPoint socketEndPoint, + SocketSettings socketSettings, + SettingsDictionary sessionDict, + NonSessionLog nonSessionLog) : this(socketEndPoint, socketSettings, nonSessionLog) + { } + internal void AcceptSession(Session session) { lock (_acceptedSessions) diff --git a/QuickFIXn/Fields/Converters/AsciiConverter.cs b/QuickFIXn/Fields/Converters/AsciiConverter.cs index a798ef93f..e77df7674 100644 --- a/QuickFIXn/Fields/Converters/AsciiConverter.cs +++ b/QuickFIXn/Fields/Converters/AsciiConverter.cs @@ -10,18 +10,18 @@ public static class AsciiValidator public const int ASCII_NINE = 57; public const int ASCII_MINUS = 45; - /// /// TODO can we use NumberFormatInfo or NumberStyles to avoid this bit of ASCII hackery? - /// Validates that a string looks like number (for use before conversion to an int, ulong, etc.). + /// + /// Validates that a string looks like a number (for use before conversion to an int, ulong, etc.). /// /// /// public static void Validate(string i) { - if ((null == i) || (i.Length < 1)) + if (i is null || i.Length < 1) throw new FieldConvertError("The argument string cannot be null or empty"); int asciiValOfFirstChar = System.Convert.ToInt32(i[0]); - if ((asciiValOfFirstChar < ASCII_ZERO) || (asciiValOfFirstChar > ASCII_NINE)) + if (asciiValOfFirstChar < ASCII_ZERO || asciiValOfFirstChar > ASCII_NINE) if (asciiValOfFirstChar != ASCII_MINUS) throw new FieldConvertError("Could not convert string to int (" + i + "): The first character must be a digit or a minus sign"); } diff --git a/QuickFIXn/ThreadedSocketAcceptor.cs b/QuickFIXn/ThreadedSocketAcceptor.cs index c57ce7950..840300aab 100755 --- a/QuickFIXn/ThreadedSocketAcceptor.cs +++ b/QuickFIXn/ThreadedSocketAcceptor.cs @@ -94,7 +94,7 @@ private AcceptorSocketDescriptor GetAcceptorSocketDescriptor(SettingsDictionary if (!_socketDescriptorForAddress.TryGetValue(socketEndPoint, out var descriptor)) { - descriptor = new AcceptorSocketDescriptor(socketEndPoint, socketSettings, dict, _nonSessionLog); + descriptor = new AcceptorSocketDescriptor(socketEndPoint, socketSettings, _nonSessionLog); _socketDescriptorForAddress[socketEndPoint] = descriptor; } diff --git a/QuickFIXn/ThreadedSocketReactor.cs b/QuickFIXn/ThreadedSocketReactor.cs index ac7e5b103..daaceec06 100755 --- a/QuickFIXn/ThreadedSocketReactor.cs +++ b/QuickFIXn/ThreadedSocketReactor.cs @@ -36,7 +36,6 @@ public State ReactorState internal ThreadedSocketReactor( IPEndPoint serverSocketEndPoint, SocketSettings socketSettings, - SettingsDictionary sessionDict, AcceptorSocketDescriptor? acceptorSocketDescriptor, NonSessionLog nonSessionLog) { diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 438749c53..620563d0e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -40,6 +40,8 @@ What's New * deprecate Field.Obj (renamed to Value) * deprecate Field.getValue/setValue (just use Value getter/setter) * #889 - nullable-ize Examples and fix deprecations (gbirchmeier) +* #TBD - nullable-ize UnitTests project (gbirchmeier) + * also deprecate a AcceptorSocketDescriptor ctor due to unused param ### v1.12.0 diff --git a/UnitTests/DataDictionaryTests.cs b/UnitTests/DataDictionaryTests.cs index aac8303d1..87db364dd 100644 --- a/UnitTests/DataDictionaryTests.cs +++ b/UnitTests/DataDictionaryTests.cs @@ -379,7 +379,7 @@ private static XmlNode MakeNode(string xmlString) if (xmlString.StartsWith('<')) { doc.LoadXml(xmlString); - return doc.DocumentElement; + return doc.DocumentElement!; } return doc.CreateTextNode(xmlString); } @@ -392,18 +392,18 @@ public void VerifyChildNodeAndReturnNameAtt() { MakeNode(""), parentNode)); DictionaryParseException dpx = Assert.Throws( - delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("foo"), parentNode); }); - Assert.AreEqual("Malformed data dictionary: Found text-only node containing 'foo'", dpx!.Message); + delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("foo"), parentNode); })!; + Assert.AreEqual("Malformed data dictionary: Found text-only node containing 'foo'", dpx.Message); dpx = Assert.Throws( - delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("qty"), parentNode); }); - Assert.AreEqual("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/Daddy'", dpx!.Message); + delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("qty"), parentNode); })!; + Assert.AreEqual("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/Daddy'", dpx.Message); // alt error message, where parent has no name parentNode = MakeNode(""); dpx = Assert.Throws( - delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("qty"), parentNode); }); - Assert.AreEqual("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/parentnode'", dpx!.Message); + delegate { DataDictionary.VerifyChildNodeAndReturnNameAtt(MakeNode("qty"), parentNode); })!; + Assert.AreEqual("Malformed data dictionary: Found 'field' node without 'name' within parent 'parentnode/parentnode'", dpx.Message); } } } diff --git a/UnitTests/Fields/Converters/DecimalConverterTests.cs b/UnitTests/Fields/Converters/DecimalConverterTests.cs index 734454b2f..6363fd7a1 100644 --- a/UnitTests/Fields/Converters/DecimalConverterTests.cs +++ b/UnitTests/Fields/Converters/DecimalConverterTests.cs @@ -11,29 +11,29 @@ public class DecimalConverterTests { [Test] public void Convert() { - Assert.That(DecimalConverter.Convert(new Decimal(4.23322)), Is.EqualTo("4.23322")); - Assert.That(DecimalConverter.Convert(new Decimal(-4.23322)), Is.EqualTo("-4.23322")); + Assert.That(DecimalConverter.Convert(4.23322m), Is.EqualTo("4.23322")); + Assert.That(DecimalConverter.Convert(-4.23322m), Is.EqualTo("-4.23322")); Assert.That(DecimalConverter.Convert("4332.33"), Is.EqualTo(new Decimal(4332.33))); Assert.That(DecimalConverter.Convert("3.000000000021874E-4"), Is.EqualTo(0.0003000000000021874M)); Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert("2.32a34"); }); Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert("+1.2"); }); Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert("(1.2)"); }); Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert(""); }); - Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert(null); }); + Assert.Throws(typeof(FieldConvertError), delegate { DecimalConverter.Convert(null!); }); // check for a different culture than en-XX - System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo( "tr-TR" ); - Assert.That( DecimalConverter.Convert( "4332.33" ), Is.EqualTo( new Decimal( 4332.33 ) ) ); - Assert.That( DecimalConverter.Convert( "-2.33" ), Is.EqualTo( new Decimal( -2.33 ) ) ); - Assert.That( DecimalConverter.Convert( new Decimal( 4.23322 ) ), Is.EqualTo( "4.23322" ) ); - Assert.That( DecimalConverter.Convert( new Decimal( -4.23322 ) ), Is.EqualTo( "-4.23322" ) ); + System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("tr-TR"); + Assert.That(DecimalConverter.Convert("4332.33"), Is.EqualTo(4332.33m)); + Assert.That(DecimalConverter.Convert("-2.33"), Is.EqualTo(-2.33m)); + Assert.That(DecimalConverter.Convert(4.23322m), Is.EqualTo("4.23322")); + Assert.That(DecimalConverter.Convert(-4.23322m), Is.EqualTo("-4.23322")); } [Test] public void Convert_WithoutLeadingTrailingZeros() { - Assert.That(DecimalConverter.Convert("23."), Is.EqualTo(new Decimal(23))); - Assert.That(DecimalConverter.Convert(".23"), Is.EqualTo(new Decimal(0.23))); - Assert.That(DecimalConverter.Convert("-.23"), Is.EqualTo(new Decimal(-0.23))); + Assert.That(DecimalConverter.Convert("23."), Is.EqualTo(23m)); + Assert.That(DecimalConverter.Convert(".23"), Is.EqualTo(0.23m)); + Assert.That(DecimalConverter.Convert("-.23"), Is.EqualTo(-0.23m)); } } diff --git a/UnitTests/Fields/Converters/IntConverterTests.cs b/UnitTests/Fields/Converters/IntConverterTests.cs index 827aebd46..e2b8152f8 100644 --- a/UnitTests/Fields/Converters/IntConverterTests.cs +++ b/UnitTests/Fields/Converters/IntConverterTests.cs @@ -19,6 +19,6 @@ public void Convert() Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert("AB"); }); Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert("2.3234"); }); Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert(""); }); - Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert(null); }); + Assert.Throws(typeof(FieldConvertError), delegate { IntConverter.Convert(null!); }); } } diff --git a/UnitTests/FileStoreTests.cs b/UnitTests/FileStoreTests.cs index bed03da65..ed6c6470c 100755 --- a/UnitTests/FileStoreTests.cs +++ b/UnitTests/FileStoreTests.cs @@ -3,6 +3,7 @@ using System.IO; using NUnit.Framework; using System.Threading; +using QuickFix; using QuickFix.Store; namespace UnitTests @@ -10,13 +11,13 @@ namespace UnitTests [TestFixture] public class FileStoreTests { - private FileStore _store; - private FileStoreFactory _factory; + private FileStore? _store; + private FileStoreFactory? _factory; - private QuickFix.SessionSettings _settings; - private QuickFix.SessionID _sessionID; + private QuickFix.SessionSettings _settings = new(); + private QuickFix.SessionID _sessionId = new("unset", "unset", "unset"); - private string _storeDirectory; + private string _storeDirectory = "unset"; [SetUp] public void Setup() @@ -26,34 +27,30 @@ public void Setup() if (System.IO.Directory.Exists(_storeDirectory)) System.IO.Directory.Delete(_storeDirectory, true); - _sessionID = new QuickFix.SessionID("FIX.4.2", "SENDERCOMP", "TARGETCOMP"); + _sessionId = new QuickFix.SessionID("FIX.4.2", "SENDERCOMP", "TARGETCOMP"); QuickFix.SettingsDictionary config = new QuickFix.SettingsDictionary(); config.SetString(QuickFix.SessionSettings.CONNECTION_TYPE, "initiator"); config.SetString(QuickFix.SessionSettings.FILE_STORE_PATH, _storeDirectory); _settings = new QuickFix.SessionSettings(); - _settings.Set(_sessionID, config); + _settings.Set(_sessionId, config); _factory = new FileStoreFactory(_settings); - _store = (FileStore)_factory.Create(_sessionID); + _store = (FileStore)_factory.Create(_sessionId); } void RebuildStore() { - if(_store != null) - { - _store.Dispose(); - } - - _store = (FileStore)_factory.Create(_sessionID); + _store?.Dispose(); + _store = (FileStore)_factory!.Create(_sessionId); } [TearDown] public void Teardown() { - _store.Dispose(); + _store!.Dispose(); Directory.Delete(_storeDirectory, true); } @@ -79,7 +76,7 @@ public void GenerateFileNamesTest() [Test] public void NextSenderMsgSeqNumTest() { - Assert.AreEqual(1, _store.NextSenderMsgSeqNum); + Assert.AreEqual(1, _store!.NextSenderMsgSeqNum); _store.NextSenderMsgSeqNum = 5; Assert.AreEqual(5, _store.NextSenderMsgSeqNum); RebuildStore(); @@ -89,7 +86,7 @@ public void NextSenderMsgSeqNumTest() [Test] public void IncNextSenderMsgSeqNumTest() { - _store.IncrNextSenderMsgSeqNum(); + _store!.IncrNextSenderMsgSeqNum(); Assert.AreEqual(2, _store.NextSenderMsgSeqNum); RebuildStore(); Assert.AreEqual(2, _store.NextSenderMsgSeqNum); @@ -98,7 +95,7 @@ public void IncNextSenderMsgSeqNumTest() [Test] public void NextTargetMsgSeqNumTest() { - Assert.AreEqual(1, _store.NextTargetMsgSeqNum); + Assert.AreEqual(1, _store!.NextTargetMsgSeqNum); _store.NextTargetMsgSeqNum = 6; Assert.AreEqual(6, _store.NextTargetMsgSeqNum); RebuildStore(); @@ -108,7 +105,7 @@ public void NextTargetMsgSeqNumTest() [Test] public void IncNextTargetMsgSeqNumTest() { - _store.IncrNextTargetMsgSeqNum(); + _store!.IncrNextTargetMsgSeqNum(); Assert.AreEqual(2, _store.NextTargetMsgSeqNum); RebuildStore(); Assert.AreEqual(2, _store.NextTargetMsgSeqNum); @@ -119,7 +116,7 @@ public void IncNextTargetMsgSeqNumTest() public void TestSeqNumLimitsForContinuousMarkets() { // Given the next seqnums are UInt64.MaxValue - 1 - _store.NextSenderMsgSeqNum = System.UInt64.MaxValue - 1; + _store!.NextSenderMsgSeqNum = System.UInt64.MaxValue - 1; _store.NextTargetMsgSeqNum = _store.NextSenderMsgSeqNum; // When the next seqnums are incremented @@ -157,7 +154,7 @@ public void TestSeqNumLimitsForContinuousMarkets() public void ResetTest() { // seq nums reset - _store.NextTargetMsgSeqNum = 5; + _store!.NextTargetMsgSeqNum = 5; _store.NextSenderMsgSeqNum = 4; _store.Reset(); Assert.AreEqual(1, _store.NextTargetMsgSeqNum); @@ -179,7 +176,7 @@ public void ResetTest() [Test] public void CreationTimeTest() { - DateTime d1 = _store.CreationTime.Value; + DateTime d1 = _store!.CreationTime!.Value; RebuildStore(); DateTime d2 = _store.CreationTime.Value; Util.UtcDateTimeSerializerTests.AssertHackyDateTimeEquality(d1, d2); @@ -194,7 +191,7 @@ public void CreationTimeTest() [Test] public void GetTest() { - _store.Set(1, "dude"); + _store!.Set(1, "dude"); _store.Set(2, "pude"); _store.Set(3, "ok"); _store.Set(4, "ohai"); diff --git a/UnitTests/GroupTests.cs b/UnitTests/GroupTests.cs index 5daad06b9..25dad3555 100644 --- a/UnitTests/GroupTests.cs +++ b/UnitTests/GroupTests.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NUnit.Framework; +using NUnit.Framework; using QuickFix; using QuickFix.Fields; @@ -15,40 +12,38 @@ public void SubGroup() { // issue #11 bug, as reported by karabiberoglu's further-down post - QuickFix.FIX44.CollateralInquiry.NoPartyIDsGroup noParty = new QuickFix.FIX44.CollateralInquiry.NoPartyIDsGroup(); - noParty.PartyID = new QuickFix.Fields.PartyID("ABC"); - noParty.PartyIDSource = new QuickFix.Fields.PartyIDSource(QuickFix.Fields.PartyIDSource.PROPRIETARY_CUSTOM_CODE); - noParty.PartyRole = new QuickFix.Fields.PartyRole(QuickFix.Fields.PartyRole.CLEARING_FIRM); + QuickFix.FIX44.CollateralInquiry.NoPartyIDsGroup noParty = new(); + noParty.PartyID = new PartyID("ABC"); + noParty.PartyIDSource = new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE); + noParty.PartyRole = new PartyRole(PartyRole.CLEARING_FIRM); // group in group - QuickFix.FIX44.CollateralInquiry.NoPartyIDsGroup.NoPartySubIDsGroup noPartySub = new QuickFix.FIX44.CollateralInquiry.NoPartyIDsGroup.NoPartySubIDsGroup(); - noPartySub.PartySubID = new QuickFix.Fields.PartySubID("subABC"); - noPartySub.PartySubIDType = new QuickFix.Fields.PartySubIDType(QuickFix.Fields.PartySubIDType.FIRM); + QuickFix.FIX44.CollateralInquiry.NoPartyIDsGroup.NoPartySubIDsGroup noPartySub = new(); + noPartySub.PartySubID = new PartySubID("subABC"); + noPartySub.PartySubIDType = new PartySubIDType(PartySubIDType.FIRM); noParty.AddGroup(noPartySub); - noPartySub.PartySubID = new QuickFix.Fields.PartySubID("subDEF"); - noPartySub.PartySubIDType = new QuickFix.Fields.PartySubIDType(QuickFix.Fields.PartySubIDType.LOCATION); + noPartySub.PartySubID = new PartySubID("subDEF"); + noPartySub.PartySubIDType = new PartySubIDType(PartySubIDType.LOCATION); noParty.AddGroup(noPartySub); string msgString = noParty.ToString(); - string expected = String.Join(Message.SOH, new string[] { - "448=ABC","447=D","452=4", - "802=2", //NoPartySubIDs - "523=subABC","803=1", - "523=subDEF","803=31" - }); + string expected = "448=ABC|447=D|452=4|" + + "802=2|" //NoPartySubIDs + + "523=subABC|803=1|" + + "523=subDEF|803=31|"; //Console.WriteLine(msgString); - StringAssert.Contains(expected, msgString); + StringAssert.Contains(expected, msgString.Replace(Message.SOH, '|')); } [Test] public void GroupClone() { - QuickFix.FIX42.News.LinesOfTextGroup linesGroup = new QuickFix.FIX42.News.LinesOfTextGroup(); - linesGroup.Text = new QuickFix.Fields.Text("foo"); - linesGroup.EncodedText = new QuickFix.Fields.EncodedText("bar"); + QuickFix.FIX42.News.LinesOfTextGroup linesGroup = new(); + linesGroup.Text = new Text("foo"); + linesGroup.EncodedText = new EncodedText("bar"); - QuickFix.FIX42.News.LinesOfTextGroup clone = linesGroup.Clone() as QuickFix.FIX42.News.LinesOfTextGroup; + QuickFix.FIX42.News.LinesOfTextGroup clone = (linesGroup.Clone() as QuickFix.FIX42.News.LinesOfTextGroup)!; Assert.AreEqual(linesGroup.Text.Value, clone.Text.Value); Assert.AreEqual(linesGroup.EncodedText.Value, clone.EncodedText.Value); diff --git a/UnitTests/MessageCrackerTests.cs b/UnitTests/MessageCrackerTests.cs index 4d9dd53c6..ddfaa3e27 100644 --- a/UnitTests/MessageCrackerTests.cs +++ b/UnitTests/MessageCrackerTests.cs @@ -1,18 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; using NUnit.Framework; using QuickFix; -using QuickFix.Fields; using System.Reflection; - namespace UnitTests { [TestFixture] public class MessageCrackerTests { - private readonly SessionID _DummySessionID = new SessionID("a","b","c"); + private readonly SessionID _dummySessionId = new ("a","b","c"); [SetUp] public void Setup() @@ -87,21 +83,21 @@ public class TestCracker : MessageCracker public void GoldenPath() { MessageCracker mc = new TestCracker(); - TestCracker tc = mc as TestCracker; + TestCracker tc = (mc as TestCracker)!; - mc.Crack(new QuickFix.FIX42.News(), _DummySessionID); + mc.Crack(new QuickFix.FIX42.News(), _dummySessionId); Assert.IsTrue(tc.CrackedNews42); Assert.IsFalse(tc.CrackedNews44); // reset and do the opposite tc.CrackedNews42 = false; - mc.Crack(new QuickFix.FIX44.News(), _DummySessionID); + mc.Crack(new QuickFix.FIX44.News(), _dummySessionId); Assert.IsFalse(tc.CrackedNews42); Assert.IsTrue(tc.CrackedNews44); Assert.IsFalse(tc.CrackedLogonFIXT11); - mc.Crack(new QuickFix.FIXT11.Logon(), _DummySessionID); + mc.Crack(new QuickFix.FIXT11.Logon(), _dummySessionId); Assert.IsTrue(tc.CrackedLogonFIXT11); } @@ -109,8 +105,8 @@ public void GoldenPath() public void UnsupportedMessage() { MessageCracker mc = new TestCracker(); - Assert.Throws(delegate { mc.Crack(new QuickFix.FIX42.Email(), _DummySessionID); }); - Assert.Throws(delegate { mc.Crack(new QuickFix.FIX43.News(), _DummySessionID); }); + Assert.Throws(delegate { mc.Crack(new QuickFix.FIX42.Email(), _dummySessionId); }); + Assert.Throws(delegate { mc.Crack(new QuickFix.FIX43.News(), _dummySessionId); }); } } } diff --git a/UnitTests/MessageTests.cs b/UnitTests/MessageTests.cs index 132c666d4..c4993f37b 100644 --- a/UnitTests/MessageTests.cs +++ b/UnitTests/MessageTests.cs @@ -367,8 +367,8 @@ public void XmlDataWithoutLengthTest() { + "10=028|").Replace('|', Message.SOH); FieldNotFoundException ex = - Assert.Throws(delegate { n.FromString(s, true, dd, dd, _defaultMsgFactory); }); - Assert.AreEqual("field not found for tag: 212", ex!.Message); + Assert.Throws(delegate { n.FromString(s, true, dd, dd, _defaultMsgFactory); })!; + Assert.AreEqual("field not found for tag: 212", ex.Message); } [Test] diff --git a/UnitTests/MessageToXmlTests.cs b/UnitTests/MessageToXmlTests.cs index 8d22a3b89..a1388bc48 100644 --- a/UnitTests/MessageToXmlTests.cs +++ b/UnitTests/MessageToXmlTests.cs @@ -99,7 +99,7 @@ public void ToJSONWithGroupsTest() StringAssert.Contains("\"35\":\"8\"", msg.ToJSON(dataDictionary: null)); // EXCEPTION CASE: params (null, true) => Exception - var ex = Assert.Throws(delegate { msg.ToJSON(null, true); }); + var ex = Assert.Throws(delegate { msg.ToJSON(null, true); })!; StringAssert.Contains( "Must be non-null if 'convertEnumsToDescriptions' is true. (Parameter 'dataDictionary')", ex.Message); diff --git a/UnitTests/SessionDynamicTest.cs b/UnitTests/SessionDynamicTest.cs index 1c405a194..f442c2e8b 100644 --- a/UnitTests/SessionDynamicTest.cs +++ b/UnitTests/SessionDynamicTest.cs @@ -20,8 +20,8 @@ class SessionDynamicTest { public class TestApplication : IApplication { - Action _logonNotify; - Action _logoffNotify; + private readonly Action _logonNotify; + private readonly Action _logoffNotify; public TestApplication(Action logonNotify, Action logoffNotify) { _logonNotify = logonNotify; @@ -55,7 +55,7 @@ public SocketState(Socket s) public Socket _socket; public byte[] _rxBuffer = new byte[1024]; public string _messageFragment = string.Empty; - public string _exMessage; + public string _exMessage = "unset"; } const string Host = "127.0.0.1"; diff --git a/UnitTests/SessionScheduleTests.cs b/UnitTests/SessionScheduleTests.cs index 953b1b320..ecfa36ba3 100755 --- a/UnitTests/SessionScheduleTests.cs +++ b/UnitTests/SessionScheduleTests.cs @@ -44,15 +44,15 @@ private static string PacificStandardTimeZoneId public void TestCtor_BasicDailySchedule() { SettingsDictionary settings = new SettingsDictionary(); - var ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + Exception ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); })!; StringAssert.Contains("No value for key: StartTime", ex.Message); settings.SetString(SessionSettings.START_TIME, "00:00:00"); - ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); })!; StringAssert.Contains("No value for key: EndTime", ex.Message); settings.SetString(SessionSettings.END_TIME, "00:0blkajsdf"); - ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); })!; StringAssert.Contains("String '00:0blkajsdf' was not recognized as a valid TimeSpan", ex.Message); settings.SetString(SessionSettings.END_TIME, "00:00:00"); @@ -67,7 +67,7 @@ public void TestCtor_WeeklongSession() settings.SetString(SessionSettings.END_TIME, "00:00:00"); settings.SetDay(SessionSettings.START_DAY, DayOfWeek.Thursday); - var ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + Exception ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); })!; StringAssert.Contains("StartDay used without EndDay", ex.Message); settings.SetDay(SessionSettings.END_DAY, DayOfWeek.Friday); @@ -80,7 +80,7 @@ public void TestCtor_WeekdaysSession() SettingsDictionary settings = new SettingsDictionary(); settings.SetString(SessionSettings.WEEKDAYS, "Sun,Tue,Fri"); - var ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + Exception ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); })!; StringAssert.Contains("No value for key: StartTime", ex.Message); settings.SetString(SessionSettings.START_TIME, "00:00:00"); @@ -88,7 +88,7 @@ public void TestCtor_WeekdaysSession() Assert.DoesNotThrow(delegate { new SessionSchedule(settings); }); settings.SetString(SessionSettings.START_DAY, "Tue"); - ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); })!; StringAssert.Contains("StartDay/EndDay are not compatible with 'Weekdays' setting", ex.Message); } @@ -100,13 +100,13 @@ public void TestCtor_NonStopSession() Assert.DoesNotThrow(delegate { new SessionSchedule(settings); }); settings.SetString(SessionSettings.START_DAY, "Monday"); - var ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + Exception ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); })!; StringAssert.Contains("NonStopSession is not compatible with StartDay/EndDay and StartTime/EndTime", ex.Message); settings = new SettingsDictionary(); settings.SetBool(SessionSettings.NON_STOP_SESSION, true); settings.SetString(SessionSettings.START_TIME, "05:00:00"); - ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); })!; StringAssert.Contains("NonStopSession is not compatible with StartDay/EndDay and StartTime/EndTime", ex.Message); } diff --git a/UnitTests/SessionSettingsTest.cs b/UnitTests/SessionSettingsTest.cs index 9b6c8d1de..ca108193c 100755 --- a/UnitTests/SessionSettingsTest.cs +++ b/UnitTests/SessionSettingsTest.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Linq; using NUnit.Framework; using QuickFix; @@ -7,12 +8,12 @@ namespace UnitTests [TestFixture] public class SessionSettingsTest { - protected System.Text.StringBuilder partialConfiguration; + private System.Text.StringBuilder _partialConfiguration = new(); [SetUp] public void Init() { - partialConfiguration = new System.Text.StringBuilder() + _partialConfiguration = new System.Text.StringBuilder() .AppendLine("[SESSION]") .AppendLine("BeginString=FIX.4.2") .AppendLine("SenderCompID=ISLD") @@ -56,9 +57,9 @@ public void Load() .AppendLine("BeginString=FIX.4.0") .AppendLine("Value=4") .AppendLine("Empty=") - .AppendLine(partialConfiguration.ToString()) + .AppendLine(_partialConfiguration.ToString()) .ToString(); - SessionSettings settings = new SessionSettings(new System.IO.StringReader(configuration)); + SessionSettings settings = new SessionSettings(new StringReader(configuration)); SessionID session1 = new SessionID("FIX.4.2", "ISLD", "TW"); SessionID session2 = new SessionID("FIX.4.1", "ISLD", "WT"); @@ -99,14 +100,14 @@ public void Load() public void LoadSettingsWithDefaultSectionLast() { string configuration = new System.Text.StringBuilder() - .AppendLine(partialConfiguration.ToString()) + .AppendLine(_partialConfiguration.ToString()) .AppendLine("[DEFAULT]") .AppendLine("ConnectionType=initiator") .AppendLine("BeginString=FIX.4.0") .AppendLine("Value=4") .AppendLine("Empty=") .ToString(); - SessionSettings settings = new SessionSettings(new System.IO.StringReader(configuration)); + SessionSettings settings = new SessionSettings(new StringReader(configuration)); SessionID session1 = new SessionID("FIX.4.2", "ISLD", "TW"); SessionID session2 = new SessionID("FIX.4.1", "ISLD", "WT"); @@ -158,7 +159,7 @@ public void DuplicateSession() .AppendLine("SenderCompID=ISLD") .AppendLine("TargetCompID=TW") .ToString(); - Assert.Throws(delegate { new SessionSettings(new System.IO.StringReader(configuration)); }); + Assert.Throws(delegate { new SessionSettings(new StringReader(configuration)); }); } [Test] @@ -175,7 +176,7 @@ public void StripSpaces() .AppendLine(" Double = 1.23 ") .AppendLine(" Bool = N ") .ToString(); - SessionSettings settings = new SessionSettings(new System.IO.StringReader(configuration)); + SessionSettings settings = new SessionSettings(new StringReader(configuration)); Assert.That(settings.Get().GetString("ConnectionType"), Is.EqualTo("initiator")); @@ -232,13 +233,13 @@ public void SettingsToString() .AppendLine("TARGETCOMPID=WT") .AppendLine("VALUE=2") .ToString(); - SessionSettings settings = new SessionSettings(new System.IO.StringReader(configuration)); + SessionSettings settings = new SessionSettings(new StringReader(configuration)); Assert.That(settings.ToString(), Is.EqualTo(configuration)); } [Test] - public void testExtendedSettings() + public void TestExtendedSettings() { string settingsString = new System.Text.StringBuilder() .AppendLine("[DEFAULT]") @@ -259,7 +260,7 @@ public void testExtendedSettings() .AppendLine("EndTime=05:59:00") .ToString(); - SessionSettings settings = new SessionSettings(new System.IO.StringReader(settingsString)); + SessionSettings settings = new SessionSettings(new StringReader(settingsString)); SessionID id = new SessionID("FIX.4.2", "Company", "FixedIncome", "HongKong", "CLIENT1", "HedgeFund", "NYC"); Assert.That(settings.Get(id).GetString("HeartBtInt"), Is.EqualTo("60")); @@ -275,12 +276,8 @@ public void testExtendedSettings() Assert.That(settings.Get(id).GetString("MaxMessagesInResendRequest"), Is.EqualTo("2500")); Assert.That(settings.Get(id).GetString("StartTime"), Is.EqualTo("06:00:00")); Assert.That(settings.Get(id).GetString("EndTime"), Is.EqualTo("05:59:00")); - id = null; - foreach(SessionID sid in settings.GetSessions()) - { - id = sid; - break; - } + + id = settings.GetSessions().First(); Assert.NotNull(id); Assert.That(id.BeginString, Is.EqualTo("FIX.4.2")); Assert.That(id.SenderCompID, Is.EqualTo("Company")); @@ -310,7 +307,7 @@ public void CaseInsensitiveSectionName() BeginString=FIX.4.2 SenderCompID=ISLD TargetCompID=TW"; - SessionSettings settings = new SessionSettings(new System.IO.StringReader(configuration)); + SessionSettings settings = new SessionSettings(new StringReader(configuration)); Assert.That(settings.Get().GetString("ConnectionType"), Is.EqualTo("initiator")); diff --git a/UnitTests/SessionStateTest.cs b/UnitTests/SessionStateTest.cs index 2e0db7cc4..a5e79191f 100755 --- a/UnitTests/SessionStateTest.cs +++ b/UnitTests/SessionStateTest.cs @@ -169,8 +169,8 @@ public void ThreadSafeSetAndGet() { //Simulate background sending of messages that populate into the store AutoResetEvent setEvent = new AutoResetEvent(false); - ThreadPool.QueueUserWorkItem(delegate(object stateObject) { - AutoResetEvent internalSetEvent = (AutoResetEvent)((object[])stateObject)[0]; + ThreadPool.QueueUserWorkItem(delegate(object? stateObject) { + AutoResetEvent internalSetEvent = (AutoResetEvent)((object[])stateObject!)[0]; SessionState internalState = (SessionState)((object[])stateObject)[1]; for (SeqNumType i = 1001; i < 2000; i++) { try { @@ -187,8 +187,8 @@ public void ThreadSafeSetAndGet() { //Simulate background reading of messages from the store - like is done in a resend request answer AutoResetEvent getEvent = new AutoResetEvent(false); - ThreadPool.QueueUserWorkItem(delegate(object stateObject){ - AutoResetEvent internalGetEvent = (AutoResetEvent)((object[])stateObject)[0]; + ThreadPool.QueueUserWorkItem(delegate(object? stateObject){ + AutoResetEvent internalGetEvent = (AutoResetEvent)((object[])stateObject!)[0]; SessionState internalState = (SessionState)((object[])stateObject)[1]; for (SeqNumType i = 1; i < 1000; i++) { try { diff --git a/UnitTests/SettingsTest.cs b/UnitTests/SettingsTest.cs index 94cc53b3b..7a373bc85 100644 --- a/UnitTests/SettingsTest.cs +++ b/UnitTests/SettingsTest.cs @@ -34,14 +34,14 @@ public void Load() LinkedList foo = settings.Get("FOO"); Assert.That(foo.Count, Is.EqualTo(1)); - Assert.That(foo.First.Value.GetLong("bar"), Is.EqualTo(24)); + Assert.That(foo.First!.Value.GetLong("bar"), Is.EqualTo(24)); Assert.That(foo.First.Value.GetString("baz"), Is.EqualTo("moo")); Assert.That(foo.First.Value.GetString("baz"), Is.EqualTo("moo")); Assert.That(foo.First.Value.Count, Is.EqualTo(2)); LinkedList oren = settings.Get("OREN"); Assert.That(oren.Count, Is.EqualTo(2)); - Assert.That(oren.First.Value.Count, Is.EqualTo(1)); + Assert.That(oren.First!.Value.Count, Is.EqualTo(1)); Assert.That(oren.First.Value.GetString("Nero"), Is.EqualTo("TW")); oren.RemoveFirst(); Assert.That(oren.First.Value.Count, Is.EqualTo(2)); @@ -50,7 +50,7 @@ public void Load() LinkedList nero = settings.Get("NERO"); Assert.That(nero.Count, Is.EqualTo(1)); - Assert.That(nero.First.Value.Count, Is.EqualTo(5)); + Assert.That(nero.First!.Value.Count, Is.EqualTo(5)); Assert.That(nero.First.Value.GetString("WINDIR"), Is.EqualTo("D:\\This Is\\A-Directory\\Connamara\\")); Assert.That(nero.First.Value.GetString("UNIXDIR"), Is.EqualTo("/home/mgatny/This Is/A Directory/ok/")); Assert.That(nero.First.Value.GetString("WINFILE"), Is.EqualTo("D:\\Program Files\\Tomcat 4.1\\webapps\\mgatny\\WEB-INF\\connamara.cfg")); @@ -70,14 +70,14 @@ public void CaseInsensitiveSectionName() LinkedList byLower = settings.Get("foo"); Assert.AreEqual(1, byLower.Count); - Assert.AreEqual(2, byLower.First.Value.Count); + Assert.AreEqual(2, byLower.First!.Value.Count); Assert.AreEqual("uno", byLower.First.Value.GetString("one")); Assert.AreEqual("dos", byLower.First.Value.GetString("two")); // too lazy to write a QuickFix.Dictionary#Equals method (which would only be used by this test) LinkedList byUpper = settings.Get("FOO"); Assert.AreEqual(byLower.Count, byUpper.Count); - Assert.AreEqual(byLower.First.Value.Count, byUpper.First.Value.Count); + Assert.AreEqual(byLower.First.Value.Count, byUpper.First!.Value.Count); Assert.AreEqual(byUpper.First.Value.GetString("one"), byUpper.First.Value.GetString("one")); Assert.AreEqual(byUpper.First.Value.GetString("two"), byUpper.First.Value.GetString("two")); } diff --git a/UnitTests/ThreadedSocketReactorTests.cs b/UnitTests/ThreadedSocketReactorTests.cs index 57c300b99..cc9ad0505 100644 --- a/UnitTests/ThreadedSocketReactorTests.cs +++ b/UnitTests/ThreadedSocketReactorTests.cs @@ -11,17 +11,16 @@ namespace UnitTests [TestFixture] public class ThreadedSocketReactorTests { - static readonly Random _random = new Random(); - static TcpListener _tcpListener; + static TcpListener? _tcpListener; private int OccupyAPort() { - int randomPort; + Random random = new(); for (int i = 0; i < 10; i++) { try { - randomPort = _random.Next(5000, 6000); + int randomPort = random.Next(5000, 6000); _tcpListener = new TcpListener(IPAddress.Loopback, randomPort); _tcpListener.Start(); @@ -49,7 +48,6 @@ public void TestStartOnBusyPort() var testingObject = new ThreadedSocketReactor( new IPEndPoint(IPAddress.Loopback, port), settings, - sessionDict: null, acceptorSocketDescriptor: null, new NonSessionLog(new ScreenLogFactory(true, true, true))); @@ -61,10 +59,8 @@ public void TestStartOnBusyPort() } [TearDown] - public void TearDown() - { - if (_tcpListener != null) - _tcpListener.Stop(); + public void TearDown() { + _tcpListener?.Stop(); } } } diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index 5811fa7af..872b9c08d 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -2,6 +2,7 @@ net8.0 + enable AnyCPU;x64 false