-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Labels
Description
I'd like to be able to perform exception assertions in a single statement, without using the subject.Invoking(...) pattern (e.g. for calling static methods), and without having to create an Action variable first.
I propose a static class with Invoking, Awaiting, and Enumerating methods for this purpose, e.g.:
public static class FluentAction
{
public static Action Invoking(Action action) => action;
public static Func<T> Invoking<T>(Func<T> func) => func;
public static Func<Task> Awaiting(Func<Task> action) => action;
public static Func<Task<T>> Awaiting<T>(Func<Task<T>> func) => func;
public static Action Enumerating(Func<IEnumerable> enumerable) => enumerable.Enumerating();
public static Action Enumerating<T>(Func<IEnumerable<T>> enumerable) => enumerable.Enumerating();
}Used like so:
FluentAction.Invoking(() => MyClass.Create(null)).Should().Throw<ArgumentNullException();Or even:
using static FluentAssertions.FluentAction;
...
Invoking(() => MyClass.Create(null)).Should().Throw<ArgumentNullException();eNeRGy164