7

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?

Andrew Stakhov
  • 1,105
  • 8
  • 26

1 Answers1

14

Call the indexer then use Returns:

var sub = Substitute.For<IFoo>();
sub["hello"].Returns("world");
David Tchepak
  • 9,826
  • 2
  • 56
  • 68