You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When multiple invocations with the same arguments are defined consecutive on a mock, then the last matching method call is used instead of the method call corresponding with the current sequence step.
This is because while scanning for a matching method call, the sequence step is incremented on each match. This causes subsequent method calls with matching arguments - even though their sequence step is higher then the current step - to be considered as candidate.
I've added the following test which currently fails on the first assert (Expected: 101, Actual: 102):
[Fact]
public void SameMockRightSequenceMultipleInvocationsWithSameArguments()
{
var a = new Mock<IFoo>(MockBehavior.Strict);
var sequence = new MockSequence();
a.InSequence(sequence).Setup(x => x.Do(100)).Returns(101);
a.InSequence(sequence).Setup(x => x.Do(100)).Returns(102);
a.InSequence(sequence).Setup(x => x.Do(200)).Returns(201);
a.InSequence(sequence).Setup(x => x.Do(100)).Returns(103);
Assert.Equal(101, a.Object.Do(100));
Assert.Equal(102, a.Object.Do(100));
Assert.Equal(201, a.Object.Do(200));
Assert.Equal(103, a.Object.Do(100));
}
I'll provide a PR which adds this test, and the corresponding fix.
The text was updated successfully, but these errors were encountered:
When multiple invocations with the same arguments are defined consecutive on a mock, then the last matching method call is used instead of the method call corresponding with the current sequence step.
This is because while scanning for a matching method call, the sequence step is incremented on each match. This causes subsequent method calls with matching arguments - even though their sequence step is higher then the current step - to be considered as candidate.
I've added the following test which currently fails on the first assert (Expected: 101, Actual: 102):
I'll provide a PR which adds this test, and the corresponding fix.
The text was updated successfully, but these errors were encountered: