mardi 13 février 2018

Moq - How to call the same setup with different parameters in a loop

I'm having some issues setting up one of my mocks in a test that will ultimately call the setup many times but with different parameters so:

var testMock = new Mock<SomeClass>(MockBehavior.Strict);

for (int i = 30000; i <= 300000; i+=10000)
{
   testMock.Setup(x => x.MethodA(SomeStaticClass.GetIt(varA, varB, i), It.IsAny<int>()))
       .Returns(new List<SomeClass>());
}

So, the above doesn't work. It seems like only the last iteration will be "remembered" by the mock. How can I set up many setups on one mock like I intended to do above?

Aucun commentaire:

Enregistrer un commentaire