我有一类是有这样的签名的方法:如何处理委托参数NSubstitute
public async Task<ResponseType> getSuff(string id,
string moreInfo,
deletegateName doStuff
) { // details. }
我想嘲笑这个调用与NSubstitute这样的:
MyClass helper = Substitute.ForPartsOf<MyClass>();
ResponseType response = new ResponseType();
helper.getSuff(Arg.Any<string>(),
Arg.Any<string>(),
Arg.Any<DelegateDefn>()).Returns(Task.FromResult(response));
但我得到一个运行时错误:
NSubstitute.Exceptions.CouldNotSetReturnDueToNoLastCallException: Could not find a call to return from.
Make sure you called Returns() after calling your substitute (for example: mySub.SomeMethod().Returns(value)), and that you are not configuring other substitutes within Returns() (for example, avoid this: mySub.SomeMethod().Returns(ConfigOtherSub())).
If you substituted for a class rather than an interface, check that the call to your substitute was on a virtual/abstract member. Return values cannot be configured for non-virtual/non-abstract members.
Correct use: mySub.SomeMethod().Returns(returnValue);
Potentially problematic use: mySub.SomeMethod().Returns(ConfigOtherSub()); Instead try: var returnValue = ConfigOtherSub(); mySub.SomeMethod().Returns(returnValue);
问题是,我认为,代表。我只是想嘲笑这个方法,我不想让实际传递的委托被执行。
那么,有没有人知道我能做到这一点? 谢谢。
谢谢,菜鸟的错误:我忘了让方法虚拟:-( – dave