Skip to content

Allow Is.AnyOf to be called with arrays or other collections #4355

@manfred-brands

Description

@manfred-brands

Follow-up to a great docs observation on nunit/docs#750 and nunit/nunit.analyzers#533

The Is.AnyOf only works if the members are specified as individual values, not if passed as an array or list.

Example Gotcha:

[Test]
public void CanBeUsedWithParameters()
{
    Assert.That(42, Is.AnyOf(0, -1, 42, 100)); // Passes
}

[Test]
public void CantBeUsedWithAnArray()
{
    var array = new[] { 0, -1, 42, 100 };
    Assert.That(42, Is.AnyOf(array)); // Fails
}

[Test]
public void CantBeUsedWithAList()
{
    var list = new List<int>() { 0, -1, 42, 100 };
    Assert.That(42, Is.AnyOf(list)); // Fails
}

It was suggested to make an Analyzer to warn about this, but it seems more prudent to fix it in the framework, so that these expected cases work.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions