public AllUserRoleViewModel BuildUserRoleViewModel()
        {
            AllUserRoleViewModel allUsersModel = new AllUserRoleViewModel()
            {
                AllUsers = new List <UserRoleViewModel>(),
            };

            var users     = _userRepository.GetUsers();
            var userRoles = _userRepository.GetUserRoles();
            var allRoles  = _userRepository.GetRoles();

            foreach (var user in users)
            {
                var currentRole = _userRepository.GetUserRole(user.Id);

                var UserRoleModel = new UserRoleViewModel()
                {
                    UserId         = user.Id,
                    Role           = allRoles.Find(x => x.Id == currentRole.Id).Name,
                    Username       = user.UserName,
                    AvailableRoles = BuildAvailableRolesList(currentRole)
                };

                allUsersModel.AllUsers.Add(UserRoleModel);
            }
            return(allUsersModel);
        }
示例#2
0
        public void When_Index_Returns_AllUserRoleViewModel()
        {
            //Given
            var model = new AllUserRoleViewModel();

            _adminModelBuilder.Setup(x => x.BuildUserRoleViewModel()).Returns(model);
            //When
            var result = _adminController.ManageUserRoles() as ViewResult;

            //Then
            Assert.NotNull(result);
            Assert.AreEqual(String.Empty, result.ViewName);
            Assert.IsInstanceOf <AllUserRoleViewModel>(result.Model);
        }