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

Verify an overloaded method with params string[] #603

Closed
dacanizares opened this issue Mar 7, 2018 · 2 comments
Closed

Verify an overloaded method with params string[] #603

dacanizares opened this issue Mar 7, 2018 · 2 comments

Comments

@dacanizares
Copy link

dacanizares commented Mar 7, 2018

It can not explicitly verify this call cause it adds [] and tries to verify an overloaded method, but action calls the one without that param.

CALLED: mock.Verify(m => m.FindAsync(t => t.Id == 1, null, 0, 0), Times.Once);
VERIFIED: mock.Verify(m => m.FindAsync(t => t.Id == 1, null, 0, 0, []), Times.Once);

The methods are:
Task FindAsync(
Expression<Func<T, bool>> filter = null,
Func<IQueryable, IOrderedQueryable> orderBy = null,
int skip = 0,
int take = 0,
params string[] includeProperties);

Task FindAsync(
Expression<Func<T, bool>> filter = null,
Func<IQueryable, IOrderedQueryable> orderBy = null,
int skip = 0,
int take = 0);

Even with a setup it does not work.

@stakx
Copy link
Contributor

stakx commented Mar 7, 2018

The C# compiler will bind the expression m.FindAsync(t => t.Id == 1, null, 0, 0) to the method overload without the includeProperties parameter, so verification should indeed tell you that the overload with includeProperties wasn't called. There's nothing wrong here, as far as I can tell. If you want to call that other overload, e.g. add an additional , new string[0] to the argument list where you call that method.

(If I misunderstood something, please post a small but complete code example that demonstrates the issue; a small failing unit test would be best.)

@stakx stakx closed this as completed Mar 7, 2018
@dacanizares
Copy link
Author

Sorry, my error was this: https://stackoverflow.com/questions/32654730/verifying-moq-method-call-when-used-as-a-base-class-interface

Message: Moq.MockException :
Expected invocation on the mock once, but was 0 times: m => m.FindAsync(t => t.Id == 1, null, 0, 0, [])
No setups configured.

Performed invocations:
IDataStorage`1.FindAsync(t => (t.Id == 1), null, 0, 0)

Thanks anyway!

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

2 participants