Repository: dotnet/aspnetcore
File: src/Middleware/HttpLogging/test/HttpLoggingMiddlewareTests.cs (C#)

Code before:
        var httpContext = new DefaultHttpContext();
        httpContext.Request.ContentType = "text/plain";
        httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes(expected));

        await middleware.Invoke(httpContext);

        Assert.Contains(TestSink.Writes, w => w.Message.Contains(expected));
    }

    [Theory]
    [MemberData(nameof(BodyData))]
    public async Task RequestBodyWithStreamCloseWorks(string expected)
    {
        var options = CreateOptionsAccessor();
        options.CurrentValue.LoggingFields = HttpLoggingFields.RequestBody;

        var middleware = CreateMiddleware(
            async c =>
            {
                var arr = new byte[4096];
                var contentLengthBytesLeft = c.Request.Body.Length;

                // (1) The subsequent middleware reads right up to the buffer size (guided by the ContentLength header)
                while (contentLengthBytesLeft > 0)
                {
                    var res = await c.Request.Body.ReadAsync(arr, 0, (int)Math.Min(arr.Length, contentLengthBytesLeft));
                    contentLengthBytesLeft -= res;
                    if (res == 0)
                    {
                        break;
                    }
                }

                // (2) The subsequent middleware closes the request stream after its consumption
                c.Request.Body.Close();
            },
            options);

        var httpContext = new DefaultHttpContext();
        httpContext.Request.ContentType = "text/plain";
        var buffer = Encoding.UTF8.GetBytes(expected);
        httpContext.Request.Body = new MemoryStream(buffer);
        httpContext.Request.ContentLength = buffer.Length;

        await middleware.Invoke(httpContext);

        Assert.Contains(TestSink.Writes, w => w.Message.Contains(expected));
    }

    [Fact]
    public async Task RequestBodyReadingLimitLongCharactersWorks()

Review comment (suggestion):
nit?
```suggestion
                    var res = await c.Request.Body.ReadAsync(arr, 0, arr.Length);
```

Code after:
        var httpContext = new DefaultHttpContext();
        httpContext.Request.ContentType = "text/plain";
        httpContext.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes(expected));

        await middleware.Invoke(httpContext);

        Assert.Contains(TestSink.Writes, w => w.Message.Contains(expected));
    }

    [Theory]
    [MemberData(nameof(BodyData))]
    public async Task RequestBodyWithStreamCloseWorks(string expected)
    {
        var options = CreateOptionsAccessor();
        options.CurrentValue.LoggingFields = HttpLoggingFields.RequestBody;

        var middleware = CreateMiddleware(
            async c =>
            {
                var arr = new byte[4096];
                var contentLengthBytesLeft = c.Request.Body.Length;

                // (1) The subsequent middleware reads right up to the buffer size (guided by the ContentLength header)
                while (contentLengthBytesLeft > 0)
                {
                    var res = await c.Request.Body.ReadAsync(arr, 0, arr.Length);
                    contentLengthBytesLeft -= res;
                    if (res == 0)
                    {
                        break;
                    }
                }

                // (2) The subsequent middleware closes the request stream after its consumption
                c.Request.Body.Close();
            },
            options);

        var httpContext = new DefaultHttpContext();
        httpContext.Request.ContentType = "text/plain";
        var buffer = Encoding.UTF8.GetBytes(expected);
        httpContext.Request.Body = new MemoryStream(buffer);
        httpContext.Request.ContentLength = buffer.Length;

        await middleware.Invoke(httpContext);

        Assert.Contains(TestSink.Writes, w => w.Message.Contains(expected));
    }

    [Fact]
    public async Task RequestBodyReadingLimitLongCharactersWorks()