Skip to content

TUnitAssertions0009 fixer for Assert.All puts test subject and callback in wrong order #3776

@sliekens

Description

@sliekens

Hi,

Consider this test with xUnit.net assertions:

public class User
{
    public required string Name { get; set; }
    public required int Age { get; set; }
}

public class ConversionTest
{
    [Test]
    public async Task ConvertAssertAll()
    {
        User[] users =
        [
            new () { Name = "Alice", Age = 30 },
            new () { Name = "Bob", Age = 25 }
        ];

        Xunit.Assert.All(users, user =>
        {
            Xunit.Assert.NotNull(user.Name);
            Xunit.Assert.True(user.Age > 18);
        });
    }
}

The fixer for Assert.All produces incorrect code in the form of Assert.That(callback).All().Satisfy(testSubject):

TUnit.Assertions.Assert.That(user =>
{
    Xunit.Assert.NotNull(user.Name);
    Xunit.Assert.True(user.Age > 18);
}).All().Satisfy(users);

Based on discussion in #3766, I don't think this should use All().Satisfy(), but rather something like this:

using (TUnit.Assertions.Assert.Multiple())
{
    foreach (User user in users)
    {
        Xunit.Assert.NotNull(user.Name);
        Xunit.Assert.True(user.Age > 18);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions