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

De-deprecate [Matcher] attribute #732

Merged
merged 6 commits into from
Dec 8, 2018
Merged

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Dec 6, 2018

Fixes #725 (though that is not the only reason behind this change).

@stakx stakx added this to the 4.11.0 milestone Dec 6, 2018
Copy link
Contributor Author

@stakx stakx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of additional explanatory notes.

src/Moq/ExpressionExtensions.cs Show resolved Hide resolved
src/Moq/MatcherAttribute.cs Show resolved Hide resolved
tests/Moq.Tests/ExtensibilityFixture.cs Outdated Show resolved Hide resolved
tests/Moq.Tests/ExtensibilityFixture.cs Show resolved Hide resolved
One of the tests being added here fails because a configured mock is
used as an argument, which Moq executes to find out whether that argu-
ment is a matcher. This is done by means of the `AmbientObserver`,
which has the unfortunate side effect of disabling the argument mock's
setups. Therefore, the expression `data.Id` in `data.Id.Value` will
return `default(Guid?)` instead of the set up value, causing a null
reference exception.
Until now, matchers based on `Match.Create<T>` worked just fine, even
when they were not explicitly marked with a `[Matcher]` attribute (as
an existing XML documentation comment claims is required.)

This introduces a small breaking change by adding the requirement that
*all* matchers must be marked as such using the `[Matcher]` attribute.

This makes it possible for Moq to recognize `Match.Create<T>`-based
matchers statically (i.e. just by inspecting an expression, but with-
out executing it). This means improved runtime performance and allows
us to fix the occasional bug.
@stakx stakx merged commit 233063e into devlooped:master Dec 8, 2018
@stakx stakx deleted the matcherattribute branch December 8, 2018 09:00
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