I would like to set up a method with Moq twice but it seems that the last one overrides the previous ones. Here\'s my initial setup:
string username = \"foo\";
s
Moq supports this out of box with argument constraints:
mock.Setup(ms => ms.ValidateUser(
It.Is(u => u == username), It.Is(p => p == password))
.Returns(new ValidUserContext { Principal = principal });
mock.Setup(ms => ms.ValidateUser(
It.Is(u => u != username), It.Is(p => p != password))
.Returns(new ValidUserContext());
Catch-all It.IsAny
also works, but the order is important:
// general constraint first so that it doesn't overwrite more specific ones
mock.Setup(ms => ms.ValidateUser(
It.IsAny(), It.IsAny())
.Returns(new ValidUserContext());
mock.Setup(ms => ms.ValidateUser(
It.Is(u => u == username), It.Is(p => p == password))
.Returns(new ValidUserContext { Principal = principal });