Ejemplo n.º 1
0
        public void IndexTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            SideController target = new SideController();
            List<side> expectedSideItems = db.sides.Where(si => si.is_active == true && si.is_deleted == false).ToList();
            ViewResult actual;

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

            //Assert
            List<side> actualSideItems = actual.Model as List<side>;
            Assert.AreEqual(expectedSideItems.Count(), actualSideItems.Count());
        }
Ejemplo n.º 2
0
        public void EditViewTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            SideController target = new SideController();
            int expected = side1.id;
            SelectList expectedSideList = new SelectList(db.menu_category, "id", "id", side1.menu_category_id);

            ViewResult actual;

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

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

            SelectList actualSideList = actual.ViewBag.menu_category_id;
            Assert.AreEqual(expectedSideList.GetType(), actualSideList.GetType());
            Assert.AreEqual(expectedSideList.Count(), actualSideList.Count());
        }
Ejemplo n.º 3
0
        public void FilterSidesTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            SideController target = new SideController(); // TODO: Initialize to an appropriate value
            menuCategory1.menu = menu1;
            List<side> expectedSides = db.sides.Where
            (
                si =>
                    si.menu_category.menu.resto_id == menuCategory1.menu.resto_id
                    && si.is_active == false
                    && si.is_deleted == false
                    && si.menu_category.id == menuCategory1.id
            ).ToList();

            PartialViewResult actual;

            //Act
            actual = target.FilterSides(menuCategory1);

            //Assert
            SideFilterVM actualSideItems = actual.Model as SideFilterVM;
            Assert.AreEqual(expectedSides.Count(), actualSideItems.sides.Count());
        }
Ejemplo n.º 4
0
        public void DetailsTest()
        {
            //Arrange
            SideController target = new SideController();
            int expected = side1.id;
            ViewResult actual;

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

            //Assert
            Assert.AreEqual(expected, ((side)actual.ViewData.Model).id);
        }
Ejemplo n.º 5
0
        public void EditTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            SideController target = new SideController();
            int expectedVersion = side1.version + 1;
            string changeName = "thisIsANewName";
            side1.name = changeName;

            //Check Setup
            Assert.IsFalse(db.sides.Find(side1.id).name == changeName);

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

            // Assertions
            db = new touch_for_foodEntities();
            var actualResultURI = actualResult.RouteValues["action"];
            Assert.AreEqual(db.sides.Find(side1.id).version, expectedVersion); //version was incremented
            Assert.IsTrue(db.sides.Find(side1.id).name == changeName); //price was changed
            Assert.AreEqual("Index", actualResultURI); //directed to correct location
        }
Ejemplo n.º 6
0
        public void DeleteConfirmedTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            SideController target = new SideController();

            //CheckSetup
            Assert.IsFalse(db.sides.Find(side1.id).is_deleted);

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

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

            Assert.IsTrue(db.sides.Find(side1.id).is_deleted);
            Assert.AreEqual("Index", actualResultURI);
        }
Ejemplo n.º 7
0
        public void DeleteConfirmedTestItemActiveException()
        {
            // Arrange
            db = new touch_for_foodEntities();
            SideController target = new SideController();
            int expectedSides = db.sides.ToList<side>().Count();
            side1 = db.sides.Find(side1.id);
            side1.is_active = true;
            db.Entry(side1).State = EntityState.Modified;
            db.SaveChanges();

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

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

            Assert.AreEqual(expectedSides, actualSides);
            Assert.IsFalse(db.sides.Find(side1.id).is_deleted);
            Assert.AreEqual("Index", actualResultURI);
        }
Ejemplo n.º 8
0
        public void CreateViewTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            SideController target = new SideController();
            SelectList expectedMenuCategoryList = new SelectList(db.menu_category, "id", "id");
            ViewResult actual;

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

            //Assert
            SelectList actualSideList = actual.ViewBag.menu_category_id;
            Assert.AreEqual(expectedMenuCategoryList.GetType(), actualSideList.GetType());
            Assert.AreEqual(expectedMenuCategoryList.Count(), actualSideList.Count());
        }
Ejemplo n.º 9
0
        public void CreateTestInvalidStateModel()
        {
            // Arrange
            db = new touch_for_foodEntities();
            SideController target = new SideController();
            target.ModelState.AddModelError("error", "ModelState is invalid");
            SelectList expectedSideList = new SelectList(db.menu_category, "id", "id", side2.menu_category_id);
            ViewResult actual;

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

            // Assert
            SelectList actualSideList = actual.ViewBag.menu_category_id;
            Assert.AreEqual(expectedSideList.GetType(), actualSideList.GetType());
            Assert.AreEqual(expectedSideList.Count(), actualSideList.Count());

            string errorMsg = actual.ViewBag.Error;
            Assert.IsNotNull(errorMsg); //error message is sent to view
        }
Ejemplo n.º 10
0
        public void CreateTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            SideController target = new SideController();
            int expectedSides = db.sides.ToList<side>().Count() + 1;

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

            db = new touch_for_foodEntities();
            var actualResultURI = actualResult.RouteValues["action"];
            int actualSides = db.sides.ToList<side>().Count();
            Assert.AreEqual(expectedSides, actualSides);
            Assert.AreEqual("Index", actualResultURI);
        }
Ejemplo n.º 11
0
        public void AjaxDeleteTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            SideController target = new SideController();
            int expected = side1.id;

            // Act
            int actual = target.AjaxDelete(side1.id);

            // Assert
            side actualSide = db.sides.Find(side1.id);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
        public void AjaxActiveSetInactiveTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            SideController target = new SideController();
            int expected = side1.id;
            bool isActive = false;

            // Act
            int actual = target.AjaxActive(side1.id, isActive);

            // Assert
            side actualSide = db.sides.Find(side1.id);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(isActive, actualSide.is_active);
        }