Say I have a reference to a service called myService. It has a method called MyMethod which takes an int parameter.
Using Moq, I want to test a particular scenario that means MyMethod is called once with a specific value (let's say it's 3) and to also ensure that no other call is made.
If I wrote:
myService.Verify(o => o.MyMethod(It.IsAny<int>()), Times.Once);
Then this would ensure the method was only called once but I do not know if it was called with 3.
If I wrote:
myService.Verify(o => o.MyMethod(3), Times.Once);
Then this would ensure the method was only called once with 3 but I do not know if it was called any other times with values other than 3.
So, if I want to ensure both that it was only called once with a 3 and it was not called any other times then I would need to have two Verify calls like this:
myService.Verify(o => o.MyMethod(3), Times.Once);
myService.Verify(o => o.MyMethod(It.IsAny<int>()), Times.Once);
Is there any Moq convention that allows me to achieve the same thing with just one Verify call?