Verifying a delegate was called with Moq

后端 未结 4 1258
隐瞒了意图╮
隐瞒了意图╮ 2021-02-11 14:20

i got a class that gets by argument a delegate. This class invokes that delegate, and i want to unit test it with Moq. how do i verify that this method was called ?

exam

4条回答
  •  礼貌的吻别
    2021-02-11 14:55

    What about using an anonymous function? It can act like an inline mock here, you don't need a mocking framework.

    bool isDelegateCalled = false;
    var a = new A(a => { isDelegateCalled = true});
    
    //do something
    Assert.True(isDelegateCalled);
    

提交回复
热议问题