public async Task DisablesResponseBuffering_IfBufferingFeatureAvailable() { // Arrange var expectedContentType = "text/foo; charset=us-ascii"; var buffer = new byte[] { 1, 2, 3, 4, 5 }; var httpContext = GetHttpContext(); var bufferingFeature = new TestBufferingFeature(); httpContext.Features.Set <IHttpBufferingFeature>(bufferingFeature); var outStream = new MemoryStream(); httpContext.Response.Body = outStream; var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var result = new FileContentResult(buffer, MediaTypeHeaderValue.Parse(expectedContentType)); // Act await result.ExecuteResultAsync(context); // Assert Assert.Equal(buffer, outStream.ToArray()); Assert.Equal(expectedContentType, httpContext.Response.ContentType); Assert.True(bufferingFeature.DisableResponseBufferingInvoked); }
public async Task WriteFileAsync_CopiesBuffer_ToOutputStream() { // Arrange var buffer = new byte[] { 1, 2, 3, 4, 5 }; var httpContext = GetHttpContext(); var outStream = new MemoryStream(); httpContext.Response.Body = outStream; var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var result = new FileContentResult(buffer, "text/plain"); // Act await result.ExecuteResultAsync(context); // Assert Assert.Equal(buffer, outStream.ToArray()); }
public async Task WriteFileAsync_CopiesBuffer_ToOutputStream() { // Arrange var buffer = new byte[] { 1, 2, 3, 4, 5 }; var httpContext = GetHttpContext(); var outStream = new MemoryStream(); httpContext.Response.Body = outStream; var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var result = new FileContentResult(buffer, "text/plain"); // Act await result.ExecuteResultAsync(context); // Assert Assert.Equal(buffer, outStream.ToArray()); }
public async Task ExecuteResultAsync_SetsSuppliedContentTypeAndEncoding() { // Arrange var expectedContentType = "text/foo; charset=us-ascii"; var buffer = new byte[] { 1, 2, 3, 4, 5 }; var httpContext = GetHttpContext(); var outStream = new MemoryStream(); httpContext.Response.Body = outStream; var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var result = new FileContentResult(buffer, MediaTypeHeaderValue.Parse(expectedContentType)); // Act await result.ExecuteResultAsync(context); // Assert Assert.Equal(buffer, outStream.ToArray()); Assert.Equal(expectedContentType, httpContext.Response.ContentType); }
public async Task ExecuteResultAsync_SetsSuppliedContentTypeAndEncoding() { // Arrange var expectedContentType = "text/foo; charset=us-ascii"; var buffer = new byte[] { 1, 2, 3, 4, 5 }; var httpContext = GetHttpContext(); var outStream = new MemoryStream(); httpContext.Response.Body = outStream; var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var result = new FileContentResult(buffer, MediaTypeHeaderValue.Parse(expectedContentType)); // Act await result.ExecuteResultAsync(context); // Assert Assert.Equal(buffer, outStream.ToArray()); Assert.Equal(expectedContentType, httpContext.Response.ContentType); }
public async Task DisablesResponseBuffering_IfBufferingFeatureAvailable() { // Arrange var expectedContentType = "text/foo; charset=us-ascii"; var buffer = new byte[] { 1, 2, 3, 4, 5 }; var httpContext = GetHttpContext(); var bufferingFeature = new TestBufferingFeature(); httpContext.Features.Set<IHttpBufferingFeature>(bufferingFeature); var outStream = new MemoryStream(); httpContext.Response.Body = outStream; var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var result = new FileContentResult(buffer, MediaTypeHeaderValue.Parse(expectedContentType)); // Act await result.ExecuteResultAsync(context); // Assert Assert.Equal(buffer, outStream.ToArray()); Assert.Equal(expectedContentType, httpContext.Response.ContentType); Assert.True(bufferingFeature.DisableResponseBufferingInvoked); }