Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mock object's indexer with private setter in NSubstitute?

I have an interface that is defined like the following

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

How can I mock this indexer using NSubstitute?

like image 427
Andrew Stakhov Avatar asked Aug 26 '14 01:08

Andrew Stakhov


1 Answers

Call the indexer then use Returns:

var sub = Substitute.For<IFoo>();
sub["hello"].Returns("world");
like image 107
David Tchepak Avatar answered Oct 19 '22 23:10

David Tchepak