コード例 #1
0
        public void TestEdit_WhenUserIsDeleted_AddModelErrorAndReturnEditView()
        {
            // Arrange
            IUnitOfWork unitOfWork = new UnitOfWork();
            UserController target = new UserController(unitOfWork);
            Nullable<bool> errorOccurred = null;

            // Act
            ViewResult actual = target.Edit(2, errorOccurred) as ViewResult;

            // Assert
            Assert.AreEqual("Edit", actual.ViewName);
            Assert.IsFalse(target.ModelState.IsValid);
        }
コード例 #2
0
        public void TestEdit_WhenUserIDIsZero_ReturnIndexViewAndErrorMessage()
        {
            // Arrange
            IUnitOfWork unitOfWork = new UnitOfWork();
            UserController target = new UserController(unitOfWork);
            Nullable<bool> errorOccurred = null;

            // Act
            RedirectToRouteResult actual = target.Edit(0, errorOccurred) as RedirectToRouteResult;

            // Assert
            Assert.AreEqual("Index", actual.RouteValues["action"]);
            Assert.AreEqual(true, actual.RouteValues["errorOccurred"]);
        }
コード例 #3
0
        public void TestEdit_WhenNoError_ReturnEditView()
        {
            // Arrange
            IUnitOfWork unitOfWork = new UnitOfWork();
            UserController target = new UserController(unitOfWork);
            Nullable<bool> errorOccurred = null;

            // Act
            ViewResult actual = target.Edit(1, errorOccurred) as ViewResult;

            // Assert
            Assert.AreEqual("Edit", actual.ViewName);
        }
コード例 #4
0
        public void TestEdit_WhenNoError_EditUserAndReturnIndexView()
        {
            // Arrange
            IUnitOfWork unitOfWork = new UnitOfWork();
            UserController target = new UserController(unitOfWork);

            var editedUser = userRepository.GetUserByID(1);
            editedUser.FirstName = "Edited_First_Name";
            editedUser.LastName = "Edited_Last_Name";
            editedUser.Email = "*****@*****.**";

            // Act
            RedirectToRouteResult actual = target.Edit(editedUser) as RedirectToRouteResult;

            // Assert
            Assert.AreEqual("Index", actual.RouteValues["action"]);
            Assert.IsNotNull(editedUser.DateModified);
            Assert.IsNull(editedUser.IsDeleted);
        }
コード例 #5
0
        public void TestEdit_WhenError_ReturnEditViewAndErrorMessage()
        {
            // Arrange
            IUnitOfWork unitOfWork = new UnitOfWork();
            UserController target = new UserController(unitOfWork);
            Nullable<bool> errorOccurred = true;

            // Act
            ViewResult actual = target.Edit(1, errorOccurred) as ViewResult;

            // Assert
            Assert.AreEqual("Edit", actual.ViewName);
            Assert.AreEqual("Error occurred.", actual.ViewBag.ErrorMessage);
        }
コード例 #6
0
        public void TestEdit_WhenError_ModelStateNotValid_ReturnEditView()
        {
            // Arrange
            IUnitOfWork unitOfWork = new UnitOfWork();
            UserController target = new UserController(unitOfWork);

            var editedUser = userRepository.GetUserByID(1);
            editedUser.FirstName = "";
            editedUser.LastName = "";
            editedUser.Email = "";
            //TODO: it shows that modelstate is valid, throws an exception when saving

            // Act
            ViewResult actual = target.Edit(editedUser) as ViewResult;

            // Assert
            Assert.AreEqual("Edit", actual.ViewName);
            Assert.IsFalse(target.ModelState.IsValid);
        }