【问题标题】:How to mock object's indexer with private setter in NSubstitute?如何在 NSubstitute 中使用私有设置器模拟对象的索引器?
【发布时间】:2014-10-19 05:54:07
【问题描述】:

我有一个定义如下的接口

 public interface IFoo
    {
        object this[string key] { get; }
    }

如何使用 NSubstitute 模拟这个索引器?

【问题讨论】:

    标签: .net unit-testing mocking nsubstitute


    【解决方案1】:

    调用索引器然后使用Returns

    var sub = Substitute.For<IFoo>();
    sub["hello"].Returns("world");
    

    【讨论】:

      猜你喜欢
      • 2015-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多