You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(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.
The text was updated successfully, but these errors were encountered:
This is a meta-issue that essentially covers the following previous issues:
VerifyAll
fail #556 -Recursive setup expression creates ghost setups that make(fixed by MakeVerifyAll
failVerifyAll
ignore setups fromSetupAllProperties
#684)(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 asIt.IsAny
get "erased". Additionally, in order forMockBehavior.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.
The text was updated successfully, but these errors were encountered: