Hi,
I am using the MVP design for a website I am developing at the
moment. I am hoping that I am using the Mocking framework correctly.
Here is a test I wrote.
[Test]
public void ProjectPresenter_LoadProject_ShouldLoadAProject()
{
//Create mock objects
MockRepository mockRepository = new MockRepository();
IProjectView view = mockRepository.Stub<IProjectView>();
IProjectService service =
mockRepository.StrictMock<IProjectService>();
IRedirector redirector =
mockRepository.StrictMock<IRedirector>();
//Initial SUT
ProjectPresenter presenter = new ProjectPresenter(view,
service, redirector);
//Setup Stub
Guid viewIdentity = Guid.NewGuid();
SetupResult.For(view.Identity).Return(viewIdentity);
view.Mode = DisplayMode.Edit;
//Setup other objects used in test case
Guid id = Guid.NewGuid();
PrefetchPath2 prefetchPath = new PrefetchPath2((int)
EntityType.ProjectEntity)
{
ProjectEntity.PrefetchPathContact,
ProjectEntity.PrefetchPathProjectPaybackPeriod,
ProjectEntity.PrefetchPathProjectCategory
};
ProjectEntity entity = new ProjectEntity
{
Id = id,
Name = "Test Project",
InitiatedBy = "Blair Davidson",
ProjectNumber = "PRJ001",
StartDate = new DateTime(2008, 12, 5),
EndDate = new DateTime(2008, 12, 20),
ProjectedSavingUnitYr = 100,
ProjectedSavingDollarYr = 1000,
Notes = "Test Notes"
};
//Set expectations
Expect.Call(service.FindByIdentity(viewIdentity,
prefetchPath)).Return(entity);
//Move into replay mode
mockRepository.ReplayAll();
//Call SUT
presenter.LoadProject();
//Additional assertions
Assert.AreEqual(entity.ProjectNumber, view.ProjectNumber);
Assert.AreEqual(entity.Name, view.ProjectName);
Assert.AreEqual(entity.InitiatedBy, view.InitiatedBy);
Assert.AreEqual(entity.StartDate, view.StartDate);
Assert.AreEqual(entity.EndDate, view.EndDate);
Assert.AreEqual(entity.ProjectedSavingUnitYr,
view.ProjectedSavingsUnitYear);
Assert.AreEqual(entity.ProjectedSavingDollarYr,
view.ProjectedSavingsDollarYear);
Assert.AreEqual(entity.ActualSavingsUnitYr,
view.ActualSavingsUnitYear);
Assert.AreEqual(entity.ActualSavingsDollarYr,
view.ActualSavingsDollarYear);
Assert.AreEqual(entity.Notes, view.Notes);
Assert.AreEqual(entity.Version, view.Version);
//Verify expectations
mockRepository.VerifyAll();
}
Should I be using the view as a stub and doing state based assertions
as I have done. The reason I am doing this is because I want to make
sure when I find the entity and update the view the values in the view
should be the same as the entity or should i use a dynamic mock and
set expectation on the view being called?
Kind Regards,
Blair Davidson
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---