예제 #1
0
        public void OnTheMenuTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            List<menu_item> expectedMenuItems = db.menu_item.Where(mi => mi.menu_category_id == menuCategory1.id && mi.is_deleted == false).ToList();
            PartialViewResult actual;

            //Act
            actual = (PartialViewResult)target.OnTheMenu(menuCategory1.id);

            //Assert
            List<menu_item> actualMenuItems = actual.Model as List<menu_item>;
            Assert.AreEqual(expectedMenuItems.Count(), actualMenuItems.Count());
            Assert.AreEqual("_OnTheMenu", actual.ViewName);
        }
예제 #2
0
        public void PickSidesTest()
        {
            //Arrange
            Menu_ItemController target = new Menu_ItemController();
            int expected = menuItem1.id;
            PartialViewResult actual;

            //Act
            actual = (PartialViewResult)target.PickSides(menuItem1.id);

            //Assert
            Assert.AreEqual(expected, ((menu_item)actual.ViewData.Model).id);
        }
예제 #3
0
        public void GetAllReviewsTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            PartialViewResult actual;
            List<review_order_item> expectedReviews = db.menu_item.Find(menuItem1.id)
                                                        .order_item
                                                        .SelectMany(oi => oi.review_order_item)
                                                        .OrderByDescending(r => r.submitted_on)
                                                        .ToList<review_order_item>();
            //Act
            actual = target.GetAllReviews(menuItem1);

            //Assert
            List<review_order_item> actualReviews = actual.Model as List<review_order_item>;
            Assert.AreEqual(expectedReviews.Count(), actualReviews.Count());
            Assert.AreEqual("_PastReviewsPartial", actual.ViewName);
        }
예제 #4
0
        public void IndexTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            List<menu_item> expectedMenuItems = db.menu_item.Where(mi => mi.is_active == true && mi.is_deleted == false).ToList();
            ViewResult actual;

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

            //Assert
            List<menu_item> actualMenuItems = actual.Model as List<menu_item>;
            Assert.AreEqual(expectedMenuItems.Count(), actualMenuItems.Count());
        }
예제 #5
0
        public void EditTestLockFailure()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            int expected = menuItem1.id;
            SelectList expectedItemList = new SelectList(db.items, "id", "name", menuItem1.item_id);
            SelectList expectedCategoryList = new SelectList(db.menu_category, "id", "id", menuItem1.menu_category_id);
            ViewResult actual;
            menuItem1.version += 5;

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

            // Assert
            Assert.AreEqual(expected, ((menu_item)actual.ViewData.Model).id);

            SelectList actualItemList = actual.ViewBag.item_id;
            Assert.AreEqual(expectedItemList.GetType(), actualItemList.GetType());
            Assert.AreEqual(expectedItemList.Count(), actualItemList.Count());

            SelectList actualCategoryList = actual.ViewBag.menu_category_id;
            Assert.AreEqual(expectedCategoryList.GetType(), actualCategoryList.GetType());
            Assert.AreEqual(expectedCategoryList.Count(), actualCategoryList.Count());

            string errorMsg = actual.ViewBag.Error;
            Assert.IsNotNull(errorMsg); //error message is sent to view
        }
예제 #6
0
        public void EditViewTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            int expected = menuItem1.id;
            SelectList expectedItemList = new SelectList(db.items, "id", "name", menuItem1.item_id);
            SelectList expectedCategoryList = new SelectList(db.menu_category, "id", "id", menuItem1.menu_category_id);
            ViewResult actual;

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

            // Assert
            Assert.AreEqual(expected, ((menu_item)actual.ViewData.Model).id);

            SelectList actualItemList = actual.ViewBag.item_id;
            Assert.AreEqual(expectedItemList.GetType(), actualItemList.GetType());
            Assert.AreEqual(expectedItemList.Count(), actualItemList.Count());

            SelectList actualCategoryList = actual.ViewBag.menu_category_id;
            Assert.AreEqual(expectedCategoryList.GetType(), actualCategoryList.GetType());
            Assert.AreEqual(expectedCategoryList.Count(), actualCategoryList.Count());
        }
예제 #7
0
        public void DetailsTest()
        {
            //Arrange
            Menu_ItemController target = new Menu_ItemController();
            int expected = menuItem1.id;
            ViewResult actual;

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

            //Assert
            Assert.AreEqual(expected, ((menu_item)actual.ViewData.Model).id);
        }
