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 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 void GetAcceptCharsetHeaderValues_ReadsHeaderAndParsesValues() { // Arrange const string expectedValue = "expected"; var formatter = new OverrideEncodingFormatter(encoding: null); var context = new DefaultHttpContext(); context.Request.Headers[HeaderNames.AcceptCharset] = expectedValue; var writerContext = new OutputFormatterWriteContext( context, new TestHttpResponseStreamWriterFactory().CreateWriter, objectType: null, @object: null); // Act var result = TextOutputFormatter.GetAcceptCharsetHeaderValues(writerContext); //Assert Assert.Equal(expectedValue, Assert.Single(result).Value.Value); }
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); }