public void WriteResponse_GetMediaTypeWithCharsetReturnsMediaTypeFromCache_IfEncodingIsUtf8() { // Arrange var formatter = new TestOutputFormatter(); var formatterContext = new OutputFormatterWriteContext( new DefaultHttpContext(), new TestHttpResponseStreamWriterFactory().CreateWriter, objectType: null, @object: null) { ContentType = new StringSegment("application/json"), }; formatter.SupportedMediaTypes.Add("application/json"); formatter.SupportedEncodings.Add(Encoding.UTF8); // Act formatter.WriteAsync(formatterContext); var firstContentType = formatterContext.ContentType; formatterContext.ContentType = new StringSegment("application/json"); formatter.WriteAsync(formatterContext); var secondContentType = formatterContext.ContentType; // Assert Assert.Same(firstContentType.Buffer, secondContentType.Buffer); }
public void WriteResponse_GetMediaTypeWithCharsetReplacesCharset_IfDifferentThanEncoding() { // Arrange var formatter = new TestOutputFormatter(); var formatterContext = new OutputFormatterWriteContext( new DefaultHttpContext(), new TestHttpResponseStreamWriterFactory().CreateWriter, objectType: null, @object: null) { ContentType = new StringSegment("application/json; charset=utf-7"), }; formatter.SupportedMediaTypes.Add("application/json"); formatter.SupportedEncodings.Add(Encoding.UTF8); // Act formatter.WriteAsync(formatterContext); // Assert Assert.Equal(new StringSegment("application/json; charset=utf-8"), formatterContext.ContentType); }
public void WriteResponse_GetMediaTypeWithCharsetReturnsSameString_IfCharsetEqualToEncoding() { // Arrange var formatter = new TestOutputFormatter(); var contentType = "application/json; charset=utf-16"; var formatterContext = new OutputFormatterWriteContext( new DefaultHttpContext(), new TestHttpResponseStreamWriterFactory().CreateWriter, objectType: null, @object: null) { ContentType = new StringSegment(contentType), }; formatter.SupportedMediaTypes.Add("application/json"); formatter.SupportedEncodings.Add(Encoding.Unicode); // Act formatter.WriteAsync(formatterContext); // Assert Assert.Same(contentType, formatterContext.ContentType.Buffer); }