2011-12-01 15 views

Respuesta

82

se puede utilizar el método de WhenCalled así:

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 entonces usted puede crear su talón como tal:

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

Se puede evitar la llamada a return() mediante la adición de IgnoreArguments() al final, creo. – samjudson

+2

@samjudson: Rhino aún arroja una excepción sin Retorno incluso con IgnoreArguments, por lo que se necesita Retorno. –

Cuestiones relacionadas