Skip to content

String length assertions broken #3912

@Randactyl

Description

@Randactyl

The TUnit documentation shows that HasLength() should support chained comparisons, but in version 1.2.11 HasLength() returns a LengthWrapper type that doesn't contain comparison methods like GreaterThan(), LessThan(), etc.

Expected Behavior:

According to the TUnit String Assertions documentation, the following code should work:

[Test]
public async Task Length_With_Comparison()
{
    var username = "alice";
    await Assert.That(username)
        .HasLength().GreaterThan(3)
        .And.HasLength().LessThan(20);
}

Actual Behavior:

The code fails to compile with the following error:
error CS1061: 'LengthWrapper' does not contain a definition for 'GreaterThan' and no accessible extension method 'GreaterThan' accepting a first argument of type 'LengthWrapper' could be found (are you missing a using directive or an assembly reference?)

Reproduction:

[Test]
public async Task StringHasLength()
{
    string str1 = "Hello, World!";
    await Assert.That(str1).HasLength().GreaterThan(5);
}

Environment:

TUnit Version: 1.2.11
Target Framework: .NET 10.0

Additional Notes:

I didn't try every version, but the earliest version of TUnit I noticed this broken in is 0.70.0.

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