LordWilmore
LordWilmore

Reputation: 2912

Moq method Setup without having to specify argument list

When setting up a Moq object to return a specific value regardless of input parameters I currently have to effectively write out the full signature, e.g.

Mock.Get(myThing).Setup(x => x.DoThing(It.IsAny<Int32>(), It.IsAny<String>(), It.IsAny<IEnumerable<Boolean>>())).Returns(false)

This is a little tedious if there are multiple input parameters and I don't care about any of them, so is there a way that I can say It.IsAnyForAllInputParameters()?

Upvotes: 6

Views: 1627

Answers (1)

meJustAndrew
meJustAndrew

Reputation: 6613

As specified in the comment by Bernhard Hiller, if this would be possible, then the moq should know how to setup all the methods with the same name. This should not be a problem, unless they have different return types:

void Sum(int a, int b, ref int result)
{
    result = a + b;
}

int Sum(int a, int b)
{
    return a + b;
}

Then if you want to Setup Sum method to return value 10, how should the moq proceed for the first Sum method?

Upvotes: 1

Related Questions