public void ClientDecorator_SendMessage_ShouldCallGetStreamOnce() { var message = "Test message"; using (var testStream = new MemoryStream()) { _client.Setup(c => c.GetStream()).Returns(testStream); var clientDecorator = new ClientDecorator(_client.Object); clientDecorator.SendMessage(message); } _client.Verify(c => c.GetStream(), Times.Exactly(1)); }
public void ClientDecorator_SendMessage_ShouldWriteTheMessageToStream() { var message = "Test message"; byte[] responseBytes; using (var testStream = new MemoryStream()) { _client.Setup(c => c.GetStream()).Returns(testStream); var clientDecorator = new ClientDecorator(_client.Object); clientDecorator.SendMessage(message); responseBytes = new byte[testStream.Position]; testStream.Position = 0; testStream.Read(responseBytes); } var responseMessage = Encoding.UTF8.GetString(responseBytes); Assert.That(responseMessage, Does.Contain(message)); }