public void FahClientReader_ReadAsyncThrowsInvalidOperationExceptionWhenConnectionIsNotConnected() { // Arrange var reader = new FahClientReader(new FahClientConnection("foo", 2000)); // Act & Assert Assert.ThrowsAsync <InvalidOperationException>(() => reader.ReadAsync()); }
public void FahClientReader_ReadAsyncThrowsInvalidOperationExceptionWhenTcpConnectionIsNoLongerConnected() { // Arrange using (var connection = new MockFahClientConnection()) { connection.Open(); var reader = new FahClientReader(connection); // Act & Assert Assert.ThrowsAsync <InvalidOperationException>(() => reader.ReadAsync()); } }
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); } }
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); } }
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()); } }
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()); } } }