public async Task WriteAsync_ReturnsNotAcceptable_IfSelectCharacterEncodingReturnsNull() { // Arrange var formatter = new OverrideEncodingFormatter(encoding: null); var testContentType = new StringSegment("text/json"); formatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/json")); var context = new OutputFormatterWriteContext( new DefaultHttpContext() { RequestServices = new ServiceCollection().BuildServiceProvider() }, new TestHttpResponseStreamWriterFactory().CreateWriter, objectType: null, @object: null) { ContentType = testContentType, }; // Act await formatter.WriteAsync(context); // Assert Assert.Equal(StatusCodes.Status406NotAcceptable, context.HttpContext.Response.StatusCode); }
public void WriteResponse_OverridesCharset_IfDifferentFromContentTypeCharset( string contentType, string expectedContentType) { // Arrange var formatter = new OverrideEncodingFormatter(Encoding.UTF32); var formatterContext = new OutputFormatterWriteContext( new DefaultHttpContext(), new TestHttpResponseStreamWriterFactory().CreateWriter, objectType: null, @object: null) { ContentType = new StringSegment(contentType), }; // Act formatter.WriteAsync(formatterContext); // Assert Assert.Equal(new StringSegment(expectedContentType), formatterContext.ContentType); }
public async Task WriteAsync_ReturnsNotAcceptable_IfSelectCharacterEncodingReturnsNull() { // Arrange var formatter = new OverrideEncodingFormatter(encoding: null); var testContentType = new StringSegment("text/json"); formatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/json")); var context = new OutputFormatterWriteContext( new DefaultHttpContext(), new TestHttpResponseStreamWriterFactory().CreateWriter, objectType: null, @object: null) { ContentType = testContentType, }; // Act await formatter.WriteAsync(context); // Assert Assert.Equal(StatusCodes.Status406NotAcceptable, context.HttpContext.Response.StatusCode); }