簡體   English   中英

N用不明確的參數替換掉數組嗎?

[英]NSubstitute out arrays, with ambiguous parameters?

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));
    }

結果是:

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(

簡短的答案是不要在ReceivedReturns之外使用參數匹配器

更長的答案是要獲得NSubstitute的語法,它會做一些可疑的事情。 在這種情況下,每次執行Arg.IsArg.Any都會將參數匹配器推入靜態( Arg.Is Arg.Any )隊列。 當它收到一個實際的調用時,它會檢索這些參數匹配器,以找出匹配的調用(對於Received )或對存根的調用(對於Returns )。

在這種情況下,三個參數匹配器fakeTest .Received().testMethod(bool a, bool b)隊列,但是fakeTest .Received().testMethod(bool a, bool b)僅占用兩個,因此NSubstitute不確定這三個參數匹配器的去向。

順便說一句,這些情況和錯誤消息的檢測設置為在NSubstitute的下一版本(3.1之后)中得到改進。

NSubstitute在評估包含Arg.Is的已接電話時似乎具有某種完整性檢查。

將Arg.Is放在Received調用中,或不調用.Received,或注釋掉Orphan參數似乎可以解決此問題,但我不知道為什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM