Repository: dotnet/aspnetcore
File: src/Components/Endpoints/test/Binding/FormDataMapperTests.cs (C#)

Code before:
        var errors = new List<FormDataMappingError>();
        reader.ErrorHandler = (key, message, attemptedValue) =>
        {
            errors.Add(new FormDataMappingError(key, message, attemptedValue));
        };
        reader.PushPrefix("file");
        var options = new FormDataMapperOptions();

        // Act
        var result = CallDeserialize(reader, options, typeof(IReadOnlyList<IBrowserFile>));

        // Assert
        var browserFiles = Assert.IsAssignableFrom<IReadOnlyList<IBrowserFile>>(result);
        // First file
        var browserFile1 = browserFiles[0];
        Assert.Equal("file", browserFile1.Name);
        Assert.Equal(expectedString1.Length, browserFile1.Size);
        var buffer1 = new byte[browserFile1.Size];
        browserFile1.OpenReadStream().Read(buffer1);
        Assert.Equal(expectedString1, Encoding.UTF8.GetString(buffer1, 0, buffer1.Length));
        // Second files
        var browserFile2 = browserFiles[0];
        Assert.Equal("file", browserFile2.Name);
        Assert.Equal(expectedString1.Length, browserFile2.Size);
        var buffer2 = new byte[browserFile2.Size];
        browserFile1.OpenReadStream().Read(buffer2);
        Assert.Equal(expectedString1, Encoding.UTF8.GetString(buffer2, 0, buffer2.Length));
    }

    [Fact]
    public void RecursiveTypes_Comparer_SortsValues_Correctly()
    {
        // Arrange
        var data = new Dictionary<string, StringValues>()
        {
            ["customerId"] = "20",
            ["customer[Id]"] = "20",
            ["customer.Id"] = "20"
        };
        var reader = CreateFormDataReader(data, CultureInfo.InvariantCulture);
        reader.PushPrefix("customer");

        // Act
        var result = reader.CurrentPrefixExists();

        // Assert
        Assert.True(result);
    }

    public static TheoryData<string, Type, object> NullableBasicTypes
    {

Review comment (bug):
This line correctly fixes the bug where the test was incorrectly reading from browserFile1's stream instead of browserFile2's stream when testing the second file.

Code after:
        var errors = new List<FormDataMappingError>();
        reader.ErrorHandler = (key, message, attemptedValue) =>
        {
            errors.Add(new FormDataMappingError(key, message, attemptedValue));
        };
        reader.PushPrefix("file");
        var options = new FormDataMapperOptions();

        // Act
        var result = CallDeserialize(reader, options, typeof(IReadOnlyList<IBrowserFile>));

        // Assert
        var browserFiles = Assert.IsAssignableFrom<IReadOnlyList<IBrowserFile>>(result);
        // First file
        var browserFile1 = browserFiles[0];
        Assert.Equal("file1.txt", browserFile1.Name);
        Assert.Equal(expectedString1.Length, browserFile1.Size);
        var buffer1 = new byte[browserFile1.Size];
        browserFile1.OpenReadStream().Read(buffer1);
        Assert.Equal(expectedString1, Encoding.UTF8.GetString(buffer1, 0, buffer1.Length));
        // Second files
        var browserFile2 = browserFiles[1];
        Assert.Equal("file2.txt", browserFile2.Name);
        Assert.Equal(expectedString2.Length, browserFile2.Size);
        var buffer2 = new byte[browserFile2.Size];
        browserFile2.OpenReadStream().Read(buffer2);
        Assert.Equal(expectedString2, Encoding.UTF8.GetString(buffer2, 0, buffer2.Length));
    }

    [Fact]
    public void RecursiveTypes_Comparer_SortsValues_Correctly()
    {
        // Arrange
        var data = new Dictionary<string, StringValues>()
        {
            ["customerId"] = "20",
            ["customer[Id]"] = "20",
            ["customer.Id"] = "20"
        };
        var reader = CreateFormDataReader(data, CultureInfo.InvariantCulture);
        reader.PushPrefix("customer");

        // Act
        var result = reader.CurrentPrefixExists();

        // Assert
        Assert.True(result);
    }

    public static TheoryData<string, Type, object> NullableBasicTypes
    {