When running this test
Sprint s = new Sprint();
ValidationResult<Sprint> result = new ValidationResult<Sprint>();
result.Result = true; using(mocks.Unordered())
{
Expect.On(sprintRepository).Call(sprintRepository.Save(s)).Return(result);
Expect.On(view).Call(view.ErrorMessage).PropertyBehavior().Return(string.Empty);
}
mocks.ReplayAll();
presenter.SaveSprint();
mocks.VerifyAll();
I ran across this exception
Rhino.Mocks.Exceptions.ExpectationViolationException: ISprintRepository.Save(SprintVelocity.Domain.Sprint); Expected #0, Actual #1.
ISprintRepository.Save(SprintVelocity.Domain.Sprint); Expected #1, Actual #0.
I took some time to research this problem and I found some other interesting things in the process. First of all the reason of this error is because of the Sprint object is different in the SaveSprint() method than the Sprint object in the test. This was fixed by using the IgnoreArguments() method. It's a rookie mistake, but hey someone got to own up to it so you can find the solution right.
It's hard to tell that from the error messages, which leads into one of my discoveries while fixing this:
Override the ToString method to get better messages.
If I override ToString in the Sprint Class, the previous exception becomes this:
Rhino.Mocks.Exceptions.ExpectationViolationException: ISprintRepository.Update(Sprint: ID=0;ProjectId=1; Description=description; Start-Date:2007-09-04 00:09; End-Date=2007-09-04 14:09
); Expected #0, Actual #1.
ISprintRepository.Update(Sprint: ID=0;ProjectId=null; Description=; Start-Date:0001-01-01 00:00; End-Date=0001-01-01 00:00
); Expected #1, Actual #0.
Now I know what is happening and how to fix it.
The other new discovery is that you can put Rhino Logging messages into the output. Add the following lines to you SetUp method and you will get Rhino Mocks logging messages in the console.
.Logger = new TextWriterExpectationLogger(Console.Out);
Resharper's TestRunner puts this in the same output as the results, so it's easy to see where Rhino blew up.
Recorded expectation: ISprintRepository.Update(Sprint: ID=0;ProjectId=null; Description=; Start-Date:0001-01-01 00:00; End-Date=0001-01-01 00:00
);
Recorded expectation: ISprintFormView.get_ErrorMessage();
Unexpected method call error: ISprintRepository.Update(Sprint: ID=0;ProjectId=1; Description=description; Start-Date:2007-09-04 00:09; End-Date=2007-09-04 14:09
);
Anyway, those are my Rhino Mock epiphanies for the week. I hope they help someone else.
Cheers,