C# NSSubstitute out数组,参数不明确?

C# NSSubstitute out数组,参数不明确?,c#,.net,nsubstitute,C#,.net,Nsubstitute,NSubstitute抱怨我的论点模棱两可,但据我所知,它们是完全规范化的。我想添加更多细节,但我已经将其归结为这个小示例。(编辑:现在更小,删除了参数,但不是参数的定义。) 我的最终目标是让“内联方法”成为测试的助手方法,具有结果的输入,以及预期的ITextObjC[],它表示一个错误数组 给出最小、完整、可验证的示例: public interface test { bool testMethod( bool boolA,

NSubstitute抱怨我的论点模棱两可,但据我所知,它们是完全规范化的。我想添加更多细节,但我已经将其归结为这个小示例。(编辑:现在更小,删除了参数,但不是参数的定义。)

我的最终目标是让“内联方法”成为测试的助手方法,具有结果的输入,以及预期的ITextObjC[],它表示一个错误数组

给出最小、完整、可验证的示例:

    public interface test
    {
        bool testMethod(
            bool boolA,
            bool boolB);
    }

    public interface ITestObjC { }

    public class TestObjC : ITestObjC { }

    [Test]
    public void SillyTest2()
    {
        var fakeTest = Substitute.For<test>();

        fakeTest.testMethod(  false, false);

        ITestObjC[] recOutArr = Arg.Is<ITestObjC[]>(x => x == null);

        fakeTest.Received(1).testMethod(
            Arg.Is<bool>(false),
            Arg.Is<bool>(false));
    }
公共接口测试
{
布尔测试法(
布尔布尔,
bool boolB);
}
公共接口ITestObjC{}
公共类TestObjC:ITestObjC{}
[测试]
公共无效SillyTest2()
{
var fakeTest=替换为();
fakeTest.testMethod(false,false);
ITestObjC[]recovertarr=Arg.Is(x=>x==null);
fakeTest.Received(1).testMethod(
参数为(假),
参数为(假));
}
结果:

NSubstitute.Exceptions.AmbiguousArgumentsException : Cannot determine argument specifications to use.
Please use specifications for all arguments of the same type.
   at NSubstitute.Core.Arguments.NonParamsArgumentSpecificationFactory.Create(Object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications)
   at NSubstitute.Core.Arguments.ArgumentSpecificationFactory.Create(Object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications)
   at NSubstitute.Core.Arguments.MixedArgumentSpecificationsFactory.<>c__DisplayClass3_0.<Create>b__0(Object argument, Int32 i)
   at System.Linq.Enumerable.<SelectIterator>d__5`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at NSubstitute.Core.Arguments.MixedArgumentSpecificationsFactory.Create(IList`1 argumentSpecs, Object[] arguments, IParameterInfo[] parameterInfos)
   at NSubstitute.Core.Arguments.ArgumentSpecificationsFactory.Create(IList`1 argumentSpecs, Object[] arguments, IParameterInfo[] parameterInfos, MatchArgs matchArgs)
   at NSubstitute.Core.CallSpecificationFactory.CreateFrom(ICall call, MatchArgs matchArgs)
   at NSubstitute.Routing.Handlers.CheckReceivedCallsHandler.Handle(ICall call)
   at NSubstitute.Routing.Route.<>c__DisplayClass8_0.<Handle>b__0(ICallHandler x)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at NSubstitute.Routing.Route.Handle(ICall call)
   at NSubstitute.Core.CallRouter.Route(ICall call)
   at NSubstitute.Proxies.CastleDynamicProxy.CastleForwardingInterceptor.Intercept(IInvocation invocation)
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.testProxy.testMethod(ITestObjA motionEnvelope, ITestObjB motionSeries, Boolean primaryLimits, Boolean testPitch, ITestObjC[]& exceedences)
   at HeliSAFE.DataStorage.Tests.SholMonitor.CommonSholMonitorTests.SillyTest2() in D:\Repositories\GitSAFE_Repos\helisafe.container\helisafe\HeliSAFE.DataStorage.Tests\SholMonitor\CommonSholMonitorTests.cs:line 375
NSubstitute.Exceptions.AmbiguousArgumentsException:无法确定要使用的参数规范。
请对相同类型的所有参数使用规范。
在NSubstitute.Core.Arguments.NonParamsArgumentSpecificationFactory.Create(对象参数、iPParameterInfo参数信息、iSuppliedGumentSpecifications和SuppliedGumentSpecifications)
在NSubstitute.Core.Arguments.ArgumentSpecificationFactory.Create(对象参数、iPParameterInfo参数信息、ISuppliedArgumentSpecifications和suppliedArgumentSpecifications)
在NSubstitute.Core.Arguments.MixedArgumentSpecificationsFactory.c__显示类3_0.b__0(对象参数,Int32 i)
在System.Linq.Enumerable.d_u5`2.MoveNext()中
位于System.Collections.Generic.List`1..ctor(IEnumerable`1集合)
在NSubstitute.Core.Arguments.MixedArgumentSpecificationsFactory.Create(IList`1 argumentSpecs,Object[]Arguments,iPParameterInfo[]ParameterInfo)
在NSubstitute.Core.Arguments.ArgumentSpecificationsFactory.Create(IList`1 argumentSpecs,Object[]Arguments,iPParameterInfo[]ParameterInfo,MatchArgs MatchArgs)
在NSubstitute.Core.CallSpecificationFactory.CreateFrom(ICall调用,MatchArgs MatchArgs)
在NSubstitute.Routing.Handlers.CheckReceivedCallsHandler.handler处(ICall调用)
在NSubstitute.Routing.Route.c__显示类8_0.b__0(ICallHandler x)
在System.Linq.Enumerable.WhereSelectArrayInterator`2.MoveNext()中
在System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1源,Func`2谓词)
在NSubstitute.Routing.Route.Handle处(ICall调用)
在NSubstitute.Core.CallRouter.Route(ICall呼叫)上
在NSubstitute.proxy.CastleDynamicProxy.CastleForwardingInterceptor.Intercept(IInvocation调用)处
在Castle.DynamicProxy.AbstractInvocation.procedure()中
在Castle.Proxies.testProxy.testMethod(ITestObjA motionEnvelope、ITestObjB motionSeries、Boolean primaryLimits、Boolean testPitch、ITestObjC[]&exceedences)
位于D:\Repositories\GitSAFE\u Repos\HeliSAFE.container\HeliSAFE\HeliSAFE.DataStorage.Tests.SholMonitor.commonholmonitortests.SillyTest2()中的HeliSAFE.DataStorage.Tests\SholMonitor\commonholmonitortests.cs:第375行
在这一行:


