Reset mock verification in Moq?

前端 未结 8 1699
执笔经年
执笔经年 2021-02-11 12:01

Setup as so:

public interface IFoo
{
    void Fizz();
}

[Test]
public void A()
{
    var foo = new Mock(MockBehavior.Loose);

    foo.Object.Fizz();         


        
8条回答
  •  粉色の甜心
    2021-02-11 12:34

    You could use the Callback method instead of Verify, and count the calls.

    This is demonstrated on the Moq Quick Start page, thus:

    // returning different values on each invocation
    var mock = new Mock();
    var calls = 0;
    mock.Setup(foo => foo.GetCountThing())
        .Returns(() => calls)
        .Callback(() => calls++);
    // returns 0 on first invocation, 1 on the next, and so on
    Console.WriteLine(mock.Object.GetCountThing());
    

提交回复
热议问题