#1683·moq

MockSequence doesn't ensure all calls in sequence were executed

Author: jez9999Created Jun 30, 2026Updated Jul 1, 2026
Labelsbug

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