如何为索引器属性设置模拟?

时间:2019-02-08 07:54:29

标签: c# properties installation mocking moq

我不是模拟专家,但是我知道模拟的优点。我遇到一个有接口的问题,您可以在下面看到它。我想以正确的方式设置此接口的get属性。

public interface IInterface
{
    string this[string key] { get; }
}

我尝试过这样的事情:

Mock<IInterface> mockInterface = new Mock<IInterface();
mockInterface.SetupGet(mockInterface.Object).Returns("Test"); 

但是出现以下错误:

  

错误CS0411无法从用法中推断出方法'Mock.SetupGet(Expression>)'的类型参数。尝试显式指定类型参数。

您能给我一些有关此问题的建议或解决方案吗?

0 个答案:

没有答案