NSubstitute - mock throwing an exception in method returning void

Viewed 7081

Using NSubstitute, how do you mock an exception being thrown in a method returning void?

Let's say our method signature looks something like this:

    void Add();

Here's how NSubstitute docs say to mock throwing exceptions for void return types. But this doesn't compile :(

    myService
        .When(x => x.Add(-2, -2))
        .Do(x => { throw new Exception(); });

So how do you accomplish this?

1 Answers
Related