コード例 #1
0
        public async Task WriteAsync_IsPassedToUnderlyingStream_WhenDisableResponseBuffering(bool flushable)
        {
            var buffer = new byte[] { 1 };

            var memoryStream = new MemoryStream();
            var stream       = new BodyWrapperStream(new DefaultHttpContext(), memoryStream, new MockResponseCompressionProvider(flushable), null, null, null);

            stream.DisableResponseBuffering();
            await stream.WriteAsync(buffer, 0, buffer.Length);

            Assert.Equal(buffer, memoryStream.ToArray());
        }
コード例 #2
0
        public async Task WriteAsync_IsPassedToUnderlyingStream_WhenDisableResponseBuffering(bool flushable)
        {
            var buffer = new byte[] { 1 };

            byte[] written = null;

            var mock = new Mock <Stream>();

            mock.SetupGet(s => s.CanWrite).Returns(true);
            mock.Setup(s => s.WriteAsync(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .Callback <byte[], int, int, CancellationToken>((b, o, c, t) =>
            {
                written = new ArraySegment <byte>(b, 0, c).ToArray();
            })
            .Returns(Task.FromResult(0));

            var stream = new BodyWrapperStream(new DefaultHttpContext(), mock.Object, new MockResponseCompressionProvider(flushable), null, null);

            stream.DisableResponseBuffering();
            await stream.WriteAsync(buffer, 0, buffer.Length);

            Assert.Equal(buffer, written);
        }