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

Past setups should not be checked after moving on to next sequence steps #27

Open
gmkado opened this issue Oct 9, 2024 · 0 comments
Open

Comments

@gmkado
Copy link

gmkado commented Oct 9, 2024

I'm trying to verify that a call is not made before another call in a sequence. (It is actually made afterwards, not part of what I want to test but is causing the issue).

Here is a repro:

    [Test]
    public void SequenceTest()
    {
        var bar = new Mock<IBar>();
        var baz = new Mock<IBaz>();
        var sut = new Foo(bar.Object, baz.Object);
        using (Sequence.Create())
        {
            baz.Setup(x => x.DoBazThings()).InSequence(Times.Never());
            bar.Setup(x => x.DoBarThings()).InSequence(Times.Once());
            // baz.Setup(x => x.DoBazThings()).InSequence(Times.Once()); // uncomment this to make this test pass

            sut.DoTheThing();
        }
    }

    public interface IBar
    {
        void DoBarThings();
    }

    public interface IBaz
    {
        void DoBazThings();
    }

    private class Foo
    {
        private readonly IBar _bar;
        private readonly IBaz _baz;

        public Foo(IBar bar, IBaz baz)
        {
            _bar = bar;
            _baz = baz;
        }

        public void DoTheThing()
        {
            _bar.DoBarThings();
            _baz.DoBazThings();
        }
    }

This currently fails with:

Moq.Sequences.SequenceException : Exceeded maximum number of invocations.
Expected invocation on the mock should never have been performed, but was 1 times: 'x => x.DoBazThings()'

I would expect that once a condition for a sequence has been completed that it would stop checking it, like when DoBarThings is called, the requirement that DoBazThings is never called would be "cleared".

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

1 participant