Example #1
0
        public void GetDetails()
        {
            MockRoleService service = new MockRoleService();
            RoleController controller = GetRoleController(service);
            var id = service.Roles[0].RoleId;

            ActionResult result = controller.Details(id);

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

            ViewResult viewResult = (ViewResult)result;
            Assert.IsInstanceOfType(viewResult.ViewData.Model, typeof(RoleViewModel));
        }
Example #2
0
        public void GetEdit()
        {
            MockRoleService service = new MockRoleService();
            RoleController controller = GetRoleController(service);
            Role role = service.Roles[0];

            ActionResult result = controller.Edit(role.RoleId);

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

            ViewResult viewResult = (ViewResult)result;

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

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

            Assert.AreEqual(role.RoleName, model.Name);
            Assert.AreEqual(role.RoleId, model.Id);
        }
Example #3
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 #4
0
        public void PostEdit()
        {
            MockRoleService service = new MockRoleService();
            RoleController controller = GetRoleController(service);

            Role role = service.Roles[0];

            RoleEditViewModel model = new RoleEditViewModel()
            {
                Id = role.RoleId,
                Name = "New " + role.RoleName
            };

            ActionResult result = controller.Edit(role.RoleId, model);

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

            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;

            Assert.AreEqual("Details", redirectResult.RouteValues["action"]);
            Assert.AreEqual(role.RoleId, redirectResult.RouteValues["id"]);

            Assert.AreEqual(role.RoleName, model.Name);
            Assert.AreEqual(role.RoleId, model.Id);
        }
Example #5
0
        public void PostCreate()
        {
            MockRoleService service = new MockRoleService();
            RoleController controller = GetRoleController(service);
            int nroles = service.Roles.Count;

            var model = new RoleEditViewModel()
            {
                Name = "New Role",
                Description = "New Role"
            };

            ActionResult result = controller.Create(model);

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

            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;

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

            Assert.AreEqual(nroles + 1, service.Roles.Count);

            Assert.IsNotNull(service.NewRole);
            Assert.AreEqual("New Role", service.NewRole.RoleName);
        }
Example #6
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"]);
        }