public void DeleteAction_WhenInvoking_AllowsDeleteExistingUser()
 {
     var user = new User { Id = 1, FirstName = "George", LastName = "Washington", Email = "*****@*****.**" };
     var controller = new UserController(mock.Object);
     var result = controller.Delete(user.Id);
     mock.Verify(m => m.DeleteUser(user.Id));
     Assert.IsInstanceOf<RedirectToRouteResult>(result);
 }
 public void IndexAction_WhenInvoking_CanPaginate()
 {
     var controller = new UserController(mock.Object);
     var result = ((UsersListViewModel)controller.Index(2, 3).Model).Users;
     Assert.IsTrue(result.Length == 3);
     Assert.AreEqual("Madison", result[0].LastName);
     Assert.AreEqual("Monroe", result[1].LastName);
     Assert.AreEqual("Quincy Adams", result[2].LastName);
 }
        public void EditAction_CanSaveValidChanges()
        {
            var controller = new UserController(mock.Object);
            var user = new User { FirstName = "Igor", LastName = "Blinnikov" };
            var actionResult = controller.Edit(user);

            mock.Verify(m => m.SaveUser(user));
            Assert.IsNotInstanceOf<ViewResult>(actionResult);
        }
        public void EditAction_CannotSaveInvalidChanges()
        {
            var controller = new UserController(mock.Object);
            var user = new User { FirstName = "Igor", LastName = "Blinnikov" };
            controller.ModelState.AddModelError("Email", "Email is required");
            var actionResult = controller.Edit(user);

            mock.Verify(m => m.SaveUser(It.IsAny<User>()), Times.Never());
            Assert.IsInstanceOf<ViewResult>(actionResult);
        }
        public void EditAction_WhenInvoking_AllowsEditExistingUser()
        {
            var controller = new UserController(mock.Object);
            var firstUser = (User)((ViewResult)controller.Edit(1)).Model;
            var seconduser = (User)((ViewResult)controller.Edit(2)).Model;
            var thirduser = (User)((ViewResult)controller.Edit(3)).Model;

            Assert.AreEqual(1, firstUser.Id);
            Assert.AreEqual(2, seconduser.Id);
            Assert.AreEqual(3, thirduser.Id);
        }
        public void IndexAction_WhenInvoking_ReturnsFirstPageOfUsers()
        {
            var controller = new UserController(mock.Object);

            var usersResult = ((UsersListViewModel)controller.Index().ViewData.Model).Users;

            Assert.AreEqual(5, usersResult.Length);
            Assert.AreEqual("George", usersResult[0].FirstName);
            Assert.AreEqual("John", usersResult[1].FirstName);
            Assert.AreEqual("Thomas", usersResult[2].FirstName);
            Assert.AreEqual("James", usersResult[3].FirstName);
            Assert.AreEqual("James", usersResult[4].FirstName);
        }
 public void EditAction_WhenInvoking_ProhibitsEditNonexistingUser()
 {
     var controller = new UserController(mock.Object);
     var result = controller.Edit(101);
     Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
 }
        public void IndexAction_WhenInvoking_ReturnViewModel()
        {
            var controller = new UserController(mock.Object);

            var viewModel = (UsersListViewModel)controller.Index(2, 2).Model;

            var pagerData = viewModel.PagerData;
            Assert.AreEqual(2, pagerData.PageNumber);
            Assert.AreEqual(2, pagerData.PageSize);
            Assert.AreEqual(6, pagerData.UsersCount);
            Assert.AreEqual(3, pagerData.PagesCount);
        }