首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSubstitute out数组,参数不明确?

NSubstitute out数组,参数不明确?
EN

Stack Overflow用户
提问于 2018-05-07 06:19:27
回答 2查看 1.2K关注 0票数 0

NSubstitute抱怨我的论点含糊不清,但据我所知,它们是完全规范的。我想补充更多的细节,但我已经把它归结为这个小例子了。(编辑:现在更小了,删除了out参数,而不是参数的定义。)

我的最终目标是使“内联方法”成为测试的辅助方法,输入结果,以及表示一系列错误的预期ITextObjC[]。

考虑到最小、完整、可验证的例子:

代码语言:javascript
复制
    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));
    }

在以下方面的成果:

代码语言:javascript
复制
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

在这条线上:

fakeTest.Received(1).testMethod(

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-05-07 09:27:09

简单的回答是Returns

更长的答案是,为了获得NSub妓女的语法,它会做一些可疑的事情。在这种情况下,每次执行Arg.IsArg.Any时,它都会将参数匹配器推入静态(线程本地)队列。当它接收到一个实际的调用时,它将检索这些参数匹配器,以求出匹配什么调用(对于Received)或对存根的调用(对于Returns)。

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

另外,这些情况和错误消息的检测被设置为改进下一个版本的NSubstitute (在3.1之后)。

票数 3
EN

Stack Overflow用户

发布于 2018-05-07 07:04:06

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50208099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档