“Short circuiting” void methods with Moq?

前端 未结 1 1179
别那么骄傲
别那么骄傲 2020-12-29 03:55

my team has made the decision recently to use Moq as our mocking framework for its tremendous flexibility and highly readable syntax. As we\'re new to it, I\'m stumbling on

1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 04:36

    If the SaveItem() method is virtual or abstract, and you're not setting Callbase = true, then the method should be re-implemented to do nothing by the mock.

    You should be able to do:

    mockDb.Setup(d => d.SaveItem(It.IsAny())).Verifiable();
    
    ...  test here ...
    
    mockDb.Verify();
    
        

    0 讨论(0)
    提交回复
    热议问题