Why are you stubbing the viewmodel? I would never stub the SUT just
the dependencies.

I guess you need the appointment because the savecommand saves that.
Perhaps you need to make your code more testable. Why are you calling
savecommand.execute(null) (which seems a violation against the law of
demeter) why not straight ds.SaveAppointment(Appointment)? Or just
plain SaveAppointment.

To solve the problem as is I would make viewmodel a mock and not a
stub.

On Feb 12, 6:22 am, Claudio Lassala <[email protected]> wrote:
> Hi all,
>
> I have the following test:
>
>         [TestMethod]
>         public void Save_command_should_save_current_appointment()
>         {
>             var view =
> MockRepository.GenerateStub<IAppointmentEditView>();
>             var editingController =
> MockRepository.GenerateStub<IEditingController>();
>             var dataService =
> MockRepository.GenerateMock<IAppointmentDataService>();
>             var viewModel =
> MockRepository.GenerateStub<AppointmentEditViewModel>(view,
> editingController, dataService);
>
>             var appointment = new AppointmentItem();
>             viewModel.Appointment = appointment;
>
>             viewModel.SaveCommand.Execute(null);
>
>             dataService.AssertWasCalled(ds => ds.SaveAppointment(Arg.Is
> (appointment)));
>         }
>
> the test passes, but there's one thing that bothers me: I want to stub
> out the viewModel.Appointment property, because its setter has some
> logic that I don't want to run in this test. I tried doing something
> like this:
>
> viewModel.Stub(x => x.Appointment).Return(appointment);
>
> but then my test fail at that line, with the following error:
>
> "This action is invalid when the mock object is in replay state."
>
> Am I missing something there?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to