Skip to content

[Bug]: GenerateAssertion extension not available when targeting concrete collection #4825

@ascott18

Description

@ascott18

Description

The following generated assertion is not available because of a type mismatch between the generated extension ContainsMessage(this IAssertionSource<string[]> source, ...) and the actual return type of Assert.That(), which is CollectionAssertion<string>.

public class UnitTest1
{
    [Test]
    public async Task Test1()
    {
        string[] items = new[] { "food", "bard" };
        await Assert.That(items).ContainsMessage("foo", false);
    }
}

public static partial class Assertions
{
    [EditorBrowsable(EditorBrowsableState.Never)]
    [GenerateAssertion(ExpectationMessage = "to contain message '{needle}'")]
    public static bool ContainsMessage(this string[] strings, string needle, bool exact = true)
    {
        return strings.Any(x => exact ? x == needle : x.Contains(needle));
    }
}

Expected Behavior

Generated assertion is available when assertion target is a concrete collection.

Actual Behavior

Assertion not available.

Steps to Reproduce

See above code.

TUnit Version

1.15.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

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions