Skip to content

[Bug]: Collection assertions don't work when type given to Assert.That is ICollection/ICollection<T> #4446

@SeanGriffin-Wellsky

Description

@SeanGriffin-Wellsky

Description

Similar to the issues described in #4387 and #4418, the collection assertions don't work when the type given to Assert.That is ICollection or ICollection<T>.

This compiles:

IEnumerable<int> numbers = [1, 2, 3];
await Assert.That(numbers).IsEmpty();

This does not:

ICollection<int> numbers2 = [1, 2, 3];
await Assert.That(numbers2).IsEmpty();

The type that is returned when an ICollection is given to That() is ValueAssertion not CollectionAssertion.

Expected Behavior

Giving an ICollection or ICollection<T> to Assert.That will return CollectionAssertion<T>.

Actual Behavior

It returns ValueAssertion

Steps to Reproduce

[Test]
public async Task CollectionAssertionTest()
{
    ICollection<int> nums = [1, 2, 3];
    await Assert.That(nums).IsEmpty();
}

TUnit Version

1.11.45

.NET Version

.NET10

Operating System

macOS

IDE / Test Runner

JetBrains Rider

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