Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何模拟对象';s索引器与NSU中的私有setter?_.net_Unit Testing_Mocking_Nsubstitute - Fatal编程技术网

.net 如何模拟对象';s索引器与NSU中的私有setter?

.net 如何模拟对象';s索引器与NSU中的私有setter?,.net,unit-testing,mocking,nsubstitute,.net,Unit Testing,Mocking,Nsubstitute,我有一个定义如下的接口 public interface IFoo { object this[string key] { get; } } 如何使用NSubstitute模拟此索引器?调用索引器,然后使用返回: var sub = Substitute.For<IFoo>(); sub["hello"].Returns("world"); var sub=Substitute.For(); sub[“你好”]。返回(“世界”);

我有一个定义如下的接口

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

如何使用NSubstitute模拟此索引器?

调用索引器,然后使用
返回

var sub = Substitute.For<IFoo>();
sub["hello"].Returns("world");
var sub=Substitute.For();
sub[“你好”]。返回(“世界”);