Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve processing of multi-dot (also called "fluent" or "recursive") setup expressions #643

Closed
5 tasks done
stakx opened this issue Jul 13, 2018 · 1 comment
Closed
5 tasks done
Assignees
Milestone

Comments

@stakx
Copy link
Contributor

stakx commented Jul 13, 2018

This is a meta-issue that essentially covers the following previous issues:

(I will close all of the above issues in favor of this one here.)

All of these are caused by the way Moq processes multi-dot setup expressions: It compiles the expression and executes them with MockBehavior.Mock temporarily enabled to create the whole object graph leading to the right-most object. Compilation means that matchers such as It.IsAny get "erased". Additionally, in order for MockBehavior.Mock to work, SetupAllProperties is executed at every step in the chain, which can cause previous setups to be "forgotten".

Instead of brute-forcing our way to the right-most object using the above approach, it would be better to actually split multi-dot expressions, let each mock handle a segment, and pass the remaining subexpression on to an "inner" mock. This would mean no compilation (making setup both faster and preserving matchers), and less overridden / forgotten setups, too.

Getting the multi-dot setup expression parsing to work is fairly easy, however replacing the current implementation in a way that doesn't introduce breaking changes is hard. What's additionally needed is a thorough set of regression tests that thoroughly cover the current behavior.

@stakx
Copy link
Contributor Author

stakx commented Mar 10, 2019

All done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant