<p>I have a Data Access Object TransactionDao.  When you call TransactionDao.Save(transaction) I would like for it to setting a transaction.IsSaved=true flag (this is a simplification the actual thing I'm trying to do is not quite so banal).  So when mocking my TransactionDao with RhinoMocks how can I indicate that it should transform its input?</p>

<p>Ideally I would like to write something like this:</p>

<pre><code>Expect.Call(delegate {dao.Save(transaction);}).Override(x =&gt; x.IsSaved=true);
</code></pre>

<p>Does anyone know how to do this?</p>

<hr>

<p>Though I got a hint how to do it from the answer specified below the actual type signature is off, you have to do something like this:
Because of what Mark Ingram posted, seems like the best answer, though nobody's explicitly said it, is to do this:</p>

<pre><code>public delegate void FakeSave(Transaction t);
...
Expect.Call(delegate {dao.Save(t); }).Do( new FakeSave(delegate(Transaction t2) { t.IsSaved = true; }));
</code></pre>

[{'answer_id': 59420, 'author': 'chrissie1', 'author_id': 2936, 'author_profile': 'https://Stackoverflow.com/users/2936', 'pm_score': -1, 'selected': False, 'text': '<p>you should mock the transaction and make it return true fo IsSaved, if you can mock the transaction of course.</p>\n\n<pre><code>ITransaction transaction = _Mocker.dynamicMock&lt;ITransaction&gt;;\nExpect.Call(transaction.IsSaved).IgnoreArguments.Return(true);\n_mocker.ReplayAll();\ndao.Save(transaction);\n</code></pre>\n'}, {'answer_id': 59429, 'author': 'Judah Gabriel Himango', 'author_id': 536, 'author_profile': 'https://Stackoverflow.com/users/536', 'pm_score': 1, 'selected': False, 'text': '<p>You can accomplish this using the Do callback:</p>\n\n<pre><code>Expect.Call(delegate {dao.Save(transaction);})\n    .Do(x =&gt; x.IsSaved = true);\n</code></pre>\n'}, {'answer_id': 867435, 'author': 'frantisek', 'author_id': 53332, 'author_profile': 'https://Stackoverflow.com/users/53332', 'pm_score': 3, 'selected': True, 'text': "<p>Gorge, </p>\n\n<p>The simplest solution, which I found, applied to your question  is the following:</p>\n\n<pre><code>Expect.Call(() =&gt; dao.Save(transaction))\n    .Do(new Action&lt;Transaction&gt;(x =&gt; x.IsSaved = true));\n</code></pre>\n\n<p>So you don't need to create a special delegate or anything else. Just use Action which is in standard .NET 3.5 libraries.</p>\n\n<p>Hope this help.\nFrantisek</p>\n"}]
['https://Stackoverflow.com/questions/59396', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5056/']