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

Don't ignore non-public interfaces unconditionally #641

Merged
merged 2 commits into from
Jul 13, 2018

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Jul 13, 2018

This should fix #640. See commit message for details.

This PR does not include the regression test provided by @fgreinacher in that issue, because it would require a [assembly: InternalsVisibleTo(…)] custom attribute in the test project, which in turn would break another test which explicitly requires that attribute to be absent.

I don't think that creating an additional test project just for this one test is warranted.

When mocking a type, Moq currently disregards all its base interfaces
that are declared non-public. This was implemented in 6ad7103 to
prevent DynamicProxy from choking on types inaccessible to it.

This produces some collateral damage concerning `CallBase`: even when
`CallBase == true` on the mock, base methods will not be called if
they are declared in a non-public base interface.

Simply excluding non-public base interfaces is too imprecise, because
if there is a suitable `[assembly: InternalsVisibleTo]` custom attri-
bute for DynamicProxy, then even a non-public interface might be
accessible to DynamicProxy, and the error which the type exclusion
supposedly protects against wouldn't occur in the first place.

So instead of just excluding a non-public base interface, let's simply
*ask* DynamicProxy whether it can access it or not.
@stakx stakx merged commit 2aa193a into devlooped:master Jul 13, 2018
@stakx stakx deleted the callbase branch July 13, 2018 17:37
@stakx stakx added this to the v4.9.0 milestone Jul 13, 2018
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.

Mock<T>.CallBase seems to be broken
1 participant