Skip to content

MockSequence doesn't ensure all calls in sequence were executed #1683

Description

@jez9999

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions