title: Using Moq With Word Interop collections
body: <p>I have a class that takes an Interop.Word.Range object and creates a list from it. I'm trying to create a test that specifically tests the Bookmarks in the range. Therefore, I'm trying to mock this.</p>
  
  <pre><code>// this works
  var mockBookmark = new Mock&lt;Word::Bookmark&gt;();
  mockBookmark.Setup(b =&gt; b.Name).Returns("A Bookmark");
  var bm1 = mockBookmark.Object;
  // this works
  var mockRange = new Mock&lt;Word::Range&gt;();
  mockRange.Setup(f =&gt; f.Text).Returns("This is the text");
  mockRange.Setup(f =&gt; f.Bookmarks).Returns(bookmarks);
  var range = mockRange.Object;
  // this doesn't
  var mockBookmarks = new Mock&lt;Word::Bookmarks&gt;();
  mockBookmarks.SetupGet(b =&gt; b[It.IsAny&lt;string&gt;()]).Returns(bm1);
  var bookmarks = mockBookmarks.Object;
  </code></pre>
  
  <p>But no matter what I put in that b[It.IsAny()] (I've tried ints, strings, and wildcards) call I get </p>
  
  <pre><code>Failure: Setup: System.IndexOutOfRangeException: Index was outside the bounds of the array 
  </code></pre>
  
  <p>on that line. I thought the whole point of mocking was that YOU'RE defining the bounds of the array, but apparently something isn't clicking for me.</p>
  
  <p>I'm certainly willing to entertain the possibility that I'm going at this completely the wrong way, but I need to be able to define a Range that contains multiple Bookmark objects that have different names, as that's what I'm testing.</p>