Reputation: 122132
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?
Ideally I would like to write something like this:
Expect.Call(delegate {dao.Save(transaction);}).Override(x => x.IsSaved=true);
Does anyone know how to do this?
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:
public delegate void FakeSave(Transaction t);
...
Expect.Call(delegate {dao.Save(t); }).Do( new FakeSave(delegate(Transaction t2) { t.IsSaved = true; }));
Upvotes: 2
Views: 2589
Reputation: 366
Gorge,
The simplest solution, which I found, applied to your question is the following:
Expect.Call(() => dao.Save(transaction))
.Do(new Action<Transaction>(x => x.IsSaved = true));
So you don't need to create a special delegate or anything else. Just use Action which is in standard .NET 3.5 libraries.
Hope this help. Frantisek
Upvotes: 4
Reputation: 60031
You can accomplish this using the Do callback:
Expect.Call(delegate {dao.Save(transaction);})
.Do(x => x.IsSaved = true);
Upvotes: 1
Reputation: 5029
you should mock the transaction and make it return true fo IsSaved, if you can mock the transaction of course.
ITransaction transaction = _Mocker.dynamicMock<ITransaction>;
Expect.Call(transaction.IsSaved).IgnoreArguments.Return(true);
_mocker.ReplayAll();
dao.Save(transaction);
Upvotes: -1