I'm using NSubsitute to mock a class that my method under test uses. I want to ensure that my method does not throw exceptions that are caused by its dependencies.
Is there a way to force a mocks to throw an exception, no matter which of its methods are called?
I know, I can 'prepare' the mock to throw an exception if a specific method will be called. But then I also need to check if this prepared method was called at all, to prevent others to change the code without changing the unit test. But this would also mean to start testing the algorithm which I don't want to do.
Edit: Because I'm trying to mock the IRestClient from RestSharp I found at least a way to throw exceptions for every call that will return a Task<IRestResponse> - this is sufficient for my use case. Maybe my question wasn't specific enough and did imply to much of a wrong solution.
var restClient = Substitute.For<IRestClient>();
restClient.ReturnsForAll<Task<IRestResponse>>(t => throw new Exception("something did go wrong with the web api call"));