public async Task WritingTextThatRequiresMultipleSegmentsWorks(Encoding encoding) { // Need to change the StreamPipeWriter with a capped MemoryPool var memoryPool = new TestMemoryPool(maxBufferSize: 16); var outputStream = new MemoryStream(); var streamPipeWriter = new StreamPipeWriter(outputStream, minimumSegmentSize: 0, memoryPool); ProtoContext context = new DefaultProtoContext(); context.Response.BodyWriter = streamPipeWriter; var inputString = "昨日すき焼きを食べました"; var expected = encoding.GetBytes(inputString); await context.Response.WriteAsync(inputString, encoding); outputStream.Position = 0; var actual = new byte[expected.Length]; var length = outputStream.Read(actual); var res1 = encoding.GetString(actual); var res2 = encoding.GetString(expected); Assert.Equal(expected.Length, length); Assert.Equal(expected, actual); streamPipeWriter.Complete(); }
public void CompleteAfterDisposeDoesNotThrowIfUnflushedData() { var streamPipeWriter = new StreamPipeWriter(new MemoryStream()); streamPipeWriter.Write(new byte[1]); streamPipeWriter.Dispose(); streamPipeWriter.Complete(); }