Add WillReceive.InOrder() for evaluating call sequence expectations at execution time#863
Add WillReceive.InOrder() for evaluating call sequence expectations at execution time#863loop8ack wants to merge 1 commit intonsubstitute:mainfrom
Conversation
|
I discovered a significant limitation with the current implementation: Because it uses // This configuration won't affect calls inside WhileExecuting
action.When(x => x.SomeMethod()).Do(_ => /* ... */);
WillReceive
.InOrder(() => /* ... */)
.WhileExecuting(() =>
{
// The configured callback won't be executed here
action.SomeMethod();
});This is a significant limitation as it prevents using configured mocks together with this new feature. I currently don't have a solution for this and would appreciate suggestions on how to properly integrate with NSubstitute's routing system. |
|
Had a quick look at this but haven't come up with a good answer sorry. :( Not sure if it is possible, but maybe look at running the expectation building in query, and run the actions themselves using normal nsub routing but adjust the call handling to check with the expectations first? (so it functions more like a standard disclaimer: no idea if this would work, just one idea to look at if you're stuck |
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.