public async Task <IHttpActionResult> ActivateUserAccount(ActivatedUserAccountData model) { var result = await userManager.ConfirmEmailAsync(model.Id.ToString(), model.Code); if (result.Succeeded) { var competentAuthorityUser = await getAdminUserDataAccess.GetAdminUserOrDefault(model.Id); if (competentAuthorityUser != null && competentAuthorityUser.UserStatus == UserStatus.Pending) { var viewUserRoute = model.ViewUserRoute; viewUserRoute.CompetentAuthorityUserID = competentAuthorityUser.Id.ToString(); var viewUserUrl = viewUserRoute.GenerateUrl(); await emailService.SendInternalUserAccountActivated( competentAuthorityUser.CompetentAuthority.Email, competentAuthorityUser.User.FullName, competentAuthorityUser.User.Email, viewUserUrl); } } return(Ok(result.Succeeded)); }
public async Task <bool> ActivateUserAccountEmailAsync(ActivatedUserAccountData activatedUserAccountData, string accessToken) { httpClient.SetBearerToken(accessToken); var response = await httpClient.PostAsJsonAsync(Controller + "ActivateUserAccount", activatedUserAccountData); return(await response.CreateResponseAsync <bool>()); }
public async Task ActivateUserAccount_SendsCompetentAuthorityEmail_WhenUserStatusIsPendingOnly(int userStatus) { // Arrange var builder = new UnauthenticatedUserControllerBuilder(); A.CallTo(() => builder.UserManager.ConfirmEmailAsync(A <string> ._, A <string> ._)) .Returns(IdentityResult.Success); var userId = Guid.NewGuid(); string emailAddress = "*****@*****.**"; var competentAuthority = new UKCompetentAuthority( A.Dummy <Guid>(), "EA", "EA", A.Dummy <Country>(), emailAddress, 0); var competentAuthorityUser = A.Fake <CompetentAuthorityUser>(); A.CallTo(() => competentAuthorityUser.CompetentAuthority) .Returns(competentAuthority); A.CallTo(() => competentAuthorityUser.UserStatus) .Returns(Enumeration.FromValue <UserStatus>(userStatus)); A.CallTo(() => builder.GetAdminUserDataAccess.GetAdminUserOrDefault(userId)) .Returns(competentAuthorityUser); var viewUserRoute = A.Fake <ViewCompetentAuthorityUserRoute>(); var activatedUserAccountData = new ActivatedUserAccountData { Id = userId, ViewUserRoute = viewUserRoute }; var controller = builder.Build(); // Act await controller.ActivateUserAccount(activatedUserAccountData); // Assert A.CallTo(() => builder.GetAdminUserDataAccess.GetAdminUserOrDefault(A <Guid> ._)) .MustHaveHappened(); A.CallTo(() => builder.EmailService.SendInternalUserAccountActivated(A <string> ._, A <string> ._, A <string> ._, A <string> ._)) .MustNotHaveHappened(); }
public async Task ActivateUserAccount_SendsEmailWithViewUserUrl() { // Arrange var builder = new UnauthenticatedUserControllerBuilder(); A.CallTo(() => builder.UserManager.ConfirmEmailAsync(A <string> ._, A <string> ._)) .Returns(IdentityResult.Success); var userId = Guid.NewGuid(); var user = new User(userId.ToString(), "FirstName", "SecondName", "*****@*****.**"); var competentAuthorityUser = A.Fake <CompetentAuthorityUser>(); A.CallTo(() => competentAuthorityUser.User) .Returns(user); A.CallTo(() => competentAuthorityUser.UserStatus) .Returns(UserStatus.Pending); A.CallTo(() => builder.GetAdminUserDataAccess.GetAdminUserOrDefault(userId)) .Returns(competentAuthorityUser); string viewUserUrl = "http://localhost/EditUser/abc"; var viewUserRoute = A.Fake <ViewCompetentAuthorityUserRoute>(); A.CallTo(() => viewUserRoute.GenerateUrl()) .Returns(viewUserUrl); var activatedUserAccountData = new ActivatedUserAccountData { Id = userId, ViewUserRoute = viewUserRoute }; var controller = builder.Build(); // Act await controller.ActivateUserAccount(activatedUserAccountData); // Assert A.CallTo(() => builder.EmailService.SendInternalUserAccountActivated(A <string> ._, A <string> ._, A <string> ._, viewUserUrl)) .MustHaveHappened(); }
public async Task ActivateUserAccount_InvokesApiWithCorrectParameters() { // Arrange var controller = AccountController(); var userId = Guid.NewGuid(); string code = "Code"; var accessToken = "token"; var viewUserRoute = A.Fake <ViewCompetentAuthorityUserRoute>(); A.CallTo(() => externalRouteService.ViewCompetentAuthorityUserRoute) .Returns(viewUserRoute); ActivatedUserAccountData activatedUserAccountData = null; A.CallTo(() => apiClient.User.ActivateUserAccountEmailAsync(A <ActivatedUserAccountData> ._, A <string> ._)) .Invokes((ActivatedUserAccountData a, string b) => { activatedUserAccountData = a; accessToken = b; }) .Returns(true); // Act await controller.ActivateUserAccount(userId, code); // Assert A.CallTo(() => apiClient.User.ActivateUserAccountEmailAsync(A <ActivatedUserAccountData> ._, accessToken)) .MustHaveHappened(Repeated.Exactly.Once); Assert.NotNull(activatedUserAccountData); Assert.Equal(userId, activatedUserAccountData.Id); Assert.Equal(code, activatedUserAccountData.Code); Assert.Same(viewUserRoute, activatedUserAccountData.ViewUserRoute); }
public async Task<bool> ActivateUserAccountEmailAsync(ActivatedUserAccountData activatedUserAccountData) { var response = await httpClient.PostAsJsonAsync(Controller + "ActivateUserAccount", activatedUserAccountData); return await response.CreateResponseAsync<bool>(); }
public async Task<IHttpActionResult> ActivateUserAccount(ActivatedUserAccountData model) { var result = await userManager.ConfirmEmailAsync(model.Id.ToString(), model.Code); if (result.Succeeded) { var competentAuthorityUser = await getAdminUserDataAccess.GetAdminUserOrDefault(model.Id); if (competentAuthorityUser != null && competentAuthorityUser.UserStatus == UserStatus.Pending) { var viewUserRoute = model.ViewUserRoute; viewUserRoute.CompetentAuthorityUserID = competentAuthorityUser.Id.ToString(); var viewUserUrl = viewUserRoute.GenerateUrl(); await emailService.SendInternalUserAccountActivated( competentAuthorityUser.CompetentAuthority.Email, competentAuthorityUser.User.FullName, competentAuthorityUser.User.Email, viewUserUrl); } } return Ok(result.Succeeded); }