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

When throwing a MockException under Strict mode it would be beneficial to indicate any generic parameters used #176

Closed
hasaki opened this issue Jun 7, 2015 · 0 comments

Comments

@hasaki
Copy link
Contributor

hasaki commented Jun 7, 2015

What I mean by this is that I've been struggling with a MockException thrown stating:

Moq.MockException : DbDataReader.GetFieldValueAsync(0, System.Threading.CancellationToken) invocation failed with mock behavior Strict.
All invocations on the mock must have a corresponding setup.

I was getting this exception despite quite clearly having set up that method in my testing suite.

In the end the issue was caused because DbDataReader.GetFieldValueAsync is actually defined as:
DbDataReader.GetFieldValueAsync<TResult>.

Keeping to a DRY principle when writing my test, rather than write 8 setup calls, i threw everything into an array and used that....not thinking that by doing so I was changing the specialization of the calls from string, DateTime, etc to object.

If the message were to indicate the generic specialization it was looking for when throwing the exception, it would make debugging such errors much easier to find.

hasaki added a commit to hasaki/moq4 that referenced this issue Jun 7, 2015
Adds type information for a generic method to the exception output,
making it easier to debug issues where passed arguments may match, but
the generic parameters do not. Fixes devlooped#176
hasaki added a commit to hasaki/moq4 that referenced this issue Jun 7, 2015
@kzu kzu closed this as completed in #177 Jun 8, 2015
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

No branches or pull requests

1 participant