public void FahClientConnection_TcpConnectionReturnsNullAfterConnectionIsOpenedAndClosed() { // Arrange using (var connection = new FahClientConnection("foo", 2000, new MockTcpConnectionFactory())) { connection.Open(); Assert.IsNotNull(connection.TcpConnection); connection.Close(); // Act & Assert Assert.IsNull(connection.TcpConnection); } }
public void FahClientConnection_OpenSuccessfullyAndCloseMultipleTimes() { // Arrange using (var connection = new FahClientConnection("foo", 2000, new MockTcpConnectionFactory())) { // Act (Open) connection.Open(); // Act (Close) foreach (var _ in Enumerable.Range(0, 3)) { connection.Close(); } } }
public void FahClientConnection_OpenSuccessfullyAndClose() { // Arrange using (var connection = new FahClientConnection("foo", 2000, new MockTcpConnectionFactory())) { // Act (Open) connection.Open(); // Assert Assert.IsTrue(connection.Connected); // Act (Close) connection.Close(); // Assert Assert.IsFalse(connection.Connected); } }
public void FahClientConnection_TcpConnectionReturnsDifferentInstanceEachTimeConnectionIsOpened() { // Arrange using (var connection = new FahClientConnection("foo", 2000, new MockTcpConnectionFactory())) { connection.Open(); // Act var tcpConnection1 = connection.TcpConnection; // close and open again connection.Close(); connection.Open(); // Act var tcpConnection2 = connection.TcpConnection; // Assert Assert.AreNotSame(tcpConnection1, tcpConnection2); } }
public void FahClientConnection_ReopenConnectionThatWasPreviouslyOpenedAndClosed() { // Arrange using (var connection = new FahClientConnection("foo", 2000, new MockTcpConnectionFactory())) { // Act (Open) connection.Open(); // Assert Assert.IsTrue(connection.Connected); // Act (Close) connection.Close(); // Assert Assert.IsFalse(connection.Connected); // Act (Open Again) connection.Open(); // Assert Assert.IsTrue(connection.Connected); } }
private static void CloseConnectionAfter(int millisecondsDelay, FahClientConnection connection) { Task.Delay(millisecondsDelay).ContinueWith(t => connection.Close()); }