Ejemplo n.º 1
0
        public void FahClientReader_ReadAsyncThrowsInvalidOperationExceptionWhenConnectionIsNotConnected()
        {
            // Arrange
            var reader = new FahClientReader(new FahClientConnection("foo", 2000));

            // Act & Assert
            Assert.ThrowsAsync <InvalidOperationException>(() => reader.ReadAsync());
        }
Ejemplo n.º 2
0
 public void FahClientReader_ReadAsyncThrowsInvalidOperationExceptionWhenTcpConnectionIsNoLongerConnected()
 {
     // Arrange
     using (var connection = new MockFahClientConnection())
     {
         connection.Open();
         var reader = new FahClientReader(connection);
         // Act & Assert
         Assert.ThrowsAsync <InvalidOperationException>(() => reader.ReadAsync());
     }
 }
Ejemplo n.º 3
0
        public void FahClientReader_ReadAsyncRethrowsExceptionFromStreamReadAsyncAndClosesTheConnection()
        {
            // Arrange
            Func <TcpConnection> factory = () => new MockTcpConnection(() => new MockStreamThrowsOnRead());

            using (var connection = new FahClientConnection("foo", 2000, new MockTcpConnectionFactory(factory)))
            {
                connection.Open();
                var reader = new FahClientReader(connection);
                // Act & Assert
                Assert.ThrowsAsync <IOException>(() => reader.ReadAsync());
                Assert.IsFalse(connection.Connected);
            }
        }
Ejemplo n.º 4
0
        public void FahClientReader_ReadReadsNoMessageFromConnection()
        {
            // Arrange
            Func <TcpConnection> factory = () => new MockTcpConnection();

            using (var connection = new FahClientConnection("foo", 2000, new MockTcpConnectionFactory(factory)))
            {
                connection.Open();
                var reader = new FahClientReader(connection);
                // Act
                bool result = reader.Read();
                // Assert
                Assert.IsFalse(result);
                Assert.IsNull(reader.Message);
            }
        }
Ejemplo n.º 5
0
        public void FahClientReader_ReadExtractsExistingMessage()
        {
            // Arrange
            Func <TcpConnection> factory = () => new MockTcpConnection();

            using (var connection = new FahClientConnection("foo", 2000, new MockTcpConnectionFactory(factory)))
            {
                connection.Open();
                var reader = new FahClientReader(connection, new FahClientMessageExtractorWithMessage(MessageFromStream));
                reader.BufferSize = 8;
                // Act
                bool result = reader.Read();
                // Assert
                Assert.IsTrue(result);
                var message = reader.Message;
                Assert.AreEqual(FahClientMessageType.Info, message.Identifier.MessageType);
                Assert.AreEqual(MessageFromReader, message.MessageText.ToString());
            }
        }
Ejemplo n.º 6
0
        public async Task FahClientReader_ReadAsyncReadsMessageFromConnection()
        {
            // Arrange
            using (var stream = CreateStreamWithMessage())
            {
                Func <TcpConnection> factory = () => new MockTcpConnection(() => stream);
                using (var connection = new FahClientConnection("foo", 2000, new MockTcpConnectionFactory(factory)))
                {
                    connection.Open();
                    var reader = new FahClientReader(connection);
                    reader.BufferSize = 8;
                    // Act
                    bool result = await reader.ReadAsync();

                    // Assert
                    Assert.IsTrue(result);
                    var message = reader.Message;
                    Assert.AreEqual(FahClientMessageType.Info, message.Identifier.MessageType);
                    Assert.AreEqual(MessageFromReader, message.MessageText.ToString());
                }
            }
        }