无法确定的参数规格使用 [英] Cannot determine argument specifications to use

查看:209
本文介绍了无法确定的参数规格使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与NSubstitute一个问题。
我有这样的短代码:

I'm having a problem with NSubstitute. I have this short code:

ReportingCycleDeliveryRepository
.When(f => f.Add(Arg.Any<ReportingCycleDelivery>()))
.Do(x => RepCycleDeliveries.Add((ReportingCycleDelivery)x[0]));



所以,当我(无效)方法 ReportingCycleDeliveryRepository.Add()调用任何ReportingCycleDelivery的说法,应该将该产品添加到我的 RepCycleDeliveries 列表。

So when my (void) method ReportingCycleDeliveryRepository.Add() is invoked with any ReportingCycleDelivery argument, it should add this item to my RepCycleDeliveries list.

不过,相反,它抛出一个异常:

But instead, it throws an exception:

NSubstitute.Exceptions.AmbiguousArgumentsException

无法确定的参数规格来使用。
请使用规格为相同类型的所有参数。

"Cannot determine argument specifications to use. Please use specifications for all arguments of the same type."

这是为什么?为什么不能NSubstitute确定正确的参数规格使用?我清楚地提供了一个暗示,该参数可以是任意 ReportingCycleDelivery 项目。

Why is that? Why can't NSubstitute determine the correct argument specifications to use? I am clearly providing a hint, that the argument can be any ReportingCycleDelivery item.

推荐答案

您应该能够在你的代码更改为以下并让它工作,你会是喜欢的方式:

You should be able to change your code to the following and have it work the way you would like it to:

ReportingCycleDeliveryRepository
    .When(f => f.Add(Arg.Do<ReportingCycleDelivery>(
        x => RepCycleDeliveries.Add(x[0])));

这很难说清楚你为什么会得到这个错误没有看到代码 ReportingCycleDeliveryRepository ReportingCycleDelivery

It's hard to say exactly why you might get this error without seeing the code for ReportingCycleDeliveryRepository and ReportingCycleDelivery.

这篇关于无法确定的参数规格使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