Asp.net mvc 3 MOQ-模拟字典<;字符串,双>;对象

Asp.net mvc 3 MOQ-模拟字典<;字符串,双>;对象,asp.net-mvc-3,tdd,moq,Asp.net Mvc 3,Tdd,Moq,我有以下Moq设置: ... other code to setup bigMoq object ... var innerMoq = new Mock<IDictionary<string, double>>(); innerMoq.SetupGet(d => d["COMPLEX"]).Returns(6d); innerMoq.SetupGet(d => d["MEDIUM"]).Returns(8d); innerMoq.SetupGet(d =>

我有以下Moq设置:

... other code to setup bigMoq object ...
var innerMoq = new Mock<IDictionary<string, double>>();
innerMoq.SetupGet(d => d["COMPLEX"]).Returns(6d);
innerMoq.SetupGet(d => d["MEDIUM"]).Returns(8d);
innerMoq.SetupGet(d => d["SIMPLE"]).Returns(10d);
bigMoq.SetupGet(d => d.ComplexityWeights).Returns(x.Object);
然而,这并不是:

bigMoqVar.ComplexityWeights.ContainsKey("COMPLEX")  // returns false instead of true

在innerMoq上支持ContainsKey的推荐方法是什么?

这是因为您没有为
ContainsKey设置期望值。您需要手动设置,Moq不知道接口的语义

innerMoq.Setup(d => d.ContainsKey("COMPLEX")).Returns(true);

但是,如果这只是您需要的
IDictionary
,那么为什么要使用模拟框架呢?只要用你需要的对象创建一个
字典

为什么不使用
字典
?谢谢。我想我是太热衷于使用最小起订量了。相反,创建一本词典非常有效。
innerMoq.Setup(d => d.ContainsKey("COMPLEX")).Returns(true);