public void WriteResponseContentHeaders_NoSelectedContentType_SetsOutputFormatterContext() { // Arrange var testFormatter = new DoesNotSetContext(); var testContentType = MediaTypeHeaderValue.Parse("application/doesNotSetContext"); var formatterContext = new OutputFormatterContext(); var mockHttpContext = new Mock <HttpContext>(); var httpRequest = new DefaultHttpContext().Request; mockHttpContext.SetupGet(o => o.Request).Returns(httpRequest); mockHttpContext.SetupProperty(o => o.Response.ContentType); formatterContext.HttpContext = mockHttpContext.Object; // Act testFormatter.WriteResponseHeaders(formatterContext); // Assert Assert.Equal(Encoding.Unicode.WebName, formatterContext.SelectedEncoding.WebName); Assert.Equal(Encoding.Unicode, formatterContext.SelectedEncoding); Assert.Equal("application/doesNotSetContext; charset=" + Encoding.Unicode.WebName, formatterContext.SelectedContentType.ToString()); }
public void WriteResponseContentHeaders_NoSelectedContentType_SetsOutputFormatterContext() { // Arrange var testFormatter = new DoesNotSetContext(); var testContentType = MediaTypeHeaderValue.Parse("application/doesNotSetContext"); var formatterContext = new OutputFormatterContext(); var mockHttpContext = new Mock <HttpContext>(); mockHttpContext.SetupGet(o => o.Request.AcceptCharset) .Returns(string.Empty); mockHttpContext.SetupProperty(o => o.Response.ContentType); var actionContext = new ActionContext(mockHttpContext.Object, new RouteData(), new ActionDescriptor()); formatterContext.ActionContext = actionContext; // Act testFormatter.WriteResponseHeaders(formatterContext); // Assert Assert.Equal(Encodings.UTF16EncodingLittleEndian.WebName, formatterContext.SelectedEncoding.WebName); Assert.Equal(Encodings.UTF16EncodingLittleEndian, formatterContext.SelectedEncoding); Assert.Equal("application/doesNotSetContext;charset=" + Encodings.UTF16EncodingLittleEndian.WebName, formatterContext.SelectedContentType.RawValue); }
public void WriteResponseContentHeaders_NoSelectedContentType_SetsOutputFormatterContext() { // Arrange var testFormatter = new DoesNotSetContext(); var testContentType = MediaTypeHeaderValue.Parse("application/doesNotSetContext"); var formatterContext = new OutputFormatterContext(); var mockHttpContext = new Mock<HttpContext>(); var httpRequest = new DefaultHttpContext().Request; mockHttpContext.SetupGet(o => o.Request).Returns(httpRequest); mockHttpContext.SetupProperty(o => o.Response.ContentType); formatterContext.HttpContext = mockHttpContext.Object; // Act testFormatter.WriteResponseHeaders(formatterContext); // Assert Assert.Equal(Encodings.UTF16EncodingLittleEndian.WebName, formatterContext.SelectedEncoding.WebName); Assert.Equal(Encodings.UTF16EncodingLittleEndian, formatterContext.SelectedEncoding); Assert.Equal("application/doesNotSetContext; charset=" + Encodings.UTF16EncodingLittleEndian.WebName, formatterContext.SelectedContentType.ToString()); }
public void WriteResponseContentHeaders_NoSelectedContentType_SetsOutputFormatterContext() { // Arrange var testFormatter = new DoesNotSetContext(); var testContentType = MediaTypeHeaderValue.Parse("application/doesNotSetContext"); var formatterContext = new OutputFormatterContext(); var mockHttpContext = new Mock<HttpContext>(); mockHttpContext.SetupGet(o => o.Request.AcceptCharset) .Returns(string.Empty); mockHttpContext.SetupProperty(o => o.Response.ContentType); var actionContext = new ActionContext(mockHttpContext.Object, new RouteData(), new ActionDescriptor()); formatterContext.ActionContext = actionContext; // Act testFormatter.WriteResponseContentHeaders(formatterContext); // Assert Assert.Equal(Encodings.UTF16EncodingLittleEndian.WebName, formatterContext.SelectedEncoding.WebName); Assert.Equal(Encodings.UTF16EncodingLittleEndian, formatterContext.SelectedEncoding); Assert.Equal("application/doesNotSetContext;charset=" + Encodings.UTF16EncodingLittleEndian.WebName, formatterContext.SelectedContentType.RawValue); }