Пример #1
0
        public void CreateViewTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            Order_ItemController target = new Order_ItemController();
            SelectList expectedMenuList = new SelectList(db.menu_item, "id", "id");
            SelectList expectedOrderList = new SelectList(db.orders, "id", "id");
            ViewResult actual;

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

            //Assert
            SelectList actualMenuList = actual.ViewBag.menu_item_id;
            Assert.AreEqual(expectedMenuList.GetType(), actualMenuList.GetType());
            Assert.AreEqual(expectedMenuList.Count(), actualMenuList.Count());

            SelectList actualOrderList = actual.ViewBag.order_id;
            Assert.AreEqual(expectedOrderList.GetType(), actualOrderList.GetType());
            Assert.AreEqual(expectedOrderList.Count(), actualOrderList.Count());
        }
Пример #2
0
        public void CreateTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Order_ItemController target = new Order_ItemController();
            int expectedOrderItems = db.order_item.ToList<order_item>().Count() + 1;

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

            // Assertions
            db = new touch_for_foodEntities();
            var actualResultURI = actualResult.RouteValues["action"];
            int actualOrderItems = db.order_item.ToList<order_item>().Count();
            Assert.AreEqual(expectedOrderItems, actualOrderItems);
            Assert.IsNotNull(db.order_item.Find(orderItem3.id));
            Assert.AreEqual("Index", actualResultURI);
        }
Пример #3
0
        public void CreateTestInvalidStateModel()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Order_ItemController target = new Order_ItemController();
            target.ModelState.AddModelError("error", "ModelState is invalid");
            SelectList expectedMenuList = new SelectList(db.menu_item, "id", "id", orderItem3.menu_item_id);
            SelectList expectedOrderList = new SelectList(db.orders, "id", "id", orderItem3.order_id);
            ViewResult actual;

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

            // Assert
            SelectList actualMenuList = actual.ViewBag.menu_item_id;
            Assert.AreEqual(expectedMenuList.GetType(), actualMenuList.GetType());
            Assert.AreEqual(expectedMenuList.Count(), actualMenuList.Count());

            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
        }