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); HttpContext context = new DefaultHttpContext(); context.Response.BodyPipe = 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(); }
protected PipeTest(int pauseWriterThreshold = MaximumSizeHigh, int resumeWriterThreshold = MaximumSizeLow) { _pool = new TestMemoryPool(); Pipe = new Pipe( new PipeOptions( _pool, pauseWriterThreshold: pauseWriterThreshold, resumeWriterThreshold: resumeWriterThreshold )); }
protected PipeTest(int pauseWriterThreshold = MaximumSizeHigh, int resumeWriterThreshold = MaximumSizeLow) { _pool = new TestMemoryPool(); Pipe = new Pipe( new PipeOptions( _pool, pauseWriterThreshold: pauseWriterThreshold, resumeWriterThreshold: resumeWriterThreshold, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline )); }