Repository: dotnet/aspnetcore
File: src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs (C#)

Code before:
    [Fact]
    public async Task RequestDelegateHandlesFromFormStringArrayParameter()
    {
        var httpContext = CreateHttpContext();
        httpContext.Request.Form = new FormCollection(new Dictionary<string, StringValues>
        {
            ["form"] = new(new[] { "1", "2", "3" })
        });

        var factoryResult = RequestDelegateFactory.Create(
            (HttpContext context, [FromForm(Name = "form")] string[] formValues) =>
        {
            context.Items["form"] = formValues;
        });

        var requestDelegate = factoryResult.RequestDelegate;

        await requestDelegate(httpContext);

        Assert.Equal(new StringValues(new[] { "1", "2", "3" }), httpContext.Items["form"]!);
    }

    [Fact]
    public async Task RequestDelegateCanAwaitValueTasksThatAreNotImmediatelyCompleted()
    {
        var httpContext = CreateHttpContext();

        httpContext.Request.Headers.Referer = "https://example.org";

        var resultFactory = RequestDelegateFactory.Create(
            (HttpContext httpContext, MyAwaitedBindAsyncRecord myAwaitedBindAsyncRecord, MyAwaitedBindAsyncStruct myAwaitedBindAsyncStruct) =>
            {
                httpContext.Items["myAwaitedBindAsyncRecord"] = myAwaitedBindAsyncRecord;
                httpContext.Items["myAwaitedBindAsyncStruct"] = myAwaitedBindAsyncStruct;
            });

        var requestDelegate = resultFactory.RequestDelegate;
        await requestDelegate(httpContext);

        Assert.Equal(new MyAwaitedBindAsyncRecord(new Uri("https://example.org")), httpContext.Items["myAwaitedBindAsyncRecord"]);
        Assert.Equal(new MyAwaitedBindAsyncStruct(new Uri("https://example.org")), httpContext.Items["myAwaitedBindAsyncStruct"]);
    }

    public static object[][] DelegatesWithAttributesOnNotTryParsableParameters
    {
        get
        {
            void InvalidFromRoute([FromRoute] object notTryParsable) { }
            void InvalidFromQuery([FromQuery] object notTryParsable) { }
            void InvalidFromHeader([FromHeader] object notTryParsable) { }


Review comment (suggestion):
```suggestion
        var parameterBindingMetadata = factoryResult.EndpointMetadata
            .FirstOrDefault(e => e is ParameterBindingMetadata metadata &&
                metadata.Name == "formValues") as ParameterBindingMetadata;

        Assert.NotNull(parameterBindingMetadata);
        Assert.Equal(typeof(string[]), parameterBindingMetadata.ParameterInfo.ParameterType);
        Assert.Equal(new StringValues(new[] { "1", "2", "3" }), httpContext.Items["form"]!);
```

Code after:
    [Fact]
    public async Task RequestDelegateHandlesFromFormStringArrayParameter()
    {
        var httpContext = CreateHttpContext();
        httpContext.Request.Form = new FormCollection(new Dictionary<string, StringValues>
        {
            ["form"] = new(new[] { "1", "2", "3" })
        });

        var factoryResult = RequestDelegateFactory.Create(
            (HttpContext context, [FromForm(Name = "form")] string[] formValues) =>
        {
            context.Items["form"] = formValues;
        });

        var requestDelegate = factoryResult.RequestDelegate;

        await requestDelegate(httpContext);

        var parameterBindingMetadata = factoryResult.EndpointMetadata
            .FirstOrDefault(e => e is ParameterBindingMetadata metadata &&
                metadata.Name == "formValues") as ParameterBindingMetadata;

        Assert.NotNull(parameterBindingMetadata);
        Assert.Equal(typeof(string[]), parameterBindingMetadata.ParameterInfo.ParameterType);
        Assert.Equal(new StringValues(new[] { "1", "2", "3" }), httpContext.Items["form"]!);
    }

    [Fact]
    public async Task RequestDelegateCanAwaitValueTasksThatAreNotImmediatelyCompleted()
    {
        var httpContext = CreateHttpContext();

        httpContext.Request.Headers.Referer = "https://example.org";

        var resultFactory = RequestDelegateFactory.Create(
            (HttpContext httpContext, MyAwaitedBindAsyncRecord myAwaitedBindAsyncRecord, MyAwaitedBindAsyncStruct myAwaitedBindAsyncStruct) =>
            {
                httpContext.Items["myAwaitedBindAsyncRecord"] = myAwaitedBindAsyncRecord;
                httpContext.Items["myAwaitedBindAsyncStruct"] = myAwaitedBindAsyncStruct;
            });

        var requestDelegate = resultFactory.RequestDelegate;
        await requestDelegate(httpContext);

        Assert.Equal(new MyAwaitedBindAsyncRecord(new Uri("https://example.org")), httpContext.Items["myAwaitedBindAsyncRecord"]);
        Assert.Equal(new MyAwaitedBindAsyncStruct(new Uri("https://example.org")), httpContext.Items["myAwaitedBindAsyncStruct"]);
    }

    public static object[][] DelegatesWithAttributesOnNotTryParsableParameters
    {