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

Improve method match accuracy in ExtractProxyCall #415

Merged
merged 1 commit into from
Jul 12, 2017

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Jul 12, 2017

If you're setting up methods in a type hierarchy (e.g. Base.Method and Derived.Method), the setup order currently matters, even though two different methods are set up.

This commits is a first step in making Moq associate the "right" setup with a proxy method invocation. This will make sure that if there are several setups that potentially match an invocation, it will attempt to pick the one for the exact same method.

This is only a start, but probably still not good enough in all situations (for example, for overridden methods, the distance of the inheritance relationship is not taken into account).

This should fix #131.

/cc @dcastro, @pjquirk

If you're setting up methods in a type hierarchy (e.g. `Base.Method`
and `Derived.Method`), the setup order currently matters, even though
two different methods are set up.

This commits is a first step in making Moq associate the "right" setup
with a proxy method invocation. This will make sure that if there are
several setups that potentially match an invocation, it will attempt
to pick the one for the exact same method.

This is only a start, but probably still not good enough in all
situations (for example, for overridden methods, the distance of the
inheritance relationship is not taken into account).
}
}
localctx.Call = lastMatchingSetupForSameMethod ?? lastMatchingSetup;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

At first glance, this looks much more involved than a simple LastOrDefault, but it has the advantage of only performing a single enumeration over ctx.OrderedCalls while looking for two different items.

@stakx stakx merged commit 9f65584 into devlooped:develop Jul 12, 2017
@stakx stakx deleted the setup-order branch July 12, 2017 11:07
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