示例#1
0
        public void FahClientConnection_DisposeClosesInnerTcpConnection()
        {
            // Arrange
            var tcpConnectionFactory = new MockTcpConnectionFactory();

            using (var connection = new FahClientConnection("foo", 2000, tcpConnectionFactory))
            {
                // Act (Open)
                connection.Open();
                // Assert
                Assert.IsTrue(tcpConnectionFactory.TcpConnection.Connected);
            }
            // Assert
            Assert.IsFalse(tcpConnectionFactory.TcpConnection.Connected);
        }
        public void FahClientCommand_ExecuteWritesNullCommandTextToConnection()
        {
            // Arrange
            var tcpConnectionFactory = new MockTcpConnectionFactory();

            using (var connection = new FahClientConnection("foo", 2000, tcpConnectionFactory))
            {
                connection.Open();
                var command = new FahClientCommand(connection, null);
                // Act
                int bytesWritten = command.Execute();
                // Assert
                Assert.AreEqual(0, bytesWritten);
                var memoryStream = (MemoryStream)tcpConnectionFactory.TcpConnection.GetStream();
                Assert.AreEqual("", Encoding.ASCII.GetString(memoryStream.ToArray()));
            }
        }
        public async Task FahClientCommand_ExecuteAsyncWritesCommandTextToConnection()
        {
            // Arrange
            var tcpConnectionFactory = new MockTcpConnectionFactory();

            using (var connection = new FahClientConnection("foo", 2000, tcpConnectionFactory))
            {
                connection.Open();
                var command = new FahClientCommand(connection, "command text");
                // Act
                int bytesWritten = await command.ExecuteAsync();

                // Assert
                Assert.AreEqual(13, bytesWritten);
                var memoryStream = (MemoryStream)tcpConnectionFactory.TcpConnection.GetStream();
                Assert.AreEqual("command text\n", Encoding.ASCII.GetString(memoryStream.ToArray()));
            }
        }