예제 #8
0
        public void EditTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            int expectedVersion = menuItem1.version + 1;
            decimal changePrice = new decimal(9.99);
            menuItem1.price = changePrice;

            //Check Setup
            Assert.IsFalse(db.menu_item.Find(menuItem1.id).price == changePrice);

            // Act
            var actualResult = target.Edit(menuItem1) as RedirectToRouteResult;

            // Assertions
            db = new touch_for_foodEntities();
            var actualResultURI = actualResult.RouteValues["action"];
            Assert.AreEqual(db.menu_item.Find(menuItem1.id).version, expectedVersion); //version was incremented
            Assert.IsTrue(db.menu_item.Find(menuItem1.id).price == changePrice); //price was changed
            Assert.AreEqual("Index", actualResultURI); //directed to correct location
        }
예제 #9
0
        public void DeleteConfirmedTestItemActiveException()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            int expectedMenuItems = db.menu_item.ToList<menu_item>().Count();
            menuItem1 = db.menu_item.Find(menuItem1.id);
            menuItem1.is_active = true;
            db.Entry(menuItem1).State = EntityState.Modified;
            db.SaveChanges();

            // Act
            var actualResult = target.DeleteConfirmed(menuItem1.id) as RedirectToRouteResult;

            // Assertions
            db = new touch_for_foodEntities();
            var actualResultURI = actualResult.RouteValues["action"];
            int actualMenuItems = db.menu_item.ToList<menu_item>().Count();

            Assert.AreEqual(expectedMenuItems, actualMenuItems);
            Assert.IsFalse(db.menu_item.Find(menuItem1.id).is_deleted);
            Assert.AreEqual("Index", actualResultURI);
        }
예제 #10
0
        public void DeleteConfirmedTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();

            //CheckSetup
            Assert.IsFalse(db.menu_item.Find(menuItem1.id).is_deleted);

            // Act
            var actualResult = target.DeleteConfirmed(menuItem1.id) as RedirectToRouteResult;

            // Assertions
            db = new touch_for_foodEntities();
            var actualResultURI = actualResult.RouteValues["action"];

            Assert.IsTrue(db.menu_item.Find(menuItem1.id).is_deleted);
            Assert.AreEqual("Index", actualResultURI);
        }
예제 #11
0
        public void CreateViewTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            SelectList expectedItemList = new SelectList(db.items, "id", "name");
            SelectList expectedCategoryList = new SelectList(db.menu_category, "id", "id");
            ViewResult actual;

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

            //Assert
            SelectList actualItemList = actual.ViewBag.item_id;
            Assert.AreEqual(expectedItemList.GetType(), actualItemList.GetType());
            Assert.AreEqual(expectedItemList.Count(), actualItemList.Count());

            SelectList actualCategoryList = actual.ViewBag.menu_category_id;
            Assert.AreEqual(expectedCategoryList.GetType(), actualCategoryList.GetType());
            Assert.AreEqual(expectedCategoryList.Count(), actualCategoryList.Count());
        }
예제 #12
0
        public void CreateTestInvalidStateModel()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            target.ModelState.AddModelError("error", "ModelState is invalid");
            SelectList expectedItemList = new SelectList(db.items, "id", "name", menuItem2.item_id);
            SelectList expectedCategoryList = new SelectList(db.menu_category, "id", "id", menuItem2.menu_category_id);
            ViewResult actual;

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

            // Assert
            SelectList actualItemList = actual.ViewBag.item_id;
            Assert.AreEqual(expectedItemList.GetType(), actualItemList.GetType());
            Assert.AreEqual(expectedItemList.Count(), actualItemList.Count());

            SelectList actualCategoryList = actual.ViewBag.menu_category_id;
            Assert.AreEqual(expectedCategoryList.GetType(), actualCategoryList.GetType());
            Assert.AreEqual(expectedCategoryList.Count(), actualCategoryList.Count());

            string errorMsg = actual.ViewBag.Error;
            Assert.IsNotNull(errorMsg); //error message is sent to view
        }
예제 #13
0
        public void CreateTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            int expectedMenuItems = db.menu_item.ToList<menu_item>().Count() + 1;

            // Act
            var actualResult = target.Create(menuItem2) as RedirectToRouteResult;

            // Assertions
            db = new touch_for_foodEntities();
            var actualResultURI = actualResult.RouteValues["action"];
            int actualMenuItems = db.menu_item.ToList<menu_item>().Count();
            Assert.AreEqual(expectedMenuItems, actualMenuItems);
            Assert.AreEqual("Index", actualResultURI);
        }