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

Enable FluentMockContext to record >1 matcher per invocation #722

Merged
merged 5 commits into from
Nov 11, 2018

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Nov 11, 2018

Moq currently cannot correctly deal with setter setups using more one matcher, e.g. when setting up an indexer's setter. This is because the FluentMockContext only associates at most one matcher with observed invocations.

This PR changes how FluentMockContext records its observations and how it lets the outside world access them. When asked for the last observed mock invocation, FluentMockContext now returns all
matchers observed immediately before the final invocation.

The class is also renamed to AmbientObserver (way too many things in Moq's code base are called "fluent") and documented somewhat better using XML documentation comments and tests.

Moq currently cannot correctly deal with setter setups using more one
matcher, e.g. when setting up an indexer's setter. This is because the
`FluentMockContext` only associates at most one matcher with observed
invocations.

This commit changes how `FluentMockContext` records its observations
and how it lets the outside world access them. When asked for the last
observed mock invocation, `FluentMockContext` now returns *all*
matchers observed immediately before the final invocation.
Way too many things in Moq's code base are referred to as "fluent".
Let's try to give this component a somewhat more descriptive name.
src/Moq/AmbientObserver.cs Outdated Show resolved Hide resolved
 * Add static `Activate` method that client code uses instead of the
   ctor; so that there is better symmetry with `IsActive`.

 * Abbreviate method names to `LastIsInvocation`, `LastIsMatch`, also
   to mirror `OnInvocation`, `OnMatch` more closely.

 * Introduce `expression.IsMatch` helper method that abstracts away a
   `AmbientObserver` usage pattern repeated 3x across the code base.
@stakx stakx merged commit ce4240a into devlooped:master Nov 11, 2018
@stakx stakx deleted the fluentmockcontext branch November 11, 2018 17:54
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

Successfully merging this pull request may close these issues.

None yet

1 participant