public void OpenTableOrder() { MockContext mockContext = new MockContext(); var homeController = new HomeController() { ControllerContext = new ControllerContext() { HttpContext = mockContext.Http.Object } }; Order myOrder = new Order(); myOrder.customerID = "6"; myOrder.generatedReceipt = 0; myOrder.isPaid = 0; myOrder.orderStartDate = DateTime.UtcNow; myOrder.pointsChoice = "Save"; myOrder.staffID = 1; //act var result = homeController.OpenTable(myOrder) as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["Action"]); mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=Customer")); result = homeController.OpenTable(myOrder) as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["Action"]); mockContext.Cookies.Clear(); HttpCookie myCookie = new HttpCookie("UserSettings"); myCookie.Values["Role"] = "Staff"; myCookie.Values["ID"] = "1"; mockContext.Cookies.Add(myCookie); result = homeController.OpenTable(myOrder) as RedirectToRouteResult; string action = result.RouteValues["Action"].ToString(); bool response = action.Contains("ManageTable"); Assert.AreEqual(response, true); }
public void OpenTable() { MockContext mockContext = new MockContext(); var homeController = new HomeController() { ControllerContext = new ControllerContext() { HttpContext = mockContext.Http.Object } }; //act var result = homeController.OpenTable() as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["Action"]); mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=Customer")); result = homeController.OpenTable() as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["Action"]); mockContext.Cookies.Clear(); HttpCookie myCookie = new HttpCookie("UserSettings"); myCookie.Values["Role"] = "Staff"; myCookie.Values["ID"] = "1"; mockContext.Cookies.Add(myCookie); var newResult = homeController.OpenTable() as ViewResult; Assert.AreEqual("OpenTable", newResult.ViewName); mockContext.Cookies.Clear(); mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=SystemAdmin")); newResult = homeController.OpenTable() as ViewResult; Assert.AreEqual("OpenTable", newResult.ViewName); }