-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
Specify a mock return regardless of parameters passed into the method call #226
Comments
That's the purpose of See https://github.com/Moq/moq4/wiki/Quickstart#matching-arguments |
I know about It.IsAny already but that requires specifying per parameter. I was wondering if there is any possibility of a feature that allows similar functionality without relying on specifying each parameter via It.IsAny. |
In other words, given these methods:
And then performing a setup as mentioned:
Would be (more or less) equivalent to:
|
That's the idea exactly, thanks for the example. |
I don't think there's a lot of value in that, especially since it will break badly if you add overloads of Add that have a different return value. And you lose the ability to refactor your APIs since now those "magic strings" will get out of date. So, too many drawbacks to save a couple lines of code. |
@kzu In general I agree, though the |
That would only give you the name of one of the overloads. If you happen to On Mon, Dec 14, 2015 at 10:58 AM Patrick Quirk notifications@github.com
|
This would really help for mocking Microsoft methods because they love to put in option params with a default of null |
@j03INTHECLOUD there is nothing stopping you from creating an extension method on |
Would it be possible to implement a feature that allows a test to contain a mock setup that specifies a return regardless of the passed in parameters, something along the lines of "mock.SetupMethodsNamed("Add").Returns(5);"?
I asked if the feature already existed here and was prompted to open an issue.
The text was updated successfully, but these errors were encountered: