public void ThrowWhenRemovingAdminRoleFromAdmin() { var admin = AuthUserTestHelper.User(Username.ADMIN).WithRoles(RegisteredRole, AdminRole).Build(); Action removing = () => _userRoleService.RemoveRole(admin, AdminRole); removing.Should().Throw <ManualValidationException>(); }
public void SwapOutRolesWhenAllIsWell() { var authUser = AuthUserTestHelper.User().WithRoles(PendingRole).Build(); _userRegistrationService.Register(authUser, RegisteredRole, PendingRole); authUser.RoleIds.Should().BeEquivalentTo(RegisteredRole.Id); }
public void RemoveRoleWhenAllIsWell() { var authUser = AuthUserTestHelper.User().WithRoles(RegisteredRole, AdminRole).Build(); _userRoleService.RemoveRole(authUser, AdminRole); authUser.RoleIds.Should().BeEquivalentTo(RegisteredRole.Id); }
public void ValidationErrorWhenUserHasNoRoles() { var authUser = AuthUserTestHelper.User().WithRoles().Build(); Action registration = () => _userRegistrationService.Register(authUser, RegisteredRole, PendingRole); registration.Should().Throw <ManualValidationException>(); }
public void ThrowWhenRemovingNonAssignedRole() { var authUser = AuthUserTestHelper.User().WithRoles(RegisteredRole).Build(); var nonAssignedRole = AdminRole; Action removing = () => _userRoleService.RemoveRole(authUser, nonAssignedRole); removing.Should().Throw <ManualValidationException>(); }
public void ThrowWhenAssigningDuplicateRoles() { var authUser = AuthUserTestHelper.User().WithRoles(RegisteredRole).Build(); var duplicateRole = RegisteredRole; Action assigning = () => _userRoleService.AssignRole(authUser, duplicateRole); assigning.Should().Throw <ManualValidationException>(); }
public void ThrowWhenNotPassingPendingRole() { var authUser = AuthUserTestHelper.User().WithRoles(PendingRole).Build(); var wrongRole = RegisteredRole; Action registration = () => _userRegistrationService.Register(authUser, RegisteredRole, wrongRole); registration.Should().Throw <ArgumentException>(); }
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(); }); }
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(); }); }
private static AuthUser BuildAuthUser(long id, string name, params Role[] roles) { return(AuthUserTestHelper.User(name).WithId(id).WithRoles(roles).Build()); }