Asserting that a method is called exactly one time

后端 未结 7 1328
无人共我
无人共我 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 03:55

    You can create strict mock, if you want to ensure that a method is called only once.

    var mock = MockRepository.GenerateStrictMock();
    mock.Expect(a => a.Process()).Repeat.Once();
    var helloWorld= new HelloWorld(mock);
    
    helloworld.Process()
    
    mock.VerifyAllExpectations();
    

提交回复
热议问题