Moq to set up a function return based on called times

前端 未结 3 394
孤城傲影
孤城傲影 2021-01-01 11:34

I need to mock an interface to call to MSMQ, is there a way I can use Moq to simulate real MSMQ scenario that there are 10 messages in the queue, I call mocked function 10 t

3条回答
  •  渐次进展
    2021-01-01 12:34

    You can also set up a separate function to do this. You can even pass the function a parameter if you want:

    _serviceMock.Setup(x => x.SomeMethod(It.IsAny())).Returns((String param) => getTimesCalled(param));
    

提交回复
热议问题