I thought of stubbing the SUT because I don't want any logic to run on
either setter or getter of that Appointment property. I tried to mock
the viewmodel, but that yields the same error.
this is a ViewModel for a WPF app. SaveCommand is an ICommand, and
WPF's databinding is being used here to bind a UI control to that
Command property. I call SaveCommand.Execute(null) because that's what
WPF is going to call when the user presses the button that's bound to
that command.
SaveCommand calls a private OnSave command on the viewmodel, that does
the following:
void OnSave(object parm)
{
m_DataService.SaveAppointment(Appointment);
m_Controller.EditComplete(this);
}
so the test is checking to make sure the current appointment gets
saved when the SaveCommand is invoked.
So you know, the code under test here comes from a magazine article on
Prism. In order to dig more into Rhino Mocks, I've decided to grab
that sample code and write tests for it. Of course, since that's
sample code, I'm having to refactor things there (for instance,
passing interfaces around, instead of concrete types, and things like
that). I'm definitely taking any suggestions to improve this. :)
Thanks!
On Feb 12, 1:50 am, chrissie1 <[email protected]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---