Rhino Mocks receive argument, modify it and return?
You could use the WhenCalled
method like this:
myStub
.Stub(_ => _.Create(Arg<Invoice>.Is.Anything))
.Return(null) // will be ignored but still the API requires it
.WhenCalled(_ =>
{
var invoice = (Invoice)_.Arguments[0];
invoice.Id = 100;
_.ReturnValue = invoice;
});
and then you can create your stub as such:
Invoice invoice = new Invoice { Id = 5 };
Invoice result = myStub.Create(invoice);
// at this stage result = invoice and invoice.Id = 100
I had no need to add IgnoreArguments() to avoid using Return(). This is my original method:
List<myEntity> GetDataByRange(int pageSize, int offsetRecords);
Here is my mock example:
_Repository.Stub(x => x.GetDataByRange(Arg<int>.Is.Anything, Arg<int>.Is.Anything))
.WhenCalled(x => {
var mylist = entitiesList?.Skip((int)x.Arguments[1])?
.Take((int)x.Arguments[0])?.ToList();
x.ReturnValue = mylist;
});