How to assert that an action was called

前端 未结 2 1443
不思量自难忘°
不思量自难忘° 2021-01-20 21:13

I need to asset an action called by a mock component.

 public interface IDispatcher
    {
     void Invoke(Action action);
    }

    public interface IDial         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-20 22:08

    You need first to put an expectation on your mock. For example I want to test that Invoke is called only once and that I don't care about the incoming parameters.

    mockDispatcher.Expect(m => m.Invoke(null)).IgnoreArguments().Repeat.Once();
    

    Then you have to assert and verify your expectations

    mockDispatcher.VerifyAllExpectations();
    

    you can do it the same way for the second mock, however it's a not good practice to have two mocks per unit test. You should test each in different tests.

    For setting expectations please read http://ayende.com/wiki/Rhino+Mocks+Documentation.ashx

提交回复
热议问题