Example #1
0
        public void RemoveOrderItemTest()
        {
            //Check Setup
            db = new touch_for_foodEntities();
            Assert.IsTrue(db.order_item.Find(orderItem1.id).bill_id == bill1.id);

            //Arrange
            BillController target = new BillController();

            //Act
            RedirectToRouteResult actual = (RedirectToRouteResult)target.RemoveOrderItem(orderItem1.id);

            //Assert
            db = new touch_for_foodEntities();
            Assert.AreEqual("Bill", actual.RouteValues["controller"]);
            Assert.AreEqual("ManageBills", actual.RouteValues["action"]);
            Assert.AreEqual(order1.id, actual.RouteValues["id"]);
            Assert.IsTrue(db.order_item.Find(orderItem1.id).bill_id == null);
        }
Example #2
0
        public static void MyClassInitialize(TestContext testContext)
        {
            //Add test data (order specific)
            testDatabase = new TestDatabaseHelper();
            restaurant1 = testDatabase.AddRestaurant();
            table1 = testDatabase.AddTable(restaurant1);
            user1 = testDatabase.AddUser("*****@*****.**", table1, (int)SiteRoles.Admin);
            order1 = testDatabase.AddOrder(table1);
            item1 = testDatabase.AddItem();
            category1 = testDatabase.AddCategory();
            menu1 = testDatabase.AddMenu(restaurant1);
            menuCategory1 = testDatabase.AddMenuCategory(category1, menu1);
            menuItem1 = testDatabase.AddMenuItem(item1, menuCategory1);

            //Session
            db = new touch_for_foodEntities();
            BillController target = new BillController();
            Session session = new Session(db, target);
            session.simulateLogin(user1.username, user1.password);
        }
Example #3
0
        public void IndexTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            BillController target = new BillController();
            List<bill> expectedOrders = db.bills.Include(b => b.order).ToList();
            ViewResult actual;

            //Act
            actual = (ViewResult)target.Index();

            //Assert
            List<bill> actualOrders = actual.Model as List<bill>;
            Assert.AreEqual(expectedOrders.Count(), actualOrders.Count());
        }
Example #4
0
        public void ManageBillsTest()
        {
            //Arrange
            BillController target = new BillController();

            //Act
            ViewResult actual = (ViewResult)target.ManageBills(order1.id);

            //Assert
            Assert.AreEqual(actual.ViewName, "ManageBills");
            Assert.AreEqual(((order)actual.Model).id, order1.id);
        }
Example #5
0
        public void EditBillTestLockError()
        {
            // Arrange
            db = new touch_for_foodEntities();
            BillController target = new BillController();
            SelectList expectedOrderList = new SelectList(db.orders, "id", "id", bill1.order_id);
            ViewResult actual;
            bill1.version += 5;

            // Act
            actual = (ViewResult)target.Edit(bill1);

            // Assert
            SelectList actualOrderList = actual.ViewBag.order_id;
            Assert.AreEqual(expectedOrderList.GetType(), actualOrderList.GetType());
            Assert.AreEqual(expectedOrderList.Count(), actualOrderList.Count());

            string errorMsg = actual.ViewBag.Error;
            Assert.IsNotNull(errorMsg); //error message is sent to view
        }
Example #6
0
        public void EditTest()
        {
            //Arrange
            BillController target = new BillController();

            //Act
            ViewResult actual = (ViewResult)target.Edit(bill1.id);

            //Assert
            Assert.AreEqual(((bill)actual.Model).id, bill1.id);
        }
Example #7
0
        public void DetailsTest()
        {
            //Arrange
            BillController target = new BillController();
            int expected = bill1.id;
            ViewResult actual;

            //Act
            actual = (ViewResult)target.Details(bill1.id);

            //Assert
            Assert.AreEqual(expected, ((bill)actual.ViewData.Model).id);
        }
Example #8
0
        public void EditBillTest()
        {
            //Check Setup
            db = new touch_for_foodEntities();
            Assert.IsFalse(db.bills.Find(bill1.id).total == 9M);
            Assert.IsFalse(db.bills.Find(bill1.id).tps == 3M);

            //Arrange
            BillController target = new BillController();
            bill1.total = 9M;
            bill1.tps = 3M;

            //Act
            RedirectToRouteResult actual = (RedirectToRouteResult)target.Edit(bill1);

            //Assert
            db = new touch_for_foodEntities();
            bill newBill = db.bills.Find(bill1.id);
            Assert.IsTrue(db.bills.Find(bill1.id).total == 9M);
            Assert.IsTrue(db.bills.Find(bill1.id).tps == 3M);
        }
Example #9
0
        public void DeleteBillFromOrderTest()
        {
            //Check Setup
            db = new touch_for_foodEntities();
            Assert.IsFalse(db.bills.Find(bill1.id) == null);

            //Arrange
            BillController target = new BillController();
            int numberOfTotalBillsBefore = db.orders.SelectMany(o => o.bills).ToList<bill>().Count();
            int expected = 1;

            //Act
            int actual = target.DeleteBillFromOrder(bill1.id);

            //Assert
            db = new touch_for_foodEntities();
            int numberOfTotalBillsAfter = db.orders.SelectMany(o => o.bills).ToList<bill>().Count();
            Assert.AreEqual(expected, actual);
            Assert.IsTrue((numberOfTotalBillsBefore - 1) == numberOfTotalBillsAfter);
            Assert.IsTrue(db.bills.Find(bill1.id) == null);
        }
Example #10
0
        public void CreateViewTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            BillController target = new BillController();
            SelectList orderList = new SelectList(db.orders, "id", "id");

            //Act
            var actual = (ViewResult)target.Create();

            //Assert
            Assert.AreEqual(orderList.GetType(), actual.ViewBag.order_id.GetType());
        }
Example #11
0
        public void CreateTestInvalidStateModel()
        {
            // Arrange
            db = new touch_for_foodEntities();
            BillController target = new BillController();
            target.ModelState.AddModelError("error", "ModelState is invalid");
            SelectList expectedOrderList = new SelectList(db.orders, "id", "id", bill1.order_id);
            ViewResult actual;

            // Act
            actual = (ViewResult)target.Create(bill1);

            // Assert
            SelectList actualOrderList = actual.ViewBag.order_id;
            Assert.AreEqual(expectedOrderList.GetType(), actualOrderList.GetType());
            Assert.AreEqual(expectedOrderList.Count(), actualOrderList.Count());

            string errorMsg = actual.ViewBag.Error;
            Assert.IsNotNull(errorMsg); //error message is sent to view
        }
Example #12
0
        public void CreateBillForOrderTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            BillController target = new BillController();
            int numberOfTotalBillsBefore = db.orders.SelectMany(o => o.bills).ToList<bill>().Count();
            int expected = 1;

            //Act
            int actual = target.CreateBillForOrder(order1.id);

            //Assert
            db = new touch_for_foodEntities();
            int numberOfTotalBillsAfter = db.orders.SelectMany(o => o.bills).ToList<bill>().Count();
            Assert.IsTrue(actual == expected);
            Assert.IsTrue((numberOfTotalBillsBefore + 1) == numberOfTotalBillsAfter);
        }
Example #13
0
        public void AddOrderItemToBillTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            BillController target = new BillController();
            order_item orderItem2 = testDatabase.AddOrderItem(order1, menuItem1);
            int numberOfOrderItemsBefore = db.bills.Find(bill1.id).order_item.Count();
            int expected = 1;

            //Act
            int actual = target.AddOrderItemToBill(bill1.id, orderItem2.id);

            //Assert
            db = new touch_for_foodEntities();
            int numberOfOrderItemsAfter = db.bills.Find(bill1.id).order_item.Count();
            Assert.AreEqual(expected, actual);
            Assert.IsTrue((numberOfOrderItemsBefore + 1) == numberOfOrderItemsAfter);

            //Cleanup
            testDatabase.RemoveOrderItem(orderItem2);
        }