我有下一个界面
public interface IMyInterface
{
string this[string key] { get; set; }
}
我想在我的测试中实现get/set
var _Nvp = //...
var mockMyInterface = new Mock<IMyInterface>();
mockMyInterface
.Setup(e => e[It.IsAny<string>()])
.Returns((string key) => _Nvp[key]);
mockMyInterface
.SetupSet(c => c[It.IsAny<string>()] = It.IsAny<string>())
.Callback((string key, string value) => { _Nvp[key] = value; }));
但它不起作用..没有错误,没有消息..
var oj = mockMyInterface.Object;
oj["key"] = "value";
var value = oj["key"];
变量值始终为空。