title: How to MOQ an Indexed property
body: <p>I am attempting to mock a call to an indexed property. I.e. I would like to moq the following:</p>
  
  <pre><code>object result = myDictionaryCollection["SomeKeyValue"];
  </code></pre>
  
  <p>and also the setter value</p>
  
  <pre><code>myDictionaryCollection["SomeKeyValue"] = myNewValue;
  </code></pre>
  
  <p>I am doing this because I need to mock the functionality of a class my app uses. </p>
  
  <p>Does anyone know how to do this with MOQ? I've tried variations on the following:</p>
  
  <pre><code>Dictionary&lt;string, object&gt; MyContainer = new Dictionary&lt;string, object&gt;();
  mock.ExpectGet&lt;object&gt;( p =&gt; p[It.IsAny&lt;string&gt;()]).Returns(MyContainer[(string s)]);
  </code></pre>
  
  <p>But that doesn't compile.</p>
  
  <p>Is what I am trying to achieve possible with MOQ, does anyone have any examples of how I can do this?</p>