Add WillReceive.InOrder() for evaluating call sequence expectations at execution time #863
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces
WillReceive.InOrder()
to solve the issue where mutable objects lead to false negatives in ordered call verifications. The core problem is thatReceived.InOrder()
evaluates argument matchers at verification time instead of call time, causing tests to fail when object references are modified during test execution.This addresses the long-standing issue #392 and implements the solution I proposed in #861.
The syntax of this feature:
Produces clear error messages showing the exact point of failure:
The goal was to provide a solution that evaluates argument matchers at the time of the call while staying close to NSubstitute's existing syntax. Instead of capturing object states or requiring manual workarounds, the implementation directly solves the timing issue without compromising NSubstitute's simple and intuitive API style.
Let me know if you'd like me to make any adjustments to the implementation or tests.