Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordered call issue with invocations with same arguments in MockSequence #96

Closed
drieseng opened this issue Feb 19, 2014 · 1 comment
Closed

Comments

@drieseng
Copy link
Contributor

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.

@kzu
Copy link
Member

kzu commented Feb 20, 2014

@jdom could you review this quickly?

@kzu kzu closed this as completed May 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants