我使用NSubstitute通过PartsOf()
方法模拟一个类(我需要一些方法来工作)。它看起来像这样:
var mock = Substitute.ForPartsOf<MyWorker>();
mock.Start().Returns(void);
一个简单的代码,几乎与NSubstitute的文档相似,但我得到了这个例外:"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."
问题是什么?
答案 0 :(得分:8)
我花了一些时间来弄明白。使用ForPartsOf()
时,模拟方法必须为virtual
!这解决了CouldNotSetReturnDueToNoLastCallException
异常的问题。