title: Mocking collections with Rhino Mocks
body: <p>So this is something I guess many people want to do, mock a collection.  In the past with Rhino I have done this with something like:</p>
  
  <pre><code>var col_mock = MockRepository.GenerateMock&lt;ICustomCollection&gt;(); // returns ICustom let's say
  List&lt;ICustom&gt; col_real = new List&lt;ICustom&gt;();
  col_real.Add(custom_mock1);
  col_real.Add(custom_mock2);
  col_real.Add(custom_mock3);
  col_mock.Stub(x =&gt; x.GetEnumerator()).Return(col_real.GetEnumerator());
  </code></pre>
  
  <p>So yup this works fine, when you foreach col_mock you get the mocked (custom_mock1 etc.) objects back. Great! We have successfully mocked a custom collection by using a typed list to actually store a load of mocked objects.</p>
  
  <p>The problem is, you can only do this once! you can only foreach this collection once.  Does anyone know (without creating an actual custom collection...) how I can achieve the mocking of a custom collection which can be iterated more than once?</p>