7

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?

andrew.fox
  • 7,435
  • 5
  • 52
  • 75

1 Answers1

11

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.

andrew.fox
  • 7,435
  • 5
  • 52
  • 75