public void ApproveThenDetail() { var mockUser = University.GetUser("e101"); VisitorController vc = new VisitorController(); vc.ControllerContext = new ControllerContext(MockAuthContext(mockUser).Object, new RouteData(), vc); ViewResult actionResult = vc.Detail("TEST1") as ViewResult; Assert.IsNotNull(actionResult); Assert.IsInstanceOfType(actionResult.Model, typeof(Visitor)); Visitor model = actionResult.Model as Visitor; Assert.AreEqual(VisitorStatus.WaitingForApproval, model.Status); RedirectToRouteResult actionResult2 = vc.Approve(model.ID) as RedirectToRouteResult; Assert.AreEqual("List", actionResult2.RouteValues["action"]); ViewResult actionResult3 = vc.Detail("TEST1") as ViewResult; Assert.IsNotNull(actionResult3); Assert.IsInstanceOfType(actionResult3.Model, typeof(Visitor)); Visitor model2 = actionResult3.Model as Visitor; Assert.AreEqual(VisitorStatus.WaitingForArrival, model2.Status); Assert.IsNotNull(model2.ApproveDate); }
public void ApproveMissingVisitor() { var mockUser = University.GetUser("e100"); VisitorController vc = new VisitorController(); vc.ControllerContext = new ControllerContext(MockAuthContext(mockUser).Object, new RouteData(), vc); Assert.ThrowsException <HttpAntiForgeryException>(() => vc.Approve(999)); }
public void ApproveWithAnotherUserAuth() { var mockUser = University.GetUser("e100"); VisitorController vc = new VisitorController(); vc.ControllerContext = new ControllerContext(MockAuthContext(mockUser).Object, new RouteData(), vc); ViewResult actionResult = vc.Detail("TEST1") as ViewResult; Assert.IsNotNull(actionResult); Assert.IsInstanceOfType(actionResult.Model, typeof(Visitor)); Visitor model = actionResult.Model as Visitor; Assert.AreEqual(VisitorStatus.WaitingForApproval, model.Status); Assert.ThrowsException <HttpAntiForgeryException>(() => vc.Approve(model.ID)); }