-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
Detect method signature mismatch in Setup
/ Returns
#445
Comments
Hi @ohadschn, thanks for reporting this. I think we should go even further than checking parameter count only; we should also verify parameter and return type compatibility, where applicable. (This is already done for Do you agree? |
Setup
/ Returns
Setup
/ Returns
@stakx Oh, definitely. That's what I meant when I said "at that point it can already check that the signatures don't match". My bad with the issue's title, I fixed it. |
I've implemented the necessary changes (easy enough), but was surprised to learn that several unit tests fail now. Apparently, for So we have an inconsistency in Moq's API that needs to be dealt with, and this means that we should include #105 while we're at it. TL;DR: Fixing this issue is going to take a little longer than expected, because we need to take some other things into consideration. Might have to remove this from the v4.7.next milestone. |
@ohadschn - It's taken me two attempts to arrive at a solution that I think strikes a sensible balance between being doing what's technically correct (validate as much as possible) and being forgiving about certain grey-area real-world use cases. My first attempt (#519) would've introduced strong validation of all delegates passed to The second attempt (#520) therefore introduces validation that is weaker overall, but with the benefit of better compatibility with existing code and no feature switch. In particular, parameter types do not get validated at all. This could be slightly improved upon in the future, but I feel it probably isn't worth the trouble at present. (See additional notes in the PR.) |
Consider the following code:
On runtime, the
Bar()
call will fail withSystem.Reflection.TargetParameterCountException: Parameter count mismatch
. It would be better if it could fail faster, ideally as early as theReturns
call (at that point it can already check that the signatures don't match). A method likeMock<T>.ValidateSetup()
could work too, though you'd have to remember to call it so not as good IMHO.The same goes for
SetupSequence
and possibly others (I'm not well versed in the Moq API).The text was updated successfully, but these errors were encountered: