Skip to content

[Bug]: xUnit fixer incorrectly converts Assert.All with item action #4811

@ascott18

Description

@ascott18

Description

The following xUnit test will not have the inner item assertions converted.

    [Fact]
    public void TestWithAssertAll()
    {
        var items = new[] { 1, 2, 3 };

        Assert.All(items, item =>
        {
            Assert.True(item > 0);
            Assert.True(item < 10);
            Assert.NotEqual(0, item);
        });
    }

Expected Behavior

Ideally, an overload of All that takes an async delegate and allows for nested awaited TUnit assertions, perhaps working in a similar way for Assert.Multiple() for each nested item? Like this:

        await Assert.That(items).All(async item =>
        {
            await Assert.That(item > 0).IsTrue();
            await Assert.That(item < 10).IsTrue();
            await Assert.That(item).IsNotEqualTo(0);
        });

Or, failing that, to just have the assertion be converted to a foreach loop:

        foreach (var item in items)
        {
            await Assert.That(item > 0).IsTrue();
            await Assert.That(item < 10).IsTrue();
            await Assert.That(item).IsNotEqualTo(0);
        };

Actual Behavior

Fixer produces the following, which is not a valid way to use TUnit's All assertion, and inner assertions are left as xUnit assertions.

        await Assert.That(items).All(item =>
        {
            Assert.True(item > 0);
            Assert.True(item < 10);
            Assert.NotEqual(0, item);
        });

Steps to Reproduce

Run xUnit code fixer on the code in the description above.

TUnit Version

1.14.0

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

Additional Context

No response

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