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

Make System.Object members interceptable by *any* interceptor #764

Merged
merged 2 commits into from
Mar 2, 2019

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Mar 2, 2019

System.Object methods are currently not interceptable if the proxied type is an interface type, and the interceptor used is not an instance of the Mock class. These methods should be interceptable by all interceptors, regardless of their type.

As it happens, this requires the introduction of an IProxy interface which is to IInterceptor what IMocked is to Mock. It works in exactly the same fashion, too.

This PR might seem a bit pointless, since the only implementation of IInterceptor is the Mock class, so at the surface IMocked should suffice.

However, this lays the groundwork for my next PR, which will introduce some new machinery for converting Action<T> delegates back to Expression<Action<T>> (which is important to fix some long-standing bugs with e.g. SetupSet). That PR will require a new interceptor type... so we'll need IProxy anyway.

The failing tests added in this commit demonstrate that `ProxyFactory`
doesn't currently guarantee interceptability of `Object` methods under
all circumstances.

More precisely, `Object` methods are currently not interceptable if:

 * the proxied type is an interface type, and
 * the interceptor used is not an instance of the `Mock` class.
These methods should be interceptable by all interceptors, regardless
of their type. (So far, this only worked for `Mock` interceptors.)
@stakx stakx added this to the 4.11.0 milestone Mar 2, 2019
// All generated proxies need to implement `IProxy`:
var additionalInterfaces = new Type[1 + interfaces.Length];
additionalInterfaces[0] = typeof(IProxy);
Array.Copy(interfaces, 0, additionalInterfaces, 1, interfaces.Length);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a pity that this kind of thing happens twice now; once to add IMocked<T> for Mock, and once here, to add IProxy for IInterceptor. It would be nice to eventually optimize this a little.

@stakx stakx merged commit 346d2e9 into devlooped:master Mar 2, 2019
@stakx stakx deleted the object-members-interceptability branch March 2, 2019 00:27
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