public void SetsMaxRequestBodySize()
    {
        // Arrange
        var requestSizeLimitResourceFilter = new RequestSizeLimitFilter(NullLoggerFactory.Instance);

        requestSizeLimitResourceFilter.Bytes = 12345;
        var authorizationFilterContext = CreateAuthorizationFilterContext(new IFilterMetadata[] { requestSizeLimitResourceFilter });

        var httpMaxRequestBodySize = new TestHttpMaxRequestBodySizeFeature();

        authorizationFilterContext.HttpContext.Features.Set <IHttpMaxRequestBodySizeFeature>(httpMaxRequestBodySize);

        // Act
        requestSizeLimitResourceFilter.OnAuthorization(authorizationFilterContext);

        // Assert
        Assert.Equal(12345, httpMaxRequestBodySize.MaxRequestBodySize);
    }
    public void LogsFeatureNotFound()
    {
        // Arrange
        var sink          = new TestSink();
        var loggerFactory = new TestLoggerFactory(sink, enabled: true);

        var requestSizeLimitResourceFilter = new RequestSizeLimitFilter(loggerFactory);

        requestSizeLimitResourceFilter.Bytes = 12345;
        var authorizationFilterContext = CreateAuthorizationFilterContext(new IFilterMetadata[] { requestSizeLimitResourceFilter });

        // Act
        requestSizeLimitResourceFilter.OnAuthorization(authorizationFilterContext);

        // Assert
        var write = Assert.Single(sink.Writes);

        Assert.Equal($"A request body size limit could not be applied. This server does not support the IHttpRequestBodySizeFeature.",
                     write.State.ToString());
    }
    public void LogsMaxRequestBodySizeSet()
    {
        // Arrange
        var sink          = new TestSink();
        var loggerFactory = new TestLoggerFactory(sink, enabled: true);

        var requestSizeLimitResourceFilter = new RequestSizeLimitFilter(loggerFactory);

        requestSizeLimitResourceFilter.Bytes = 12345;
        var authorizationFilterContext = CreateAuthorizationFilterContext(new IFilterMetadata[] { requestSizeLimitResourceFilter });

        var httpMaxRequestBodySize = new TestHttpMaxRequestBodySizeFeature();

        authorizationFilterContext.HttpContext.Features.Set <IHttpMaxRequestBodySizeFeature>(httpMaxRequestBodySize);

        // Act
        requestSizeLimitResourceFilter.OnAuthorization(authorizationFilterContext);

        // Assert
        var write = Assert.Single(sink.Writes);

        Assert.Equal($"The maximum request body size has been set to 12345.", write.State.ToString());
    }
    public void LogsFeatureIsReadOnly()
    {
        // Arrange
        var sink          = new TestSink();
        var loggerFactory = new TestLoggerFactory(sink, enabled: true);

        var requestSizeLimitResourceFilter = new RequestSizeLimitFilter(loggerFactory);

        requestSizeLimitResourceFilter.Bytes = 12345;
        var authorizationFilterContext = CreateAuthorizationFilterContext(new IFilterMetadata[] { requestSizeLimitResourceFilter });

        var httpMaxRequestBodySize = new TestHttpMaxRequestBodySizeFeature();

        httpMaxRequestBodySize.IsReadOnly = true;
        authorizationFilterContext.HttpContext.Features.Set <IHttpMaxRequestBodySizeFeature>(httpMaxRequestBodySize);

        // Act
        requestSizeLimitResourceFilter.OnAuthorization(authorizationFilterContext);

        // Assert
        var write = Assert.Single(sink.Writes);

        Assert.Equal($"A request body size limit could not be applied. The IHttpRequestBodySizeFeature for the server is read-only.", write.State.ToString());
    }