c# - Can I define implementation of methods on Rhino Mocked objects? -
with rhino.mocks, once mock interface can:
- set "return" values non void methods on mocked object
- inspect how , values methods called with
however, possible selectively define implementation methods on mocked objects?
ideally i'd (rhinoimplement rhino extension i'm hoping exists!):
var messages = new list<imessage>(); ibus bus = mockrepository.generatemock<ibus>(); bus.rhinoimplement(b => b.send(arg<imessage>.is.anything), imess => messages.add(imess)); //now run test on class uses ibus //now, can inspect local (list<imessage>)messages collection
update answer
thanks patrick's answer below, correct code achieve above is:
var messages = new list<imessage>(); ibus bus = mockrepository.generatemock<ibus>(); bus .expect(b => b.send(arg<imessage>.is.anything)) .whencalled(invocation => messages.add((imessage)invocation.arguments[0])) .repeat.any() //the repeat part because method might called multiple times //now run test on class uses ibus //now, can inspect local (list<imessage>)messages collection
use "whencalled" method:
Comments
Post a Comment