public void SaveProjectAs_CanBeCanceled_AAA() { //Arrange IProjectView view = MockRepository.GenerateStrictMock <IProjectView>(); Project prj = new Project("Example Project"); IProjectPresenter presenter = new ProjectPresenter(prj, view); view.Expect(v => v.Title).Return(null); view.Expect(v => v.Ask(Arg <string> .Is.Null, Arg <string> .Is.Null)).Return(null); //Act bool isProjectSave = presenter.SaveProjectAs(); //Assert Assert.IsFalse(isProjectSave); view.VerifyAllExpectations(); }
public void SaveProjectAs_NewNameWithoutConflicts_AAA() { //Arrange MockRepository mocks = new MockRepository(); IProjectView view = mocks.StrictMock <IProjectView>(); IProjectRepository repository = mocks.StrictMock <IProjectRepository>(); IProject prj = mocks.StrictMock <IProject>(); //Component to test IProjectPresenter presenter = new ProjectPresenter(prj, repository, view); string question = "Mock ?"; string answer = "Yes"; string newProjectName = "RhinoMocks"; //Not expected but its necessary for the implementation //We give the property behavior to prj.Name prj.Expect(p => p.Name).PropertyBehavior(); using (mocks.Ordered()) { view.Expect(v => v.Title).Return(prj.Name); view.Expect(v => v.Ask(question, answer)).Return(newProjectName); repository.Expect(r => r.GetProjectByName(newProjectName)).Return(null); view.Title = newProjectName; view.HasChanges = false; repository.SaveProject(prj); } //Act mocks.ReplayAll(); bool isSave = presenter.SaveProjectAs(); //Assert Assert.IsTrue(isSave); Assert.AreEqual(newProjectName, prj.Name); view.VerifyAllExpectations(); repository.VerifyAllExpectations(); prj.VerifyAllExpectations(); }