我正在安排对单元测试中方法的调用,如下所示
container.Arrange(p=> p.doSomething(Arg.AnyString, Arg.AnyString)).ReturnsMany(1, 2);是始终按顺序返回1和2,还是需要InSequence()链?
ReturnsMany是按顺序返回值还是需要显式InSequence?
发布于 2020-06-07 14:53:40
要保存序列,不需要调用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。
https://stackoverflow.com/questions/62235361
复制相似问题