public void TestProtocol() { var connection = new ConnectionParams(); connection.Protocol = null; Assert.Equal("http", connection.Protocol); Assert.Null(connection.GetProtocol()); Assert.Equal("https", connection.GetProtocolWithDefault("https")); connection.Protocol = "https"; Assert.Equal("https", connection.Protocol); }
/// <summary> /// Validates connection parameters. /// This method can be overriden in child classes. /// Throw error if validation failed. /// </summary> /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param> /// <param name="connection">connection parameters to be validated</param> protected void ValidateConnection(string correlationId, ConnectionParams connection) { if (connection == null) { throw new ConfigException(correlationId, "NO_CONNECTION", "Connection parameters are not set is not set"); } // URI usually contains all information var uri = connection.Uri; if (uri != null) { return; } var protocol = connection.GetProtocolWithDefault(_defaultProtocol); if (protocol == null) { throw new ConfigException(correlationId, "NO_PROTOCOL", "Connection protocol is not set"); } if (_supportedProtocols != null && _supportedProtocols.IndexOf(protocol) < 0) { throw new ConfigException(correlationId, "UNSUPPORTED_PROTOCOL", "The protocol " + protocol + " is not supported"); } var host = connection.Host; if (host == null) { throw new ConfigException(correlationId, "NO_HOST", "Connection host is not set"); } var port = connection.GetPortWithDefault(_defaultPort); if (port == 0) { throw new ConfigException(correlationId, "NO_PORT", "Connection port is not set"); } }