小编Ski*_*ors的帖子

NSubstitute测试单独工作,但在套件中抛出Unexpected Matcher Argument

我有一个单元测试,我使用.Returns()返回一些示例数据:

    [TestMethod]
    public void TestRetrieveElementsInVersion()
    {
        IRetrieveElementSequence component = Substitute.For<IRetrieveElementSequence>();
        List<UnconstructedElement> list = new List<UnconstructedElement>
        {
            new UnconstructedElement{Version = "1"},
            new UnconstructedElement{Version = "2"}
        };
        component.RetrieveElements().Returns(list); // exception reported here
        const string target = "1";
        IRetrieveElementSequence service = new RetrieveElementsInAVersion(component, target);
        IList<UnconstructedElement> result = service.RetrieveElements();
        bool check = result.All(e => e.Version == target);
        Assert.IsTrue(check);
    }
Run Code Online (Sandbox Code Playgroud)

当测试单独运行时,此代码使用ReSharper运行程序在Visual Studio中传递.当它作为列表的一部分运行时失败,就像我从解决方案运行所有测试一样.

NSubstitute.Exceptions.UnexpectedArgumentMatcherException:参数匹配器(Arg.Is,Arg.Any)只应用于代替成员参数.不要在Returns()语句或成员调用之外的任何其他地方使用.

我不知道我在哪里使用Arg.Any或Arg.Is. 我在做什么让NSubstitute抱怨?当我使用.Returns()返回非本机对象列表时会发生这种情况.

c# nsubstitute

4
推荐指数
1
解决办法
1728
查看次数

标签 统计

c# ×1

nsubstitute ×1