JustMock Will ReturnsMany returns in sequence

95 views Asked by At

I am arranging call for a method in a unit test like below

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

Is 1 and 2 will be returned in sequence always or InSequence() chain is required?

Will ReturnsMany returns values in sequence or explicit InSequence is required?

Docs: https://docs.telerik.com/devtools/justmock/api/overload_telerik_justmock_helpers_multiplereturnvaluechainhelper_returnsmany

1

There are 1 answers

0
smolchanovsky On

To save a sequence, InSequence() method call is not required. To make sure you can see 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++];
    }
}

But remember about behavior parameter, by default it is equal to AfterLastValue.KeepReturningLastValue.