我有一个要尝试使用最小起订量模拟的对象。对象的构造函数具有必需的参数:
public class CustomerSyncEngine {
public CustomerSyncEngine(ILoggingProvider loggingProvider,
ICrmProvider crmProvider,
ICacheProvider cacheProvider) { ... }
}
现在,我正在尝试使用moq的v3“设置”或v4“ Mock.Of”语法为此对象创建模拟,但无法弄清楚……我尝试的所有操作均未通过验证。这是我到目前为止的内容,但是最后一行是给我一个真实的对象,而不是模拟对象。我这样做的原因是因为我要验证的CustomerSyncEngine上有一些方法正在被调用...
// setup
var mockCrm = Mock.Of<ICrmProvider>(x => x.GetPickLists() == crmPickLists);
var mockCache = Mock.Of<ICacheProvider>(x => x.GetPickLists() == cachePickLists);
var mockLogger = Mock.Of<ILoggingProvider>();
// need to mock the following, not create a real class like this...
var syncEngine = new CustomerSyncEngine(mockLogger, mockCrm, mockCache);