Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()?

like image 545
LordWilmore Avatar asked Nov 08 '22 11:11

LordWilmore


1 Answers

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?

like image 138
meJustAndrew Avatar answered Nov 14 '22 23:11

meJustAndrew