title: Trying to create Moq object
body: <p>I've got a method which takes a <code>IList&lt;Person&gt;</code> and returns an IEnumberable as so:</p>
  
  <pre><code> internal static IEnumerable&lt;Dictionary&lt;string, string&gt;&gt; GetPersonsPerSite(IList&lt;Person&gt; Data)
      { 
           //Implementation ...
      }
  </code></pre>
  
  <p>and I'm trying to create a mock object of <code>IList&lt;Person&gt;</code> so I can test this method.</p>
  
  <p>Using Moq I have written the following:</p>
  
  <p><code>var mockObjects = new Mock&lt;IList&lt;Person&gt;&gt;();</code></p>
  
  <pre><code>mockObjects.Setup(x =&gt; x[0]).Returns(new Person()
                                                   {
                                                          SITE_ID = "test",
                                                          MPAN = "test",
                                                          ADDLINE1 = "test",
                                                          ADDLINE2 = "test",
                                                          ADDRESS_LINE_1 = "test",
                                                          ADDRESS_LINE_2 = "test"
                                                   });
  </code></pre>
  
  <p>However when I come to use the object the IEnumerable returned is aways throwing exception <code>Object reference not set to an instance of an object.</code></p>
  
  <p>I'm brand new to Moq, and I'm pretty sure I'm missing a fundamental concept here, however I've successfully being able to throw exceptions and modifiy outputs with other mock objects.</p>
  
  <p>I'd appreciate if someone could point me in the right direction.</p>