Andrew Stakhov
Andrew Stakhov

Reputation: 1135

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?

Upvotes: 7

Views: 2317

Answers (1)

David Tchepak
David Tchepak

Reputation: 10464

Call the indexer then use Returns:

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

Upvotes: 14

Related Questions