【问题标题】:JustMock Will ReturnsMany returns in sequenceJustMock 将按顺序返回许多返回
【发布时间】:2020-06-06 17:23:05
【问题描述】:

我正在安排调用单元测试中的方法,如下所示

container.Arrange(p=> p.doSomething(Arg.AnyString, Arg.AnyString)).ReturnsMany(1, 2);

1 和 2 总是按顺序返回还是需要 InSequence() 链?

ReturnsMany 会按顺序返回值还是需要显式 InSequence?

文档:https://docs.telerik.com/devtools/justmock/api/overload_telerik_justmock_helpers_multiplereturnvaluechainhelper_returnsmany

【问题讨论】:

  • 您的问题是什么?
  • 对此一无所知,我可以告诉您,您链接到的文档说它配置了对方法的多次调用,因此您似乎不必调用其他任何东西,它会设置要按顺序返回的值

标签: c# asp.net justmock


【解决方案1】:

要保存序列,不需要InSequence() 方法调用。为了确保你能看到the source code

private class ReturnsManyImpl<TReturn>
{
    internal int CurrentIndex;
    private readonly IList<TReturn> values;
    private readonly Action<ReturnsManyImpl<TReturn>> afterEndAction;

    public ReturnsManyImpl(IList<TReturn> values, Action<ReturnsManyImpl<TReturn>> afterEndAction)
    {
        this.afterEndAction = afterEndAction;
        this.values = values;
    }

    internal TReturn GetNext()
    {
        if (CurrentIndex >= values.Count)
            afterEndAction(this);

        return values[CurrentIndex++];
    }
}

但请记住behavior参数,默认情况下它等于AfterLastValue.KeepReturningLastValue

【讨论】:

    猜你喜欢
    • 2015-07-22
    • 2011-12-06
    • 2014-12-28
    • 1970-01-01
    • 2017-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多