Verifying a delegate was called with Moq

后端 未结 4 1259
隐瞒了意图╮
隐瞒了意图╮ 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:46

    You can do something like that:

     public interface IWithFOOMethod
     {
         void FooAlikeMethod(int number);
     }
    
     Mock myMock = new Mock();
    
     A a = new A(myMock.Object.FooAlikeMethod);
    
     myMock.Verify(call => call.Foo(It.IsAny()), Times.Once())
    

提交回复
热议问题