diff --git a/ConformU/AlpacaProtocolTestManager.cs b/ConformU/AlpacaProtocolTestManager.cs index e892008..1203479 100644 --- a/ConformU/AlpacaProtocolTestManager.cs +++ b/ConformU/AlpacaProtocolTestManager.cs @@ -75,9 +75,9 @@ public AlpacaProtocolTestManager(ConformConfiguration conformConfiguration, Conf applicationCancellationToken = conformCancellationToken; applicationCancellationTokenSource = conformCancellationTokenSource; settings = conformConfiguration.Settings; - issueMessages = new List(); - informationMessages = new List(); - errorMessages = new List(); + issueMessages = []; + informationMessages = []; + errorMessages = []; } protected virtual void Dispose(bool disposing) @@ -106,51 +106,56 @@ public void Dispose() #region Pre-formed status lists // HTTP statuses used to assess the outcome of protocol tests - private readonly List HttpStatusCodeAny = new(); - private readonly List HttpStatusCode200 = new() { HttpStatusCode.OK }; - private readonly List HttpStatusCode400 = new() { HttpStatusCode.BadRequest }; - private readonly List HttpStatusCode200And400 = new() { HttpStatusCode.OK, HttpStatusCode.BadRequest }; + private readonly List HttpStatusCodeAny = []; + private readonly List HttpStatusCode200 = [HttpStatusCode.OK]; + private readonly List HttpStatusCode400 = [HttpStatusCode.BadRequest]; + private readonly List HttpStatusCode200And400 = [HttpStatusCode.OK, HttpStatusCode.BadRequest]; - private readonly List HttpStatusCode4XX = new() { HttpStatusCode.BadRequest, HttpStatusCode.BadRequest, HttpStatusCode.Unauthorized, HttpStatusCode.PaymentRequired, HttpStatusCode.Forbidden, - HttpStatusCode.NotFound, HttpStatusCode.MethodNotAllowed, HttpStatusCode.NotAcceptable, HttpStatusCode.ProxyAuthenticationRequired, HttpStatusCode.Conflict, HttpStatusCode.Gone }; + private readonly List HttpStatusCode4XX = [ HttpStatusCode.BadRequest, HttpStatusCode.BadRequest, HttpStatusCode.Unauthorized, HttpStatusCode.PaymentRequired, HttpStatusCode.Forbidden, + HttpStatusCode.NotFound, HttpStatusCode.MethodNotAllowed, HttpStatusCode.NotAcceptable, HttpStatusCode.ProxyAuthenticationRequired, HttpStatusCode.Conflict, HttpStatusCode.Gone ]; #endregion #region Pre-formed parameter lists that can be sent to clients // ClientID and ClientTransactionID OK - internal List ParamsOk = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)) }; + internal List ParamsOk = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture))]; // ClientID and ClientTransactionID OK but with additional spurious parameter - internal List ParamsOkPlusExtraParameter = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ExtraParameter", "ExtraValue") }; + internal List ParamsOkPlusExtraParameter = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ExtraParameter", "ExtraValue")]; // ClientID and ClientTransactionID parameter names lower case - internal List ParamClientIDLowerCase = new() { new CheckProtocolParameter("clientid", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)) }; - internal List ParamTransactionIdLowerCase = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("clienttransactionid", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)) }; + internal List ParamClientIDLowerCase = [new CheckProtocolParameter("clientid", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture))]; + internal List ParamTransactionIdLowerCase = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("clienttransactionid", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture))]; // ClientID and ClientTransactionID values empty - internal List ParamClientIDEmpty = new() { new CheckProtocolParameter("ClientID", ""), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)) }; - internal List ParamTransactionIdEmpty = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", "") }; + internal List ParamClientIDEmpty = [new CheckProtocolParameter("ClientID", ""), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture))]; + internal List ParamTransactionIdEmpty = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", "")]; // ClientID and ClientTransactionID values white space - internal List ParamClientIDWhiteSpace = new() { new CheckProtocolParameter("ClientID", " "), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)) }; - internal List ParamTransactionIdWhiteSpace = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", " ") }; + internal List ParamClientIDWhiteSpace = [new CheckProtocolParameter("ClientID", " "), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture))]; + internal List ParamTransactionIdWhiteSpace = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", " ")]; // ClientID and ClientTransactionID values negative number - internal List ParamClientIDNegative = new() { new CheckProtocolParameter("ClientID", "-12345"), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)) }; - internal List ParamTransactionIdNegative = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", "-67890") }; + internal List ParamClientIDNegative = [new CheckProtocolParameter("ClientID", "-12345"), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture))]; + internal List ParamTransactionIdNegative = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", "-67890")]; // ClientID and ClientTransactionID values non-numeric string - internal List ParamClientIDNonNumeric = new() { new CheckProtocolParameter("ClientID", "NASDAQ"), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)) }; - internal List ParamTransactionIdString = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", "qweqwe") }; + internal List ParamClientIDNonNumeric = [new CheckProtocolParameter("ClientID", "NASDAQ"), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture))]; + internal List ParamTransactionIdString = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", "qweqwe")]; // Set Connected True and False - internal List ParamConnectedTrue = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Connected", "True") }; - internal List ParamConnectedFalse = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Connected", "False") }; + internal List ParamConnectedTrue = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), + new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), + new CheckProtocolParameter("Connected", "True")]; + internal List ParamConnectedTrueReordered = [new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), + new CheckProtocolParameter("Connected", "True"), + new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture))]; + internal List ParamConnectedFalse = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Connected", "False")]; // Set Telescope.Tracking True and False - internal List ParamTrackingTrue = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Tracking", "True") }; - internal List ParamTrackingFalse = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Tracking", "False") }; + internal List ParamTrackingTrue = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Tracking", "True")]; + internal List ParamTrackingFalse = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Tracking", "False")]; #endregion @@ -250,17 +255,32 @@ public async Task TestAlpacaProtocol() { LogLine($"OK messages are suppressed, they can be enabled through the Alpaca and COM settings page."); LogBlankLine(); - LogLine($"Connecting to device..."); } + // Set Connected true to start the test + LogLine($"Connecting to device..."); await CallApi("True", "Connected", HttpMethod.Put, ParamConnectedTrue, HttpStatusCode200); + LogBlankLine(); + LogLine($"Successfully connected to device, disconnecting in order to test that connection using a different PUT parameter order is successful..."); + + // Disconnect from the device so we can try to connect with Put parameters in a different order + await CallApi("False", "Connected", HttpMethod.Put, ParamConnectedFalse, HttpStatusCode200, true); + LogBlankLine(); + LogLine($"Successfully disconnected from device, re-connecting using re-ordered PUT parameters..."); + + // Set Connected true to start the test + if (settings.AlpacaConfiguration.ProtocolMessageLevel != ProtocolMessageLevel.All) + LogBlankLine(); + await CallApi("True", "Connected", HttpMethod.Put, ParamConnectedTrueReordered, HttpStatusCode200); if (settings.AlpacaConfiguration.ProtocolMessageLevel == ProtocolMessageLevel.All) LogBlankLine(); else { - LogLine($"Successfully connected to device, testing..."); + LogLine($"Successfully connected to device using re-ordered PUT parameters, testing device..."); LogBlankLine(); } + + // Get the interface version number int interfaceVersion = await GetInterfaceVersion(); LogLine($"Device exposes interface version {interfaceVersion}"); @@ -413,9 +433,9 @@ public async Task TestAlpacaProtocol() private async Task TestCommon() { - List ParamConnectedEmpty = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Connected", "") }; - List ParamConnectedNumeric = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Connected", "123456") }; - List ParamConnectedString = new() { new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Connected", "asdqwe") }; + List ParamConnectedEmpty = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Connected", "")]; + List ParamConnectedNumeric = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Connected", "123456")]; + List ParamConnectedString = [new CheckProtocolParameter("ClientID", TEST_CLIENT_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("ClientTransactionID", TEST_TRANSACTION_ID.ToString(CultureInfo.InvariantCulture)), new CheckProtocolParameter("Connected", "asdqwe")]; try { @@ -1906,7 +1926,7 @@ private async Task GetInterfaceVersion() // Add all parameters to the request body as form URL encoded content if (parameters.Count > 0) { - Dictionary formParameters = new(); + Dictionary formParameters = []; foreach (CheckProtocolParameter parameter in parameters) { formParameters.Add(parameter.ParameterName, parameter.ParameterValue); @@ -2238,7 +2258,7 @@ private async Task SendToDevice(string testName, // Add all parameters to the request body as form URL encoded content if (parameters.Count > 0) { - Dictionary formParameters = new(); + Dictionary formParameters = []; foreach (CheckProtocolParameter parameter in parameters) { formParameters.Add(parameter.ParameterName, parameter.ParameterValue);