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

Code before:
    {
        var (response, logMessages) = await InvokeMiddleware(100, requestAcceptEncodings: new[] { "*" }, responseType: TextPlain);

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

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

        CheckResponseNotCompressed(response, expectedBodyLength: 100, sendVaryHeader: true);
        Assert.Equal(3, logMessages.Count);
        AssertLog(logMessages.First(), LogLevel.Trace, "This request accepts compression.");
        AssertLog(logMessages.Skip(1).First(), LogLevel.Trace, "Response compression is available for this Content-Type.");
        AssertLog(logMessages.Skip(2).First(), LogLevel.Debug, "No matching response compression provider found.");
    }

    [Theory]
    [InlineData(new[] { "identity;q=0.5", "gzip;q=1" }, 29)]
    [InlineData(new[] { "identity;q=0", "gzip;q=0.8" }, 29)]
    [InlineData(new[] { "identity;q=0.5", "gzip" }, 29)]
    public async Task Request_AcceptWithHigherCompressionQuality_Compressed(string[] acceptEncodings, int expectedBodyLength)
    {
        _ = expectedBodyLength; // Parameter kept for test data compatibility
        var (response, logMessages) = await InvokeMiddleware(100, requestAcceptEncodings: acceptEncodings, responseType: TextPlain);

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

    [Theory]
    [InlineData(new[] { "gzip;q=0.5", "identity;q=0.8" }, 100)]
    public async Task Request_AcceptWithhigherIdentityQuality_NotCompressed(string[] acceptEncodings, int expectedBodyLength)
    {
        var (response, logMessages) = await InvokeMiddleware(100, requestAcceptEncodings: acceptEncodings, responseType: TextPlain);

        CheckResponseNotCompressed(response, expectedBodyLength: expectedBodyLength, sendVaryHeader: true);
        Assert.Equal(3, logMessages.Count);
        AssertLog(logMessages.First(), LogLevel.Trace, "This request accepts compression.");
        AssertLog(logMessages.Skip(1).First(), LogLevel.Trace, "Response compression is available for this Content-Type.");
        AssertLog(logMessages.Skip(2).First(), LogLevel.Debug, "No matching response compression provider found.");
    }

    [Fact]
    public async Task Response_UnknownMimeType_NotCompressed()
    {
        var (response, logMessages) = await InvokeMiddleware(100, requestAcceptEncodings: new[] { "gzip" }, responseType: "text/custom");

        CheckResponseNotCompressed(response, expectedBodyLength: 100, sendVaryHeader: false);

Review comment (refactor):
nit: I don't think we care about preserving the test data from past runs for comparison here. Can just remove this param from where it's needed.

Code after:
    {
        var (response, logMessages) = await InvokeMiddleware(100, requestAcceptEncodings: new[] { "*" }, responseType: TextPlain);

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

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

        CheckResponseNotCompressed(response, expectedBodyLength: 100, sendVaryHeader: true);
        Assert.Equal(3, logMessages.Count);
        AssertLog(logMessages.First(), LogLevel.Trace, "This request accepts compression.");
        AssertLog(logMessages.Skip(1).First(), LogLevel.Trace, "Response compression is available for this Content-Type.");
        AssertLog(logMessages.Skip(2).First(), LogLevel.Debug, "No matching response compression provider found.");
    }

    [Theory]
    [InlineData("identity;q=0.5", "gzip;q=1")]
    [InlineData("identity;q=0", "gzip;q=0.8")]
    [InlineData("identity;q=0.5", "gzip")]
    public async Task Request_AcceptWithHigherCompressionQuality_Compressed(string encoding1, string encoding2)
    {
        var (response, logMessages) = await InvokeMiddleware(100, requestAcceptEncodings: new[] { encoding1, encoding2 }, responseType: TextPlain);

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

    [Theory]
    [InlineData("gzip;q=0.5", "identity;q=0.8")]
    public async Task Request_AcceptWithhigherIdentityQuality_NotCompressed(string encoding1, string encoding2)
    {
        var (response, logMessages) = await InvokeMiddleware(100, requestAcceptEncodings: new[] { encoding1, encoding2 }, responseType: TextPlain);

        CheckResponseNotCompressed(response, expectedBodyLength: 100, sendVaryHeader: true);
        Assert.Equal(3, logMessages.Count);
        AssertLog(logMessages.First(), LogLevel.Trace, "This request accepts compression.");
        AssertLog(logMessages.Skip(1).First(), LogLevel.Trace, "Response compression is available for this Content-Type.");
        AssertLog(logMessages.Skip(2).First(), LogLevel.Debug, "No matching response compression provider found.");
    }

    [Fact]
    public async Task Response_UnknownMimeType_NotCompressed()
    {
        var (response, logMessages) = await InvokeMiddleware(100, requestAcceptEncodings: new[] { "gzip" }, responseType: "text/custom");

        CheckResponseNotCompressed(response, expectedBodyLength: 100, sendVaryHeader: false);
        Assert.Equal(2, logMessages.Count);