예제 #1
0
    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);
    }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }