Skip to content

The Assert.That overloads expecting a (Async)TestDelegate/Action/Func<Task> only make sense on Throw constraints #5221

@manfred-brands

Description

@manfred-brands

As (Async)TestDelegate ,Action and Func<Task> do not return actual values, their only use is to executed under a Throw constraint so we can catch any exceptions.

Currently we allow Assert.That(() => {}, Is.Not.Null); and all other useless combinations.

We should only allow Assert.That(() => {}, Throws.Nothing)

Suitable modifiers should still be supported:

Assert.That(SomeMethod, Throws.ArgumentExeption.With.ParamName("arg"));
Assert.That(SomeMethod, Throws.Exeption<ArgumentException>().With(x => Assert.That(x.ParamName, Is.EqualTo("arg"))));
Assert.That(SomeMethod, Throws.Exeption<ArgumentException>().With(x => x.ParamName).EqualTo("arg"));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions