public void AdminCookieWarningAddItem()
        {
            MockContext mockContext = new MockContext();
            mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=SystemAdmin"));
            var homeController = new HomeController()
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = mockContext.Http.Object
                }
            };

            //act
            var result = homeController.AddItem(1) as ViewResult;
            Assert.AreEqual("There is already an existing item with this name.", result.ViewBag.ErrorMessage);
        }
        public void AdminEditItem()
        {
            MockContext mockContext = new MockContext();
            mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=SystemAdmin"));
            var homeController = new HomeController()
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = mockContext.Http.Object
                }
            };

            //act
            var result = homeController.EditItem(1) as ViewResult;
            Assert.AreEqual("EditItem", result.ViewName);
        }
        public void AdminEditNotExistingItem()
        {
            MockContext mockContext = new MockContext();
            mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=SystemAdmin"));
            var homeController = new HomeController()
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = mockContext.Http.Object
                }
            };

            //act
            var result = homeController.EditItem(0) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
        public void OtherViewMenu()
        {
            MockContext mockContext = new MockContext();
            var homeController = new HomeController()
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = mockContext.Http.Object
                }
            };

            //act
            var result = homeController.ViewMenu() as ViewResult;
            Assert.AreEqual("ViewMenu", result.ViewName);
        }
        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 NoCookieAddItem()
        {
            MockContext mockContext = new MockContext();
            var homeController = new HomeController()
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = mockContext.Http.Object
                }
            };

            //act
            var result = homeController.AddItem() as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
        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);
        }
 public void IndexError()
 {
     HomeController controller = new HomeController();
     ViewResult result = controller.Index(2) as ViewResult;
     Assert.AreEqual("There was an error creating this order!", result.ViewBag.ErrorMessage);
 }
        public void ManageTable()
        {
            MockContext mockContext = new MockContext();
            var homeController = new HomeController()
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = mockContext.Http.Object
                }
            };

            //act
            var result = homeController.ManageTable(32) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);

            mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=Customer"));
            result = homeController.ManageTable(32) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);

            mockContext.Cookies.Clear();
            HttpCookie myCookie = new HttpCookie("UserSettings");
            myCookie.Values["Role"] = "SystemAdmin";
            myCookie.Values["ID"] = "1";
            mockContext.Cookies.Add(myCookie);
            var newResult = homeController.ManageTable(32) as ViewResult;
            Assert.AreEqual("ManageTable", newResult.ViewName);

            mockContext.Cookies.Clear();
            myCookie = new HttpCookie("UserSettings");
            myCookie.Values["Role"] = "SystemAdmin";
            myCookie.Values["ID"] = "1";
            mockContext.Cookies.Add(myCookie);
            newResult = homeController.ManageTable(32, 1) as ViewResult;
            Assert.AreEqual("This order has not been paid for, so it is not possible to close it.", newResult.ViewBag.ErrorMessage);

            mockContext.Cookies.Clear();
            myCookie = new HttpCookie("UserSettings");
            myCookie.Values["Role"] = "SystemAdmin";
            myCookie.Values["ID"] = "1";
            mockContext.Cookies.Add(myCookie);
            newResult = homeController.ManageTable(32, 2) as ViewResult;
            Assert.AreEqual("This order can not be closed until an up-to-date receipt has been printed.", newResult.ViewBag.ErrorMessage);

            mockContext.Cookies.Clear();
            myCookie = new HttpCookie("UserSettings");
            myCookie.Values["Role"] = "SystemAdmin";
            myCookie.Values["ID"] = "1";
            mockContext.Cookies.Add(myCookie);
            newResult = homeController.ManageTable(32, 3) as ViewResult;
            Assert.AreEqual("Items can not be added to an order that has a valid issued receipt.", newResult.ViewBag.ErrorMessage);

            mockContext.Cookies.Clear();
            myCookie = new HttpCookie("UserSettings");
            myCookie.Values["Role"] = "SystemAdmin";
            myCookie.Values["ID"] = "1";
            mockContext.Cookies.Add(myCookie);
            newResult = homeController.ManageTable(32, 4) as ViewResult;
            Assert.AreEqual("Items can not be deleted from an order that has a valid issued receipt.", newResult.ViewBag.ErrorMessage);

            mockContext.Cookies.Clear();
            myCookie = new HttpCookie("UserSettings");
            myCookie.Values["Role"] = "SystemAdmin";
            myCookie.Values["ID"] = "1";
            mockContext.Cookies.Add(myCookie);
            newResult = homeController.ManageTable(32, 5) as ViewResult;
            Assert.AreEqual("Item quantities can not be changed after a valid receipt has been issued.", newResult.ViewBag.ErrorMessage);

            mockContext.Cookies.Clear();
            myCookie = new HttpCookie("UserSettings");
            myCookie.Values["Role"] = "SystemAdmin";
            myCookie.Values["ID"] = "1";
            mockContext.Cookies.Add(myCookie);
            newResult = homeController.ManageTable(32, 6) as ViewResult;
            Assert.AreEqual("Loyalty point settings can not be changed if a valid receipt has been issued.", newResult.ViewBag.ErrorMessage);

            mockContext.Cookies.Clear();
            myCookie = new HttpCookie("UserSettings");
            myCookie.Values["Role"] = "SystemAdmin";
            myCookie.Values["ID"] = "1";
            mockContext.Cookies.Add(myCookie);
            newResult = homeController.ManageTable(32, 7) as ViewResult;
            Assert.AreEqual("The staff member can't be changed if a valid receipt has been issued.", newResult.ViewBag.ErrorMessage);

            mockContext.Cookies.Clear();
            mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=Staff&ID=2"));
            result = homeController.ManageTable(32) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
        public void Index()
        {
            // Arrange
            HomeController controller = new HomeController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.AreEqual("Index", result.ViewName);
        }
        public void DeleteOrderLine()
        {
            MockContext mockContext = new MockContext();
            var homeController = new HomeController()
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = mockContext.Http.Object
                }
            };
            var result = homeController.DeleteOrderLine(1) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);

            mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=Customer"));
            result = homeController.DeleteOrderLine(1) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);

            mockContext.Cookies.Clear();
            HttpCookie myCookie = new HttpCookie("UserSettings");
            myCookie.Values["Role"] = "SystemAdmin";
            myCookie.Values["ID"] = "1";
            mockContext.Cookies.Add(myCookie);
            result = homeController.DeleteOrderLine(1) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
        public void CustomerStaffCookieAddItem()
        {
            MockContext mockContext = new MockContext();
            mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=Staff"));
            var homeController = new HomeController()
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = mockContext.Http.Object
                }
            };

            //act
            var result = homeController.AddItem() as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
        public void CustomerEditItemDetails()
        {
            MockContext mockContext = new MockContext();
            Item myItem = new Item();
            RestaurantDatabaseEntities db = new RestaurantDatabaseEntities();
            myItem = db.Items.Find(1);
            mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=Customer"));
            var homeController = new HomeController()
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = mockContext.Http.Object
                }
            };

            //act
            var result = homeController.EditItem(myItem) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
        public void ChangeOrderLineQuantity()
        {
            MockContext mockContext = new MockContext();
            var homeController = new HomeController()
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = mockContext.Http.Object
                }
            };
            var result = homeController.ChangeOrderLineQuantity(21,3) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);

            mockContext.Cookies.Add(new HttpCookie("UserSettings", "Role=Customer"));
            result = homeController.ChangeOrderLineQuantity(21,3) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);

            mockContext.Cookies.Clear();
            HttpCookie myCookie = new HttpCookie("UserSettings");
            myCookie.Values["Role"] = "SystemAdmin";
            myCookie.Values["ID"] = "1";
            mockContext.Cookies.Add(myCookie);
            result = homeController.ChangeOrderLineQuantity(20,3) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["Action"]);

            mockContext.Cookies.Clear();
            myCookie = new HttpCookie("UserSettings");
            myCookie.Values["Role"] = "SystemAdmin";
            myCookie.Values["ID"] = "1";
            mockContext.Cookies.Add(myCookie);
            result = homeController.ChangeOrderLineQuantity(21, 3) as RedirectToRouteResult;
            string response = result.RouteValues["Action"].ToString();
            bool check = response.Contains("ManageTable");
            Assert.AreEqual(check, true);
        }