Repository: dotnet/aspnetcore
File: src/Middleware/ResponseCompression/test/ResponseCompressionMiddlewareTest.cs (C#)

Code before:
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.TestHost;
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Microsoft.Net.Http.Headers;

namespace Microsoft.AspNetCore.ResponseCompression.Tests;

public class ResponseCompressionMiddlewareTest
{
    private const string TextPlain = "text/plain";

    public static IEnumerable<object[]> SupportedEncodings =>
        TestData.Select(x => new object[] { x.EncodingName });

    public static IEnumerable<object[]> SupportedEncodingsWithBodyLength =>
        TestData.Select(x => new object[] { x.EncodingName, x.ExpectedBodyLength });

    private static IEnumerable<EncodingTestData> TestData
    {
        get
        {
            yield return new EncodingTestData("zstd", expectedBodyLength: 27);
            yield return new EncodingTestData("gzip", expectedBodyLength: 29);
            yield return new EncodingTestData("br", expectedBodyLength: 21);
        }
    }

    [Fact]
    public void Options_HttpsDisabledByDefault()
    {
        var options = new ResponseCompressionOptions();

        Assert.False(options.EnableForHttps);
    }

    [Fact]
    public async Task Request_NoAcceptEncoding_Uncompressed()
    {
        var (response, logMessages) = await InvokeMiddleware(100, requestAcceptEncodings: null, responseType: TextPlain);

        CheckResponseNotCompressed(response, expectedBodyLength: 100, sendVaryHeader: false);
        AssertLog(logMessages.Single(), LogLevel.Debug, "No response compression available, the Accept-Encoding header is missing or invalid.");
    }

    [Fact]
    public async Task Request_AcceptGzipDeflate_CompressedGzip()
    {

Review comment (suggestion):
We should move off of hardcoding the compressed size in tests 😆

Don't need to do it in this PR though since it's not caused by the PR.

Code after:
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.TestHost;
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Microsoft.Net.Http.Headers;

namespace Microsoft.AspNetCore.ResponseCompression.Tests;

public class ResponseCompressionMiddlewareTest
{
    private const string TextPlain = "text/plain";

    private static readonly string[] _supportedEncodings =
        [
            "gzip",
            "br",
            "zstd"
        ];

    public static IEnumerable<object[]> SupportedEncodings =>
        _supportedEncodings.Select(encoding => new[] { encoding });

    [Fact]
    public void Options_HttpsDisabledByDefault()
    {
        var options = new ResponseCompressionOptions();

        Assert.False(options.EnableForHttps);
    }

    [Fact]
    public async Task Request_NoAcceptEncoding_Uncompressed()
    {
        var (response, logMessages) = await InvokeMiddleware(100, requestAcceptEncodings: null, responseType: TextPlain);

        CheckResponseNotCompressed(response, expectedBodyLength: 100, sendVaryHeader: false);
        AssertLog(logMessages.Single(), LogLevel.Debug, "No response compression available, the Accept-Encoding header is missing or invalid.");
    }

    [Fact]
    public async Task Request_AcceptGzipDeflate_CompressedGzip()
    {
        var (response, logMessages) = await InvokeMiddleware(100, requestAcceptEncodings: new[] { "gzip", "deflate" }, responseType: TextPlain);

        await CheckResponseCompressed(response, "gzip");
        AssertCompressedWithLog(logMessages, "gzip");
    }