使用 return 类型的 Moq 在模拟对象中定义方法实现

Define method implementation in mock object using Moq with return type

我的问题基于以下线程中给出的已接受答案

Define method implementation in mock object using Moq

在此示例中,RequestSenderHelpers.Send() 具有 return 类型的 "void"。如果 return 类型(implementation/defined 方法)是 int 或任何其他类型,我该如何让它工作?

试试这个:

var result = x.Send(It.IsAny<HttpWebRequest>(), It.IsAny<AsyncCallback>(), It.IsAny<object>());
Assert.IsInstanceOfType(result, typeof(yourTypeHere));