0

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

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

4

1 回答 1

0

要保存序列,InSequence()不需要方法调用。为了确保您可以看到源代码

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

于 2020-06-07T06:53:39.597 回答