public async Task<int> UpdateUserRoleAndStatus(CompetentAuthorityUser user, Role role, UserStatus status) { user.UpdateUserStatus(status.ToDomainEnumeration<Domain.User.UserStatus>()); user.UpdateRole(role); return await context.SaveChangesAsync(); }
public void UpdateCompetentAuthorityUserStatus_UserStatusRejected_UpdateToActive_UserStatusUpdateToActive() { var competentAuthorityUser = new CompetentAuthorityUser(Guid.NewGuid().ToString(), Guid.NewGuid(), UserStatus.Rejected, A.Dummy<Role>()); competentAuthorityUser.UpdateUserStatus(UserStatus.Active); Assert.Equal(competentAuthorityUser.UserStatus, UserStatus.Active); }
public async Task <int> UpdateUserRoleAndStatus(CompetentAuthorityUser user, Role role, UserStatus status) { user.UpdateUserStatus(status.ToDomainEnumeration <Domain.User.UserStatus>()); user.UpdateRole(role); return(await context.SaveChangesAsync()); }
public void UpdateCompetentAuthorityUserStatus_UserStatusRejected_UpdateToActive_UserStatusUpdateToActive() { var competentAuthorityUser = new CompetentAuthorityUser(Guid.NewGuid().ToString(), Guid.NewGuid(), UserStatus.Rejected, A.Dummy <Role>()); competentAuthorityUser.UpdateUserStatus(UserStatus.Active); Assert.Equal(competentAuthorityUser.UserStatus, UserStatus.Active); }
public async Task HandleAsync_UserExists_ButIsCurrentUser_ThrowInvalidOperationException() { var userId = Guid.NewGuid(); var competentAuthorityUserId = Guid.NewGuid(); var competentAuthorityUser = new CompetentAuthorityUser(userId.ToString(), Guid.NewGuid(), Domain.User.UserStatus.Pending, A.Dummy<Role>()); var dataAccess = A.Fake<IUpdateCompetentAuthorityUserRoleAndStatusDataAccess>(); A.CallTo(() => dataAccess.GetCompetentAuthorityUser(competentAuthorityUserId)) .Returns(competentAuthorityUser); var userContext = A.Fake<IUserContext>(); A.CallTo(() => userContext.UserId) .Returns(userId); var handler = new UpdateCompetentAuthorityUserRoleAndStatusHandler(userContext, dataAccess, A.Dummy<IWeeeAuthorization>()); await Assert.ThrowsAsync<InvalidOperationException>(() => handler.HandleAsync( new UpdateCompetentAuthorityUserRoleAndStatus(competentAuthorityUserId, A.Dummy<UserStatus>(), A.Dummy<string>()))); }
public async Task HandleAsync_UserExists_ButIsCurrentUser_ThrowInvalidOperationException() { var userId = Guid.NewGuid(); var competentAuthorityUserId = Guid.NewGuid(); var competentAuthorityUser = new CompetentAuthorityUser(userId.ToString(), Guid.NewGuid(), Domain.User.UserStatus.Pending, A.Dummy <Role>()); var dataAccess = A.Fake <IUpdateCompetentAuthorityUserRoleAndStatusDataAccess>(); A.CallTo(() => dataAccess.GetCompetentAuthorityUser(competentAuthorityUserId)) .Returns(competentAuthorityUser); var userContext = A.Fake <IUserContext>(); A.CallTo(() => userContext.UserId) .Returns(userId); var handler = new UpdateCompetentAuthorityUserRoleAndStatusHandler(userContext, dataAccess, A.Dummy <IWeeeAuthorization>()); await Assert.ThrowsAsync <InvalidOperationException>(() => handler.HandleAsync( new UpdateCompetentAuthorityUserRoleAndStatus(competentAuthorityUserId, A.Dummy <UserStatus>(), A.Dummy <string>()))); }
public async Task <Guid> HandleAsync(AddCompetentAuthorityUser message) { var userId = message.UserId; var user = await context.Users.FirstOrDefaultAsync(u => u.Id == userId); if (user == null) { throw new ArgumentException(string.Format("Could not find a user with id {0}", userId)); } // get competent authority from email address int indexofat = user.Email.IndexOf('@'); string email = user.Email.Substring(indexofat + 1); string authorityName = AuthorityName(email); var competentAuthority = await context.UKCompetentAuthorities.FirstOrDefaultAsync(c => c.Abbreviation == authorityName); if (competentAuthority == null) { throw new InvalidOperationException(string.Format("Could not find the competent authority with name: {0}", authorityName)); } var standardRole = await context.Roles.SingleOrDefaultAsync(r => r.Name == Roles.InternalUser.ToString()); if (standardRole == null) { throw new InvalidOperationException(string.Format("Could not find the role name with: {0}", Roles.InternalUser)); } CompetentAuthorityUser competentAuthorityUser = new CompetentAuthorityUser(user.Id, competentAuthority.Id, Domain.User.UserStatus.Pending, standardRole); context.CompetentAuthorityUsers.Add(competentAuthorityUser); await context.SaveChangesAsync(); return(competentAuthorityUser.Id); }
public void UpdateCompetentAuthorityUserStatus_UserStatusRejected_UpdateToPending_ThrowsException() { var competentAuthorityUser = new CompetentAuthorityUser(Guid.NewGuid().ToString(), Guid.NewGuid(), UserStatus.Rejected, A.Dummy<Role>()); Assert.Throws<InvalidOperationException>(() => competentAuthorityUser.UpdateUserStatus(UserStatus.Pending)); }
public void UpdateCompetentAuthorityUserStatus_UserStatusRejected_UpdateToPending_ThrowsException() { var competentAuthorityUser = new CompetentAuthorityUser(Guid.NewGuid().ToString(), Guid.NewGuid(), UserStatus.Rejected, A.Dummy <Role>()); Assert.Throws <InvalidOperationException>(() => competentAuthorityUser.UpdateUserStatus(UserStatus.Pending)); }