Different return values the first and second time with Moq

后端 未结 7 631
感动是毒
感动是毒 2021-01-29 18:51

I have a test like this:

    [TestCase("~/page/myaction")]
    public void Page_With_Custom_Action(string pat         


        
7条回答
  •  悲&欢浪女
    2021-01-29 19:10

    Now you can use SetupSequence. See this post.

    var mock = new Mock();
    mock.SetupSequence(f => f.GetCount())
        .Returns(3)  // will be returned on 1st invocation
        .Returns(2)  // will be returned on 2nd invocation
        .Returns(1)  // will be returned on 3rd invocation
        .Returns(0)  // will be returned on 4th invocation
        .Throws(new InvalidOperationException());  // will be thrown on 5th invocation
    

提交回复
热议问题