Mock an update method returning a void with Moq

前端 未结 2 856
自闭症患者
自闭症患者 2021-02-01 00:14

In my test, I defined as data a List with some record in.

I\'d like setup a moq the methode Update, this method receive the user <

2条回答
  •  情歌与酒
    2021-02-01 00:56

    Mock _mockUserRepository = new Mock();
            _mockUserRepository.Setup(mr => mr.Update(It.IsAny(), It.IsAny()))
                                .Callback((int id, string name) =>
                                    {
                                        //Your callback method here
                                    });
     //check to see how many times the method was called
     _mockUserRepository.Verify(mr => mr.Update(It.IsAny(), It.IsAny()), Times.Once());
    

提交回复
热议问题