Esempio n. 1
0
        public void CreateTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            FriendshipController target = new FriendshipController();
            int expectedFriendships = db.friendships.ToList<friendship>().Count()+1;

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

            // Assertions
            db = new touch_for_foodEntities();
            var actualResultURI = actualResult.RouteValues["action"];
            int actualFriendships = db.friendships.ToList<friendship>().Count();
            Assert.AreEqual(expectedFriendships, actualFriendships);
            Assert.AreEqual("Index", actualResultURI);
        }
Esempio n. 2
0
        public void EditViewTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            FriendshipController target = new FriendshipController();
            long expected = friendship1.id;
            SelectList expectedUser1List = new SelectList(db.users, "id", "username", user1);
            SelectList expectedUser2List = new SelectList(db.users, "id", "username", user2);

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

            //Assert
            SelectList actualUser1List = actual.ViewBag.first_user;
            SelectList actualUser2List = actual.ViewBag.second_user;
            Assert.AreEqual(((friendship)actual.Model).id, expected);
            Assert.AreEqual(expectedUser1List.GetType(), actualUser1List.GetType());
            Assert.AreEqual(expectedUser2List.GetType(), actualUser2List.GetType());
            Assert.AreEqual(expectedUser1List.Count(), actualUser1List.Count());
            Assert.AreEqual(expectedUser2List.Count(), actualUser2List.Count());
        }
Esempio n. 3
0
        public void IndexTest()
        {
            // Arrange
            db = new touch_for_foodEntities();
            FriendshipController target = new FriendshipController();
            List<friendship> expectedFriendships = db.friendships.ToList<friendship>();

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

            // Assert
            List<friendship> actualFriendships = actual.Model as List<friendship>;
            Assert.AreEqual(actualFriendships.Count(), expectedFriendships.Count());
        }
Esempio n. 4
0
        public void EditTestInvalidStateModel()
        {
            // Arrange
            db = new touch_for_foodEntities();
            FriendshipController target = new FriendshipController();
            long expected = friendship1.id;
            SelectList expectedUser1List = new SelectList(db.users, "id", "username", user1);
            SelectList expectedUser2List = new SelectList(db.users, "id", "username", user2);
            friendship1.second_user = user3.id;
            target.ModelState.AddModelError("error", "ModelState is invalid");

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

            // Assert
            SelectList actualUser1List = actual.ViewBag.first_user;
            SelectList actualUser2List = actual.ViewBag.second_user;
            string errorMsg = actual.ViewBag.Error;
            Assert.AreEqual(((friendship)actual.Model).id, expected);
            Assert.AreEqual(expectedUser1List.GetType(), actualUser1List.GetType());
            Assert.AreEqual(expectedUser2List.GetType(), actualUser2List.GetType());
            Assert.AreEqual(expectedUser1List.Count(), actualUser1List.Count());
            Assert.AreEqual(expectedUser2List.Count(), actualUser2List.Count());
            Assert.IsNotNull(errorMsg); //error message is sent to view
        }
Esempio n. 5
0
        public void EditTest()
        {
            //Arrange
            FriendshipController target = new FriendshipController();
            friendship1.second_user = user3.id;

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

            //Assert
            db = new touch_for_foodEntities();
            var actualResultURI = actualResult.RouteValues["action"];
            Assert.AreEqual("Index", actualResultURI);
            Assert.AreEqual(db.friendships.Find(friendship1.id).second_user, user3.id);
        }
Esempio n. 6
0
        public void DetailsTest()
        {
            //Arrange
            FriendshipController target = new FriendshipController();
            long expected = friendship1.id;

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

            //Assert
            Assert.AreEqual(expected, ((friendship)actual.ViewData.Model).id);
        }
Esempio n. 7
0
        public void DeleteConfirmedTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            FriendshipController target = new FriendshipController();
            int expectedFriendships = db.friendships.ToList<friendship>().Count() - 1;

            //Check Setup
            Assert.IsNotNull(db.friendships.Find(friendship1.id));

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

            //Assert
            db = new touch_for_foodEntities();
            var actualResultURI = actualResult.RouteValues["action"];
            int actualFriendships = db.friendships.ToList<friendship>().Count();
            Assert.AreEqual(expectedFriendships, actualFriendships);
            Assert.AreEqual("Index", actualResultURI);
            Assert.IsNull(db.friendships.Find(friendship1.id));
        }
Esempio n. 8
0
        public void CreateViewTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            FriendshipController target = new FriendshipController();
            SelectList expectedUserList = new SelectList(db.users, "id", "username");

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

            //Assert
            SelectList actualUser1List = actual.ViewBag.first_user;
            SelectList actualUser2List = actual.ViewBag.second_user;
            Assert.AreEqual(expectedUserList.GetType(), actualUser1List.GetType());
            Assert.AreEqual(expectedUserList.GetType(), actualUser2List.GetType());
            Assert.AreEqual(expectedUserList.Count(), actualUser1List.Count());
            Assert.AreEqual(expectedUserList.Count(), actualUser2List.Count());
        }