rhino mocks - How can I modify the result of a method call on a mocked object before it is returned? -
given following streamlined example, using rhinomocks , mspec:
[subject(typeof (locationcontroller))] public class when_creating_a_location_with_invalid_model : context_for_location_controller { static locationmodel model = new locationmodel(); static selectlist states = new selectlist(new dictionary<string,string> { { "in", "indiana" }, { "ny", "new york" } }); static actionresult result; establish context = () => { locationmodelbuilder.stub(x => x.build(arg<locationmodel>.is.equal(model))).return(model); } because of = () => result = subject.create(model); should_automatically_select_a_state = () => result.model<locationmodel>() .states.shouldnotbeempty(); }
how can modify object contained in model variable before returned stubbed call of locationmodelbuilder.build()? want perform assignment model.states = states
before return on build(). tried playing do() handler give up...
try using whencalled(). parameter whencalled allows access mocked method's arguments , can set return value.
.whencalled(m => { model model = (model) m.arguments[0]; model.states = ...; });
Comments
Post a Comment