public void ReportsUnavailability() { Connector.Port = Port + 1; Connector.Connect(); WaitForErrors(1); Assert.Equal(1, ConnectionErrors.Count); SocketErrorException ex = (SocketErrorException)ConnectionErrors[0]; Assert.Equal(SocketError.ConnectionRefused, ex.SocketError); Assert.Throws <InvalidOperationException>(() => WaitForConnections(1)); }
public void ReportsCancellation() { Connector.Address = IPAddress.Parse("8.8.8.8"); Connector.Port = Port + 1; Connector.Connect(); Connector.StopConnecting(); WaitForErrors(1); Assert.Equal(1, ConnectionErrors.Count); SocketErrorException ex = (SocketErrorException)ConnectionErrors[0]; Assert.Equal(SocketError.OperationAborted, ex.SocketError); Assert.Throws <InvalidOperationException>(() => WaitForConnections(1)); }
public void ReportsProblemViaTask() { Connector.Port = Port + 1; Task <Socket> task = connector.ConnectAsync(); AggregateException ex = Assert.Throws <AggregateException>(() => task.Wait(TimeSpan.FromSeconds(2))); Assert.IsType <SocketErrorException>(ex.InnerException); WaitForErrors(1); Assert.Equal(1, ConnectionErrors.Count); SocketErrorException ex2 = (SocketErrorException)ConnectionErrors[0]; Assert.Equal(SocketError.ConnectionRefused, ex2.SocketError); Assert.Throws <InvalidOperationException>(() => WaitForConnections(1)); }
public void CancelsTask() { Connector.Address = IPAddress.Parse("8.8.8.8"); Connector.Port = Port + 1; Task <Socket> task = connector.ConnectAsync(); Connector.StopConnecting(); AggregateException ex = Assert.Throws <AggregateException>(() => task.Wait(TimeSpan.FromSeconds(2))); Assert.IsType <TaskCanceledException>(ex.InnerException); WaitForErrors(1); Assert.Equal(1, ConnectionErrors.Count); SocketErrorException ex2 = (SocketErrorException)ConnectionErrors[0]; Assert.Equal(SocketError.OperationAborted, ex2.SocketError); Assert.Throws <InvalidOperationException>(() => WaitForConnections(1)); }