Пример #1
0
        public async Task DisablesResponseBuffering_IfBufferingFeatureAvailable()
        {
            // Arrange
            var formatter = new StreamOutputFormatter();

            var expected = Encoding.UTF8.GetBytes("Test data");

            var httpContext = new DefaultHttpContext();
            var body        = new MemoryStream();

            httpContext.Response.Body = body;

            var bufferingFeature = new TestBufferingFeature();

            httpContext.Features.Set <IHttpBufferingFeature>(bufferingFeature);

            var context = new OutputFormatterWriteContext(
                httpContext,
                new TestHttpResponseStreamWriterFactory().CreateWriter,
                typeof(Stream),
                new MemoryStream(expected));

            // Act
            await formatter.WriteAsync(context);

            // Assert
            Assert.Equal(expected, body.ToArray());
            Assert.True(bufferingFeature.DisableResponseBufferingInvoked);
        }
Пример #2
0
        public async Task DisablesResponseBuffering_IfBufferingFeatureAvailable()
        {
            // Arrange
            var expected    = Encoding.UTF8.GetBytes("Test data");
            var formatter   = new StreamOutputFormatter();
            var httpContext = new DefaultHttpContext();
            var ms          = new MemoryStream();

            httpContext.Response.Body = ms;
            var bufferingFeature = new TestBufferingFeature();

            httpContext.Features.Set <IHttpBufferingFeature>(bufferingFeature);
            var context = new OutputFormatterContext();

            context.Object      = new MemoryStream(expected);
            context.HttpContext = httpContext;

            // Act
            await formatter.WriteAsync(context);

            // Assert
            Assert.Equal(expected, ms.ToArray());
            Assert.True(bufferingFeature.DisableResponseBufferingInvoked);
        }
Пример #3
0
        public async Task DisablesResponseBuffering_IfBufferingFeatureAvailable()
        {
            // Arrange
            var expected = Encoding.UTF8.GetBytes("Test data");
            var formatter = new StreamOutputFormatter();
            var httpContext = new DefaultHttpContext();
            var ms = new MemoryStream();
            httpContext.Response.Body = ms;
            var bufferingFeature = new TestBufferingFeature();
            httpContext.Features.Set<IHttpBufferingFeature>(bufferingFeature);
            var context = new OutputFormatterContext();
            context.Object = new MemoryStream(expected);
            context.HttpContext = httpContext;

            // Act
            await formatter.WriteAsync(context);

            // Assert
            Assert.Equal(expected, ms.ToArray());
            Assert.True(bufferingFeature.DisableResponseBufferingInvoked);
        }
Пример #4
0
        public async Task DisablesResponseBuffering_IfBufferingFeatureAvailable()
        {
            // Arrange
            var formatter = new StreamOutputFormatter();

            var expected = Encoding.UTF8.GetBytes("Test data");

            var httpContext = new DefaultHttpContext();
            var body = new MemoryStream();
            httpContext.Response.Body = body;

            var bufferingFeature = new TestBufferingFeature();
            httpContext.Features.Set<IHttpBufferingFeature>(bufferingFeature);

            var context = new OutputFormatterWriteContext(
                httpContext,
                new TestHttpResponseStreamWriterFactory().CreateWriter,
                typeof(Stream),
                new MemoryStream(expected));

            // Act
            await formatter.WriteAsync(context);

            // Assert
            Assert.Equal(expected, body.ToArray());
            Assert.True(bufferingFeature.DisableResponseBufferingInvoked);
        }