Add support for SetupAnyArg and VerifyAnyArg #104

wants to merge 1 commit into


None yet
4 participants

olegoga commented Mar 27, 2014

We use Moq a lot in our team and I find that I spend a lot of time writing the correct It.IsAny() parameters for Verify and Setup methods. I really wanted a simple way match any parameters and created two methods SetupAnyArg and VerifyAnyArg. When they are used, the underlying logic ignores any expression parameters and just matches the method by the signature.

I realize that my current implementation might not be up to the standards of the Moq code-base and maybe I missed some important design principle. If you are interested in integrating this feature, give me some comments and I will gladly make the adjustments.

It would be nice to see some action on this pull request.
I sure also want to get rid of all this annoying It.IsAny writing.

7Pass commented Mar 1, 2016

I've love to have this too. I implemented it as an extension method ( I've tried to create a pull request but could not get the build to work, some error with xdoc:

Mock.Generic.cs(87,7): error CS1735: XML comment on 'Mock<T>.Mock(params object[])' has a typeparamref tag for 'T', but there is no type parameter by that name [Z:\moq4\Source\Moq.csproj]

kzu commented May 24, 2016 edited

I think it's more idiomatic to try to implement this as an extension method on the ISetup interface that fetches the last setup and replaces the matchers. Something like:

mock.Setup(x => x.Execute(null, null, null)).AnyArgs().Verifable();

kzu closed this May 24, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment