public void CreatePostAction_ModelStateValid_UpdateAndSaveAreCalled() { // arrange var mock = new Mock <IArchitectRepository>(); Architect architect = new Architect(); ArchitectController controller = new ArchitectController(mock.Object); // act RedirectToRouteResult result = controller.Create(architect) as RedirectToRouteResult; // assert mock.Verify(a => a.Create(architect)); mock.Verify(a => a.Save()); }
public void CreatePostAction_ModelStateValid_RedirectToIndexView() { // arrange string expected = "Index"; var mock = new Mock <IArchitectRepository>(); Architect architect = new Architect(); ArchitectController controller = new ArchitectController(mock.Object); // act RedirectToRouteResult result = controller.Create(architect) as RedirectToRouteResult; // assert Assert.IsNotNull(result); Assert.AreEqual(expected, result.RouteValues["action"]); }
public void CreatePostAction_ModelStateNotValid_ReturnCreateView() { // arrange string expected = "Create"; var mock = new Mock <IArchitectRepository>(); Architect architect = new Architect(); ArchitectController controller = new ArchitectController(mock.Object); controller.ModelState.AddModelError("FirstName", "FirstName is required"); // act ViewResult result = controller.Create(architect) as ViewResult; // assert Assert.IsNotNull(result); Assert.AreEqual(expected, result.ViewName); }