I have an interface which can't be modified and has a ridiculous amount of methods (basically overloads--each is slightly different).
In some scenarios every method on the interface should throw the same exception. There are several of these scenarios, each with their own exception (stuff like SystemInMaintenanceModeException
, ClientRateLimitedException
, TheJanitorUnpluggedTheServerException
).
There are unit tests and the amount of setup for these exception-throwing scenarios feels downright silly... something like:
_mockedService.Setup(mock => mock.DoA(It.IsAny<string>()).Throws(expectedException);
_mockedService.Setup(mock => mock.DoB(It.IsAny<string>()).Throws(expectedException);
_mockedService.Setup(mock => mock.DoC(It.IsAny<string>()).Throws(expectedException);
...
_mockedService.Setup(mock => mock.DoX(It.IsAny<string>()).Throws(expectedException);
_mockedService.Setup(mock => mock.DoY(It.IsAny<string>()).Throws(expectedException);
_mockedService.Setup(mock => mock.DoZ(It.IsAny<string>()).Throws(expectedException);
Can Moq be configured to throw a specified exception for every method on the mocked interface?
PS: I'm aware that the Strict behavior will throw an exception on any call, but I need it to be specified exception(s).