public void TcpClientConnection_ConnectAsyncThrowsObjectDisposedExceptionWhenAttemptingToConnectUsingConnectionThatWasClosed() { // Arrange using (new LocalTcpListener()) { var connection = new TcpClientConnection(); connection.Close(); // Act & Assert Assert.ThrowsAsync <ObjectDisposedException>(() => connection.ConnectAsync(LocalTcpListener.Host, LocalTcpListener.Port, 5000)); } }
public void TcpClientConnection_ConnectSuccessfullyAndClose() { // Arrange using (new LocalTcpListener()) { var connection = new TcpClientConnection(); // Act (Connect) connection.Connect(LocalTcpListener.Host, LocalTcpListener.Port, 5000); // Assert Assert.IsTrue(connection.Connected); var stream = connection.GetStream(); Assert.IsNotNull(stream); Assert.IsInstanceOf <NetworkStream>(stream); // Act (Close) connection.Close(); // Assert Assert.IsFalse(connection.Connected); Assert.IsNull(connection.GetStream()); } }