gpt4 book ai didi

c# - 起订量设置抛出异常

转载 作者:行者123 更新时间:2023-12-04 10:37:06 24 4
gpt4 key购买 nike

我正在设置起订量,例如:

mockCommand.Setup(foo => foo.Post<Foo, Response>(It.IsAny<Foo>()))
.Returns((Foo m) =>
{
if (m . . . .)
{
return new <Response>()
{
<...>
};
}
else
{
return new <Response>()
{
<...>
};
}
});

但我得到一个异常(exception):

System.ArgumentException : Invalid callback. Setup on method with 2 parameter(s) cannot invoke callback with different number of parameters (1).



泛型方法定义为:
TResponse Post<TRequest, TResponse>(TRequest request, params string[] query)

我唯一能想到的是,不知何故,因为我有条件地返回响应,所以它以某种方式混淆了 Moq,所以它抛出了异常。想法?

最佳答案

异常(exception)是指出设置中省略了参数,Returns回调委托(delegate)。

包括被模拟的成员的所有参数

mockCommand
.Setup(foo => foo.Post<Foo, Response>(It.IsAny<Foo>(), It.IsAny<string[]>()))
.Returns((Foo m, string[] q) => {
//...omitted for brevity
});

关于c# - 起订量设置抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60122867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com