public void Delete_should_stay_on_same_page_if_there_is_a_data_exception() { var repositoryStub = MockRepository.GenerateStub<IGlossaryTermRepository>(); repositoryStub.Expect(m => m.Delete(null)).IgnoreArguments().Throw(new DataException()); var controller = new GlossaryTermController(repositoryStub); var result = (RedirectToRouteResult) controller.DeleteConfirmed(1); Assert.AreEqual("Delete", result.RouteValues["action"]); }
public void Create_should_display_error_message_if_there_is_a_data_exception() { var repositoryStub = MockRepository.GenerateStub<IGlossaryTermRepository>(); var glossaryTermCausingError = new GlossaryTerm(); repositoryStub.Expect(m => m.Create(glossaryTermCausingError)).Throw(new DataException("")); var controller = new GlossaryTermController(repositoryStub); controller.Create(glossaryTermCausingError); Assert.AreEqual("The term could not be saved. Please try again.", controller.ModelState[""].Errors.First().ErrorMessage); }
private static IEnumerable<GlossaryTerm> GetGlossaryTermsFromController(IGlossaryTermRepository repositoryStub) { var controller = new GlossaryTermController(repositoryStub); var result = controller.Index(); var glossaryTerms = (IEnumerable<GlossaryTerm>) result.Model; return glossaryTerms; }