public void WriteShouldSplitByteArrayIntoPacketsAndSendToEndpoint() { // Arrange _producer.Setup(x => x.MaximumMessageSize).Returns(10); var stream = new MessageBusWriteStream(_producer.Object, "TestEndpoint", "TestSequence", _mockConfigurtaion.Object); var byteArray = new byte[20]; for (int i = 0; i < byteArray.Length; i++) { byteArray[i] = Convert.ToByte(i); } var packet1 = new byte[10]; for (int i = 0; i < packet1.Length; i++) { packet1[i] = Convert.ToByte(i); } var packet2 = new byte[10]; for (int i = 0; i < packet2.Length; i++) { packet2[i] = Convert.ToByte(i + 10); } // Act stream.Write(byteArray, 0, byteArray.Length); // Assert _producer.Verify(x => x.SendBytes("TestEndpoint", It.Is<byte[]>(y => CompareByteArrays(y, packet1)), It.IsAny<Dictionary<string, string>>())); _producer.Verify(x => x.SendBytes("TestEndpoint", It.Is<byte[]>(y => CompareByteArrays(y, packet2)), It.IsAny<Dictionary<string, string>>())); }
public void WriteShouldIncrementPacketsSentNumberWhenSendingPacketToEndpoint() { // Arrange _producer.Setup(x => x.MaximumMessageSize).Returns(10); var stream = new MessageBusWriteStream(_producer.Object, "TestEndpoint", "TestSequence", _mockConfigurtaion.Object); var byteArray = new byte[20]; // Act stream.Write(byteArray, 0, byteArray.Length); // Assert _producer.Verify(x => x.SendBytes("TestEndpoint", It.IsAny<byte[]>(), It.Is<Dictionary<string, string>>(y => y["PacketNumber"] == "1"))); _producer.Verify(x => x.SendBytes("TestEndpoint", It.IsAny<byte[]>(), It.Is<Dictionary<string, string>>(y => y["PacketNumber"] == "2"))); }