I'm using NSubstitute to mock a class by PartsOf() method (I need some of the methods to work). It looks like this:
var mock = Substitute.ForPartsOf<MyWorker>();
mock.Start().Returns(void);
A simple code almost like from the NSubstitute's documentation, but I'm getting this exception instead: "An exception of type 'NSubstitute.Exceptions.CouldNotSetReturnDueToNoLastCallException'
occurred in NSubstitute.dll but was not handled in user code
Additional information: Could not find a call to return from."
What's the problem?
I took me some time to figure it out. When using ForPartsOf() the mocked method must be virtual! That solves the problem with the CouldNotSetReturnDueToNoLastCallException exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With