Example #1
0
        public void DeactivateUser()
        {
            MockUserService service = new MockUserService();
            UserController controller = GetUserController(service);
            User user = service.Users[0];
            user.Inactive = false;
            var id = user.UserId;

            ActionResult result = controller.Deactivate(id);

            Assert.IsTrue(user.Inactive);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));

            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;

            Assert.AreEqual("Details", redirectResult.RouteValues["action"]);
            Assert.AreEqual(id, redirectResult.RouteValues["id"]);
        }
Example #2
0
        public void AddToRole()
        {
            MockRoleService service = new MockRoleService();
            MockUserService userService = new MockUserService();
            RoleController controller = GetRoleController(service, userService);
            Role role = service.Roles[0];
            var id = role.RoleId;
            var userId = userService.Users[0].UserId;

            ActionResult result = controller.AddToRole(id, userId);

            Assert.AreEqual(1, role.Users.Count());

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));

            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;

            Assert.AreEqual("Details", redirectResult.RouteValues["action"]);
            Assert.AreEqual(id, redirectResult.RouteValues["id"]);
        }
Example #3
0
        public void RemoveFromRole()
        {
            MockUserService service = new MockUserService();
            MockRoleService roleService = new MockRoleService();
            UserController controller = GetUserController(service, roleService);
            User user = service.Users[0];
            var id = user.UserId;
            var role = roleService.Roles[0];
            var roleId = role.RoleId;

            roleService.AddUserToRole(role, user);

            ActionResult result = controller.RemoveFromRole(id, roleId);

            Assert.AreEqual(0, user.Roles.Count());

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));

            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;

            Assert.AreEqual("Details", redirectResult.RouteValues["action"]);
            Assert.AreEqual(id, redirectResult.RouteValues["id"]);
        }
Example #4
0
        public void PostEdit()
        {
            MockUserService service = new MockUserService();
            UserController controller = GetUserController(service);
            User user = service.Users[0];
            var model = new UserViewModel()
            {
                Id = user.UserId,
                Name = "New " + user.Name,
                Email = "new" + user.Email
            };

            ActionResult result = controller.Edit(user.UserId, model);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));

            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;

            Assert.AreEqual("Details", redirectResult.RouteValues["action"]);
            Assert.AreEqual(user.UserId, redirectResult.RouteValues["id"]);

            Assert.IsNotNull(service.UpdatedUser);

            Assert.AreEqual(service.UpdatedUser.Name, model.Name);
            Assert.AreEqual(service.UpdatedUser.Email, model.Email);
        }
Example #5
0
        public void GetEdit()
        {
            MockUserService service = new MockUserService();
            UserController controller = GetUserController(service);
            User user = service.Users[0];

            ActionResult result = controller.Edit(user.UserId);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));

            ViewResult viewResult = (ViewResult)result;

            Assert.IsNotNull(viewResult.ViewData.Model);
            Assert.IsInstanceOfType(viewResult.ViewData.Model, typeof(UserViewModel));

            var model = (UserViewModel)viewResult.ViewData.Model;

            Assert.AreEqual(user.Name, model.Name);
            Assert.AreEqual(user.Email, model.Email);
            Assert.AreEqual(user.UserId, model.Id);
        }
Example #6
0
        public void GetDetails()
        {
            MockUserService service = new MockUserService();
            UserController controller = GetUserController(service);
            var id = service.GetUsers().First().UserId;

            ActionResult result = controller.Details(id);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));

            ViewResult viewResult = (ViewResult)result;
            Assert.IsInstanceOfType(viewResult.ViewData.Model, typeof(UserViewModel));
        }