private static byte[] GenerateMessageChunk(int messageSize) { var buffer = Enumerable.Range(0, messageSize).Select(i => i % byte.MaxValue).Select(i => (byte)i).ToArray(); var stream = new MemoryStream(); var writer = new ChunkWriter(stream); writer.OpenChunk(); writer.Write(buffer, 0, buffer.Length); writer.CloseChunk(); // Append end of message marker writer.OpenChunk(); writer.CloseChunk(); writer.Flush(); writer.Send(); return(stream.ToArray()); }
public async void ShouldResetCapacityWhenAboveMaxBufferSizeAfterEachSendAsync() { var buffer = new byte[1536]; var stream = new MemoryStream(); var logger = new Mock <ILogger>(); var writer = new ChunkWriter(stream, 512, 1024, logger.Object); writer.OpenChunk(); writer.Write(buffer, 0, buffer.Length); writer.CloseChunk(); await writer.SendAsync(); writer.OpenChunk(); writer.Write(buffer, 0, buffer.Length); writer.CloseChunk(); await writer.SendAsync(); logger.Verify(l => l.Info(It.IsRegex("^Shrinking write buffers to the"), It.IsAny <object[]>()), Times.Exactly(2)); }
public async void ShouldCloseTheChunkWithCorrectSize(int chunkSize) { var buffer = Enumerable.Range(0, chunkSize).Select(i => i % byte.MaxValue).Select(i => (byte)i).ToArray(); var stream = new MemoryStream(); var writer = new ChunkWriter(stream); // Write data writer.OpenChunk(); writer.Write(buffer, 0, buffer.Length); writer.CloseChunk(); // End Of Message Marker writer.OpenChunk(); writer.CloseChunk(); // Write To Underlying Stream writer.Send(); var constructed = await ConstructMessage(stream.ToArray()); constructed.Should().HaveCount(chunkSize); constructed.Should().Equal(buffer); }