c# .net rhino-mocks

c# - Rhino Mocks recibe un argumento, lo modifica y lo devuelve?



.net rhino-mocks (1)

Estoy tratando de escribir algo como esto:

myStub.Stub(_ => _.Create(Arg<Invoice>.It.Anything)).Callback(i => { i.Id = 100; return i; });

Quiero obtener el objeto real que pasó para simular, modificarlo y regresar.

¿Es posible este escenario con Rhino Mocks?


Puede usar el método WhenCalled como este:

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; });

y luego puedes crear tu stub como tal:

Invoice invoice = new Invoice { Id = 5 }; Invoice result = myStub.Create(invoice); // at this stage result = invoice and invoice.Id = 100