我正在安排在单元测试中调用一个方法,如下所示
container.Arrange(p=> p.doSomething(Arg.AnyString, Arg.AnyString)).ReturnsMany(1, 2);
1 和 2 将始终按顺序返回还是需要 InSequence() 链?
ReturnsMany 将按顺序返回值还是需要显式 InSequence?
我正在安排在单元测试中调用一个方法,如下所示
container.Arrange(p=> p.doSomething(Arg.AnyString, Arg.AnyString)).ReturnsMany(1, 2);
1 和 2 将始终按顺序返回还是需要 InSequence() 链?
ReturnsMany 将按顺序返回值还是需要显式 InSequence?
要保存序列,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
。