Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSubstitute CouldNotSetReturnDueToNoLastCallException

Tags:

nsubstitute

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?

like image 540
andrew.fox Avatar asked Mar 14 '15 11:03

andrew.fox


1 Answers

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.

like image 102
andrew.fox Avatar answered Nov 11 '22 11:11

andrew.fox