public async Task ShouldThrowExceptionIfConnectionTimedOut()
            {
                var client = new TcpSocketClientWithDisposeDetection(
                    new SocketSettings {
                    ConnectionTimeout = TimeSpan.FromSeconds(0)
                });

                var exception = await Record.ExceptionAsync(
                    () => client.ConnectSocketAsync(IPAddress.Parse("127.0.0.1"), 9999));

                exception.Should().BeOfType <OperationCanceledException>(exception.ToString());
                exception.Message.Should().Be("Failed to connect to server 127.0.0.1:9999 within 0ms.");
                client.DisposeCalled.Should().BeTrue();
            }
Beispiel #2
0
            public async Task ShouldThrowExceptionIfConnectionTimedOut()
            {
                using (var tcpServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                {
                    tcpServer.Bind(new IPEndPoint(IPAddress.Loopback, 9999));

                    var client = new TcpSocketClientWithDisposeDetection(
                        new SocketSettings {
                        ConnectionTimeout = TimeSpan.FromSeconds(0)
                    });

                    var exception = await Record.ExceptionAsync(
                        () => client.ConnectSocketAsync(IPAddress.Parse("127.0.0.1"), 9999));

                    exception.Should().BeOfType <OperationCanceledException>(exception.ToString());
                    exception.Message.Should().Be("Failed to connect to server 127.0.0.1:9999 within 0ms.");
                    client.DisposeCalled.Should().BeTrue();
                }
            }
Beispiel #3
0
            public async Task ShouldThrowExceptionIfConnectionTimedOut()
            {
                var client = new TcpSocketClientWithDisposeDetection(
                    new SocketSettings
                {
                    ConnectionTimeout = TimeSpan.FromSeconds(1),
                    HostResolver      = new SystemHostResolver(),
                    EncryptionManager =
                        new EncryptionManager(false, null)
                });

                // ReSharper disable once PossibleNullReferenceException
                // use non-routable IP address to mimic a connect timeout
                // https://stackoverflow.com/questions/100841/artificially-create-a-connection-timeout-error
                var exception = await Record.ExceptionAsync(
                    () => client.ConnectSocketAsync(IPAddress.Parse("192.168.0.0"), 9999));

                exception.Should().NotBeNull();
                exception.Should().BeOfType <OperationCanceledException>(exception.ToString());
                exception.Message.Should().Be("Failed to connect to server 192.168.0.0:9999 within 1000ms.");
                client.DisposeCalled.Should().BeTrue();
            }