How to trick an object indexer with a private setter in NSubstitute?

I have an interface that is defined like this

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

      

How can I mock this indexer with NSubstitute?

+3


source to share


1 answer


Call the indexer, then use Returns

:



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

      

+6


source







All Articles