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

Not able to moq setup 2 different methods with same input parameters #587

Closed
ShashiG88 opened this issue Feb 14, 2018 · 2 comments
Closed

Comments

@ShashiG88
Copy link

One of my method has 2 DB methods -

Method1(string a,int? b) and

Method2(string a, int? b)

I mocked and set up these methods -
objectMock.Setup(b => b.Method1(It.IsAny(), It.IsAny<int())).Returns(true);
objectMock.Setup(a => a.Method2(It.IsAny(), It.IsAny())).Returns(true);

and during the test always only one method is getting invoked by mock object and the 2nd method always hits DB.
And when I performed mockObject.verify(..) receiving the exception
Moq.MockException: '
Expected invocation on the mock at least once, but was never performed: a => a.Method2(It.IsAny(), It.IsAny())

@stakx
Copy link
Contributor

stakx commented Feb 14, 2018

@ShashiG88, impossivle to say what's going wrong without seeing the actual test code. Could you please post a minimal & complete code example that shows how exactly you're invoking these two methods?

@ShashiG88
Copy link
Author

I was able to resolve this .. the method which I was mocking had input parameter nullable int, but during mocking I was passing it as int.
After I change the moccking parameter to same as the method it worked fine...

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