Moq testing void method

前端 未结 2 2099
别跟我提以往
别跟我提以往 2021-02-19 18:51

Hi I am new to Moq testing and having hard time to do a simple assertion. I am using an interface

 public interface IAdd
 {
     void add(int a, int b);
 }
         


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-19 19:48

    Better to provide more context, but typically it used like this:

    var mockAdd = new Mock();
    mockAdd.Setup(x => x.Add(1, 2)).Verifiable();
    
    //do something here what is using mockAdd.Add
    
    mockAdd.VerifyAll();
    

提交回复
热议问题