NSubstitute CouldNotSetReturnDueToNoLastCallException

I use NSubstitute to bully the class using the PartsOf() method (I need some of the methods to work). It looks like this:

 var mock = Substitute.ForPartsOf<MyWorker>(); mock.Start().Returns(void); 

Simple code, almost the same as in NSubstitute documentation, but instead I get this exception: "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 is the problem?

+6
source share
1 answer

I took the time to figure it out. When using ForPartsOf() the bullying method must be virtual ! This solves the problem with a CouldNotSetReturnDueToNoLastCallException exception.

+9
source

Source: https://habr.com/ru/post/983788/


All Articles