public async Task WriteResponseHeaders_ClonesMediaType() { // Arrange var formatter = new PngImageFormatter(); formatter.SupportedMediaTypes.Clear(); var mediaType = new MediaTypeHeaderValue("image/png"); formatter.SupportedMediaTypes.Add(mediaType); var formatterContext = new OutputFormatterContext(); formatterContext.HttpContext = new DefaultHttpContext(); // Act await formatter.WriteAsync(formatterContext); // Assert Assert.NotSame(mediaType, formatterContext.SelectedContentType); Assert.Null(mediaType.Charset); Assert.Equal("image/png; charset=utf-8", formatterContext.SelectedContentType.ToString()); }
public async Task WriteResponseHeaders_ClonesMediaType() { // Arrange var formatter = new PngImageFormatter(); formatter.SupportedMediaTypes.Clear(); var mediaType = new MediaTypeHeaderValue("image/png"); formatter.SupportedMediaTypes.Add(mediaType); var context = new OutputFormatterWriteContext( new DefaultHttpContext(), new TestHttpResponseStreamWriterFactory().CreateWriter, objectType: null, @object: null); // Act await formatter.WriteAsync(context); // Assert Assert.NotSame(mediaType, context.ContentType); Assert.Null(mediaType.Charset); Assert.Equal("image/png; charset=utf-8", context.ContentType.ToString()); }