public async Task <IActionResult> InviteEmployeruser(NewEmployerUserViewModel model, string command) { if (command == "Change") { return(View("NewEmployerUser", model)); } if (!ModelState.IsValid) { return(View("ReviewDetails", model)); } var ukprn = _authenticationService.Ukprn.Value; var userId = _authenticationService.UserId; _authenticationService.TryGetUserClaimValue(ProviderClaims.DisplayName, out string providerUserFullName); var provider = await _mediator.Send(new GetProviderByUkprnQuery(ukprn), new CancellationToken()); var employerOrganisation = model.EmployerOrganisation.Trim(); var employerFirstName = model.EmployerFirstName.Trim(); var employerLastName = model.EmployerLastName.Trim(); var employerEmail = model.EmployerEmailAddress.Trim().ToLower(); var employerFullName = string.Concat(employerFirstName, " ", employerLastName); var correlationId = await _mediator.Send(new AddInvitationCommand(ukprn, userId, provider.ProviderName, providerUserFullName, employerOrganisation, employerFirstName, employerLastName, employerEmail)); await _mediator.Send(new SendInvitationEmailCommand(ukprn, provider.ProviderName, providerUserFullName, employerOrganisation, employerFullName, employerEmail, correlationId)); return(View("InviteConfirmation")); }
public async Task ThenAnInvitationIsAdded( [Frozen] Mock <IMediator> mediator, [Frozen] Mock <IAuthenticationService> authService, RegistrationController controller, NewEmployerUserViewModel model, string command, string providerName) { //arrange authService.Object.TryGetUserClaimValue(ProviderClaims.DisplayName, out var displayName); mediator.Setup(s => s.Send(It.IsAny <GetProviderByUkprnQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GetProviderByUkprnQueryResult(providerName)); //act await controller.InviteEmployeruser(model, command); //assert mediator.Verify(x => x.Send(It.Is <AddInvitationCommand>(s => s.EmployerEmail == model.EmployerEmailAddress && s.EmployerFirstName == model.EmployerFirstName && s.EmployerLastName == model.EmployerLastName && s.EmployerOrganisation == model.EmployerOrganisation && s.Ukprn == authService.Object.Ukprn.Value && s.UserRef == authService.Object.UserId && s.ProviderOrganisationName == providerName && s.ProviderUserFullName == displayName), It.IsAny <CancellationToken>()), Times.Once); }
public IActionResult NewEmployerUser(NewEmployerUserViewModel model) { if (!ModelState.IsValid) { return(View("NewEmployerUser", model)); } return(View("ReviewDetails", model)); }