public void WhenConstructedWithNullConnectionThenShouldThrowArgumentNullException() { Action act = () => new RabbitMqConnection(ConnectionId.New(), connection: null, pool: null, options: null); act.Should().Throw <ArgumentNullException>() .And.ParamName.Should().Be("connection"); }
public void WhenConstructedWithNullPoolThenShouldThrowArgumentNullException() { var connection = Mock.Of <IConnection>(); Action act = () => new RabbitMqConnection(ConnectionId.New(), connection: connection, pool: null, options: null); act.Should().Throw <ArgumentNullException>() .And.ParamName.Should().Be("pool"); }
public void WhenConstructedWithNullOptionsThenShouldThrowArgumentNullException() { var connection = Mock.Of <IConnection>(); var options = Mock.Of <IOptions <RabbitMqOptions> >(); var logger = Mock.Of <ILogger <RabbitMqConnectionPool> >(); var pool = new RabbitMqConnectionPool(logger, options); Action act = () => new RabbitMqConnection(ConnectionId.New(), connection: connection, pool: pool, options: null); act.Should().Throw <ArgumentNullException>() .And.ParamName.Should().Be("options"); }
private async Task ClientAccepted(Task <TcpClient> prev) { #pragma warning disable 4014 _endpointListener.AcceptTcpClientAsync().ContinueWith(ClientAccepted); #pragma warning restore 4014 if (prev.Exception != null) { _log.Error(prev.Exception, "Failure accepting client on port {port}", _fromPort); return; } TcpClient endpoint = null; try { endpoint = prev.Result; var remoteIPEndpoint = (IPEndPoint)endpoint.Client.RemoteEndPoint; if (!_firewallRules.IsInRange(remoteIPEndpoint)) { _log.Warning("No matching firewall rule. Dropping connection on port {port} from {remoteIPEndpoint}", _fromPort, remoteIPEndpoint.Address); endpoint.IgnoreException(x => x.Close()); } else { _log.Debug("Accepted connection on port {port} from {remoteIPEndpoint}", _fromPort, remoteIPEndpoint.Address); endpoint.NoDelay = true; endpoint.LingerState.Enabled = false; var connectionId = ConnectionId.New(); await _relayFactory .Get() .EnsureRelayConnection(endpoint, connectionId); _log.Debug("ConnectionId: {connectionId}. Pumps started on port {port} from {remoteIPEndpoint}", connectionId, _fromPort, remoteIPEndpoint.Address); } } catch (Exception e) { _log.Error(e, "Unable to establish connection on port {port}", _fromPort); endpoint.IgnoreException(x => x.Close()); } }