犀牛嘲讽收到的参数,修改它,并返回?
我试图写这样的东西:
myStub.Stub(_ => _.Create(Arg<Invoice>.It.Anything)).Callback(i => { i.Id = 100; return i; });
我想获得传递给模拟的实际对象,修改它并返回。
这种情况是可能的与犀牛嘲笑?
你可以像这样使用WhenCalled
方法:
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; });
然后你可以创build你的存根:
Invoice invoice = new Invoice { Id = 5 }; Invoice result = myStub.Create(invoice); // at this stage result = invoice and invoice.Id = 100