Repository: dotnet/aspnetcore
File: src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3StreamTests.cs (C#)

Code before:
        await outboundcontrolStream.EndStreamAsync();

        // Check that connection is closed.
        var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
        Http3Api.MultiplexedConnectionContext.ConnectionClosed.Register(() => tcs.TrySetResult());
        await tcs.Task;

        await outboundcontrolStream.ReceiveEndAsync();
    }

    [Theory]
    [InlineData(true)]
    [InlineData(false)]
    public async Task CanHaveBody_ReturnsFalseWithoutRequestBody(bool endstream)
    {
        var headers = new[]
        {
            new KeyValuePair<string, string>(InternalHeaderNames.Method, "GET"),
            new KeyValuePair<string, string>(InternalHeaderNames.Path, "/"),
            new KeyValuePair<string, string>(InternalHeaderNames.Scheme, "http"),
            new KeyValuePair<string, string>(InternalHeaderNames.Authority, "localhost:80"),
        };

        var requestStream = await Http3Api.InitializeConnectionAndStreamsAsync(context =>
        {
            Assert.Equal(!endstream, context.Features.Get<IHttpRequestBodyDetectionFeature>().CanHaveBody);
            context.Response.StatusCode = 200;
            return Task.CompletedTask;
        }, headers, endStream: endstream);

        var responseHeaders = await requestStream.ExpectHeadersAsync();
        Assert.Equal("200", responseHeaders[InternalHeaderNames.Status]);

        await requestStream.ExpectReceiveEndOfStream();
    }

    private async Task WriteOneByteAtATime(PipeReader reader, PipeWriter writer)
    {
        var res = await reader.ReadAsync();
        try
        {
            for (var i = 0; i < res.Buffer.Length; i++)
            {
                var mem = writer.GetMemory();
                mem.Span[0] = res.Buffer.Slice(i).FirstSpan[0];
                writer.Advance(1);
                await writer.FlushAsync();
            }
        }
        finally
        {

Review comment (suggestion):
```suggestion
            Assert.False(endstream, context.Features.Get<IHttpRequestBodyDetectionFeature>().CanHaveBody);
```

Code after:
        await outboundcontrolStream.EndStreamAsync();

        // Check that connection is closed.
        var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
        Http3Api.MultiplexedConnectionContext.ConnectionClosed.Register(() => tcs.TrySetResult());
        await tcs.Task;

        await outboundcontrolStream.ReceiveEndAsync();
    }

    [Theory]
    [InlineData(true)]
    [InlineData(false)]
    public async Task CanHaveBody_ReturnsFalseWithoutRequestBody(bool endstream)
    {
        var headers = new[]
        {
            new KeyValuePair<string, string>(InternalHeaderNames.Method, "GET"),
            new KeyValuePair<string, string>(InternalHeaderNames.Path, "/"),
            new KeyValuePair<string, string>(InternalHeaderNames.Scheme, "http"),
            new KeyValuePair<string, string>(InternalHeaderNames.Authority, "localhost:80"),
        };

        var requestStream = await Http3Api.InitializeConnectionAndStreamsAsync(context =>
        {
            Assert.NotEqual(endstream, context.Features.Get<IHttpRequestBodyDetectionFeature>().CanHaveBody);
            context.Response.StatusCode = 200;
            return Task.CompletedTask;
        }, headers, endStream: endstream);

        var responseHeaders = await requestStream.ExpectHeadersAsync();
        Assert.Equal("200", responseHeaders[InternalHeaderNames.Status]);

        await requestStream.ExpectReceiveEndOfStream();
    }

    private async Task WriteOneByteAtATime(PipeReader reader, PipeWriter writer)
    {
        var res = await reader.ReadAsync();
        try
        {
            for (var i = 0; i < res.Buffer.Length; i++)
            {
                var mem = writer.GetMemory();
                mem.Span[0] = res.Buffer.Slice(i).FirstSpan[0];
                writer.Advance(1);
                await writer.FlushAsync();
            }
        }
        finally
        {