Skip to content

[Bug]: All() for Collections/List<T> not available in .NET 8 #6280

Description

@manne

Description

I have this test class (see below).

When I run them with the target frameworks net9.0 and net10.0. The project compiles and the tests are being executed successfully.

When I compile the project with the target framework net8.0, it does not get compiled.

Test Class

namespace FancyTests;

public sealed class CollectionAllTests
{
    [Test]
    public async ValueTask Foo()
    {
        List<FancyEnum> cut =
        [
            FancyEnum.Foo,
            FancyEnum.Bar,
            FancyEnum.Hello
        ];

        await Assert.That(cut).All(i => i != FancyEnum.World);
    }

    [Test]
    public async Task All_Items_Match()
    {
        int[] numbers = [2, 4, 6, 8];

        await Assert.That(numbers).All(n => n % 2 == 0);
    }

    [Test]
    public async Task All_Items_Match_List()
    {
        List<int> numbers = [2, 4, 6, 8];

        await Assert.That(numbers).All(n => n % 2 == 0);
    }

    [Test]
    public async Task All_Items_Match_List_Array()
    {
        int[] numbers = new List<int>([2, 4, 6, 8]).ToArray();

        await Assert.That(numbers).All(n => n % 2 == 0);
    }
}

public enum FancyEnum
{
    Foo = 0,
    Bar = 1,
    Hello = 2,
    World = 3,
}

Result of .NET 9.0

dotnet run

████████╗██╗   ██╗███╗   ██╗██╗████████╗
╚══██╔══╝██║   ██║████╗  ██║██║╚══██╔══╝
   ██║   ██║   ██║██╔██╗ ██║██║   ██║
   ██║   ██║   ██║██║╚██╗██║██║   ██║
   ██║   ╚██████╔╝██║ ╚████║██║   ██║
   ╚═╝    ╚═════╝ ╚═╝  ╚═══╝╚═╝   ╚═╝

   TUnit v1.54.0.0 | 64-bit | Microsoft Windows 10.0.26200 | win-x64 | .NET 9.0.17 | Microsoft Testing Platform v2.2.3

   Engine Mode: SourceGenerated


  In process file artifacts produced:
    - bin\Debug\net9.0\TestResults\FancyTests-windows-net9.0-report.html

Test run summary: Passed! - bin\Debug\net9.0\FancyTests.dll (net9.0|x64)
  total: 4
  failed: 0
  succeeded: 4
  skipped: 0
  duration: 401ms

Expected Behavior

The test class gets compiled for all three target frameworks (8,9,10) and its tests are being executed successfully.

Actual Behavior

The project gets not compiled for .NET 8.0.

Steps to Reproduce

  1. Create a project with this content
    <Project Sdk="Microsoft.NET.Sdk">
    
        <PropertyGroup>
            <TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
            <OutputType>Exe</OutputType>
            <ImplicitUsings>enable</ImplicitUsings>
            <Nullable>enable</Nullable>
        </PropertyGroup>
    
        <ItemGroup>
            <PackageReference Include="TUnit" Version="1.54.0" />
        </ItemGroup>
    
    </Project>
  2. Create a CS file with the content from the description
  3. Repeat for each target framework
    1. Execute dotnet run for the project
    2. Select the target framework
  4. Observe

TUnit Version

1.54.0

.NET Version

net8.0;net9.0;net10.0

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

dotnet run
  FancyTests net8.0 failed with 2 error(s) (0,7s)
    C:\Users\zzz\Downloads\ic-tunit\FancyTests\CollectionAllTests.cs(15,32): error CS0411: The type arguments for method 'ImmutableArrayExtensions.All<T>(ImmutableArray<T>, Func<T, bool>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
    C:\Users\zzz\Downloads\ic-tunit\FancyTests\CollectionAllTests.cs(31,36): error CS0411: The type arguments for method 'ImmutableArrayExtensions.All<T>(ImmutableArray<T>, Func<T, bool>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

The build failed. Fix the build errors and run again.

Additional Context

nothing special; see project file

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions