Asserting that a method is called exactly one time

后端 未结 7 1324
无人共我
无人共我 2021-02-05 03:16

I want to assert that a method is called exactly one time. I\'m using RhinoMocks 3.5.

Here\'s what I thought would work:



        
相关标签:
7条回答
  • 2021-02-05 04:04

    You can pass a delegate to WhenCalled to count calls:

    ...
    uint callCount = 0;
    source.Expect(x => x.GetSomethingThatTakesALotOfResources(key))
        .Return(new Something())
        .WhenCalled((y) => { callCount++; });
    ...
    Assert.AreEqual(1, callCount);
    

    Also, you should use a mock not a stub, and verify expectations on the mock too.

    0 讨论(0)
提交回复
热议问题