devlooped / devlooped/moq

MockSequence doesn't ensure all calls in sequence were executed

Open
#1,683 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
6.4k
Forks
835
PR merge metrics
No merged PRs in 30d

Description

Describe the Bug

I'm testing that a helper I wrote calls a lambda with specific arguments in a specific order, which is what MockSequence is supposed to enforce. However, I don't get an exception if I add Setup steps to the sequence that are not called. I want that to be flagged as a failure.

Steps to Reproduce

	[Test]
	public void Move_B_C_H_before_F_in_given_order() {
		var input = new List<char> { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };

		var mock = new Mock<Action<int, int>>(MockBehavior.Strict);
		var seq = new MockSequence();
		mock.InSequence(seq).Setup(x => x(7, 5));
		mock.InSequence(seq).Setup(x => x(1, 5));
		mock.InSequence(seq).Setup(x => x(1, 5));
		mock.InSequence(seq).Setup(x => x(2, 5));

		ReorderingHelper.ReorderPages(
			[7, 1, 2],
			5,
			mock.Object,
			orderSelectedIndicesAscending: false
		);

		// ^ passes, but was not called with 2,5!
	}

Expected Behavior

The test should fail unless all specified setups in the sequence were called.

Back this issue
Back this issue

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with MockSequence and the InSequence setup behavior, then reproduce the issue using the provided Move_B_C_H_before_F_in_given_order test case. Done means a sequence with an uncalled setup fails, while sequences whose setups are all called continue to work and the existing test suite passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.