Asserting that a method is called exactly one time

后端 未结 7 1325
无人共我
无人共我 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    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.

提交回复
热议问题