Esempio n. 1
0
        public void ThrowWhenRemovingAdminRoleFromAdmin()
        {
            var admin = AuthUserTestHelper.User(Username.ADMIN).WithRoles(RegisteredRole, AdminRole).Build();

            Action removing = () => _userRoleService.RemoveRole(admin, AdminRole);

            removing.Should().Throw <ManualValidationException>();
        }
Esempio n. 2
0
        public void SwapOutRolesWhenAllIsWell()
        {
            var authUser = AuthUserTestHelper.User().WithRoles(PendingRole).Build();

            _userRegistrationService.Register(authUser, RegisteredRole, PendingRole);

            authUser.RoleIds.Should().BeEquivalentTo(RegisteredRole.Id);
        }
Esempio n. 3
0
        public void RemoveRoleWhenAllIsWell()
        {
            var authUser = AuthUserTestHelper.User().WithRoles(RegisteredRole, AdminRole).Build();

            _userRoleService.RemoveRole(authUser, AdminRole);

            authUser.RoleIds.Should().BeEquivalentTo(RegisteredRole.Id);
        }
Esempio n. 4
0
        public void ValidationErrorWhenUserHasNoRoles()
        {
            var authUser = AuthUserTestHelper.User().WithRoles().Build();

            Action registration = () => _userRegistrationService.Register(authUser, RegisteredRole, PendingRole);

            registration.Should().Throw <ManualValidationException>();
        }
Esempio n. 5
0
        public void ThrowWhenRemovingNonAssignedRole()
        {
            var authUser        = AuthUserTestHelper.User().WithRoles(RegisteredRole).Build();
            var nonAssignedRole = AdminRole;

            Action removing = () => _userRoleService.RemoveRole(authUser, nonAssignedRole);

            removing.Should().Throw <ManualValidationException>();
        }
Esempio n. 6
0
        public void ThrowWhenAssigningDuplicateRoles()
        {
            var authUser      = AuthUserTestHelper.User().WithRoles(RegisteredRole).Build();
            var duplicateRole = RegisteredRole;

            Action assigning = () => _userRoleService.AssignRole(authUser, duplicateRole);

            assigning.Should().Throw <ManualValidationException>();
        }
Esempio n. 7
0
        public void ThrowWhenNotPassingPendingRole()
        {
            var authUser  = AuthUserTestHelper.User().WithRoles(PendingRole).Build();
            var wrongRole = RegisteredRole;

            Action registration = () => _userRegistrationService.Register(authUser, RegisteredRole, wrongRole);

            registration.Should().Throw <ArgumentException>();
        }
Esempio n. 8
0
        private void SeedAuthUserDomain(User admin)
        {
            var pendingRegistrationRole = RoleTestHelper.PendingRegistration().Build();
            var registeredUserRole      = RoleTestHelper.RegisteredUser().Build();
            var adminRole = RoleTestHelper.Admin().Build();

            var adminAuthUser = AuthUserTestHelper.FromUserAndRoles(admin, registeredUserRole, adminRole).Build();

            _unitOfWork.WithAuthUserTransaction(tran => {
                _roleRepository.Save(pendingRegistrationRole);
                _roleRepository.Save(registeredUserRole);
                _roleRepository.Save(adminRole);

                _authUserRepository.Save(adminAuthUser);

                tran.Commit();
            });
        }
Esempio n. 9
0
        private void SeedAuthUserDomain(IReadOnlyList <User> users)
        {
            _unitOfWork.WithAuthUserTransaction(tran => {
                var roles = _roleRepository.List();
                var pendingRegistrationRole = roles.Single(r => r.Rolename == Role.PENDING_REGISTRATION_ROLENAME);
                var registeredUserRole      = roles.Single(r => r.Rolename == Role.REGISTERED_USER_ROLENAME);
                var adminRole = roles.Single(r => r.Rolename == Role.ADMIN_ROLENAME);

                foreach (var u in users)
                {
                    var role            = u.Username == "PendingPlayer" ? pendingRegistrationRole : registeredUserRole;
                    var authUserBuilder = AuthUserTestHelper.FromUserAndRoles(u, role).WithPasswordHash("admin");
                    if (u.Username == Username.MATTY)
                    {
                        authUserBuilder.AddRole(adminRole);
                    }

                    _authUserRepository.Save(authUserBuilder.Build());
                }

                tran.Commit();
            });
        }
Esempio n. 10
0
 private static AuthUser BuildAuthUser(long id, string name, params Role[] roles)
 {
     return(AuthUserTestHelper.User(name).WithId(id).WithRoles(roles).Build());
 }