每个方法调用的安装回调都使用MOQ

时间:2012-04-27 13:44:31

标签: c# .net moq

有没有办法在没有设置每个方法的情况下将回调附加到模拟的每个方法? E.g。

var serviceMock = new Mock<IService>();    
var count = 0;

//method does not exist, but you get the picture
serviceMock.CallbackAllMethods( () => { count++; throw new WebException()}; ) 

1 个答案:

答案 0 :(得分:1)

AutoFixture与Moq很好地集成,并会自动设置这样的方法。

有一个很好的介绍here on Mark Seemann's blog

相关问题