<p>I have an Enumerable array</p>

<pre><code>int meas[] = new double[] {3, 6, 9, 12, 15, 18};
</code></pre>

<p>On each successive call to the mock's method that I'm testing I want to return a value from that array.</p>

<pre><code>using(_mocks.Record()) {
  Expect.Call(mocked_class.GetValue()).Return(meas); 
}
using(_mocks.Playback()) {
  foreach(var i in meas)
    Assert.AreEqual(i, mocked_class.GetValue();    
}
</code></pre>

<p>Does anyone have an idea how I can do this?</p>

[{'answer_id': 69382, 'author': 'vrdhn', 'author_id': 414441, 'author_profile': 'https://Stackoverflow.com/users/414441', 'pm_score': 0, 'selected': False, 'text': '<p>IMHO, yield will handle this.\n<a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0%28VS.80%29.aspx" rel="nofollow noreferrer">Link</a>.</p>\n\n<p>Something like:</p>\n\n<pre><code>get_next() {\n  foreach( float x in meas ) {\n    yield x;\n  }\n}\n</code></pre>\n'}, {'answer_id': 69426, 'author': 'Gishu', 'author_id': 1695, 'author_profile': 'https://Stackoverflow.com/users/1695', 'pm_score': 0, 'selected': False, 'text': "<p>Any reason why you must have a mock here...<br>\nIf not, I would go for a fake class.. Much Simpler and I know how to get it to do this :) \nI don't know if mock frameworks provide this kind of custom behavior.</p>\n"}, {'answer_id': 69642, 'author': 'Darren', 'author_id': 6065, 'author_profile': 'https://Stackoverflow.com/users/6065', 'pm_score': 1, 'selected': False, 'text': '<p>If the functionality is the GetValue() returns each array element in succession then you should be able to set up multiple expectations eg</p>\n\n<pre><code>using(_mocks.Record()) {\n  Expect.Call(mocked_class.GetValue()).Return(3); \n  Expect.Call(mocked_class.GetValue()).Return(6); \n  Expect.Call(mocked_class.GetValue()).Return(9); \n  Expect.Call(mocked_class.GetValue()).Return(12); \n  Expect.Call(mocked_class.GetValue()).Return(15); \n  Expect.Call(mocked_class.GetValue()).Return(18); \n}\nusing(_mocks.Playback()) {\n  foreach(var i in meas)\n    Assert.AreEqual(i, mocked_class.GetValue();    \n}\n</code></pre>\n\n<p>The mock repository will apply the expectations in order.</p>\n'}, {'answer_id': 69985, 'author': 'bahadorn', 'author_id': 6476, 'author_profile': 'https://Stackoverflow.com/users/6476', 'pm_score': 3, 'selected': True, 'text': "<p>There is alway static fake object, but this question is about rhino-mocks, so I present you with the way I'll do it.\nThe trick is that you create a local variable as the counter, and use it in your anonymous delegate/lambda to keep track of where you are on the array. Notice that I didn't handle the case that GetValue() is called more than 6 times.</p>\n\n<pre><code>var meas = new int[] { 3, 6, 9, 12, 15, 18 };\nusing (mocks.Record())\n{\n    int forMockMethod = 0;\n    SetupResult.For(mocked_class.GetValue()).Do(\n        new Func&lt;int&gt;(() =&gt; meas[forMockMethod++])\n        );\n}\n\nusing(mocks.Playback())\n{\n    foreach (var i in meas)\n        Assert.AreEqual(i, mocked_class.GetValue());\n}\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/69277', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5056/']