fakeTest.Received(1).testMethod(

NSubstitute)在评估包含Arg.Is的已接收调用时,似乎有某种完整性检查


在接收到的调用中省略Arg.Is,或者不调用.Received,或者注释掉孤立参数似乎可以修复它,但我不知道为什么。

NSubstitute在评估包含Arg.Is的接收到的调用时似乎有某种完整性检查

在Received call中省略Arg.Is,或不调用.Received,或注释掉孤立参数似乎可以修复它,但我不知道为什么。

简短的答案是

较长的答案是,要获取NSubstitute的语法,它会做一些有问题的事情。在这种情况下,每次执行
Arg.is
Arg.Any
时,它都会将参数匹配器推到静态(threadlocal)队列中。当它收到实际调用时,它会检索这些参数匹配器,以确定匹配的调用(对于
接收的
)或对存根的调用(对于
返回的

在这种情况下,三个参数匹配器排队,但是
fakeTest.Received().testMethod(bool a,bool b)
只需要两个,因此NSubstitute不确定这三个参数匹配器要去哪里

另一方面,这些情况和错误消息的检测将随着NSubstitute的下一个版本(3.1之后)而改进。

简短的回答是

较长的答案是,要获取NSubstitute的语法,它会做一些有问题的事情。在这种情况下,每次执行
Arg.is
Arg.Any
时,它都会将参数匹配器推到静态(threadlocal)队列中。当它收到实际调用时,它会检索这些参数匹配器,以确定匹配的调用(对于
接收的
)或对存根的调用(对于
返回的

在这种情况下,三个参数匹配器排队,但是
fakeTest.Received().testMethod(bool a,bool b)
只需要两个,因此NSubstitute不确定这三个参数匹配器要去哪里


另一方面,这些情况和错误消息的检测将随着下一个版本的NSubstitute(3.1之后)而改进。

感谢您的权威回复!这仅仅是我的一半努力,另一个是返回(value)和返回(Lamda)以及返回(ranyargs)之间的语义差异。模拟的方法被多次调用,我的假设是1。它将多次返回true。2。我的问题在于Arg由于类型而不匹配,(我处理的是重载方法)3。我可以控制lambda之外的out参数。因为