MockSequence doesn't ensure all calls in sequence were executed
Nobody has claimed this yet.
- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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
