public async Task <Guid> Handle(CreateProviderInterestsCommand request, CancellationToken cancellationToken) { var result = await _apiClient.PostWithResponseCode <PostCreateProviderInterestsResponse>( new PostCreateProviderInterestsRequest(request)); if (result.StatusCode == System.Net.HttpStatusCode.Created) { foreach (var employerDemandId in request.EmployerDemandIds) { var employerDemand = await _apiClient.Get <GetEmployerDemandResponse>( new GetEmployerDemandRequest(employerDemandId)); var email = new ProviderIsInterestedEmail( employerDemand.ContactEmailAddress, employerDemand.OrganisationName, employerDemand.Course.Title, employerDemand.Course.Level, employerDemand.Location.Name, employerDemand.NumberOfApprentices, request.ProviderName, request.Email, request.Phone, request.Website, request.FatUrl, employerDemand.StopSharingUrl); await _notificationService.Send(new SendEmailCommand(email.TemplateId, email.RecipientAddress, email.Tokens)); } } return(result.Body.Id); }
public void And_No_NumberOfApprentices_Then_NotSure_Text( string recipientEmail, string recipientName, int standardId, string standardName, int standardLevel, string location, int ukprn, string providerName, string providerEmail, string providerPhone, string providerWebsite, string fatUrl, string stopSharingUrl) { var email = new ProviderIsInterestedEmail( recipientEmail, recipientName, standardName, standardLevel, location, 0, providerName, providerEmail, providerPhone, providerWebsite, fatUrl, stopSharingUrl); email.Tokens["AEDNumberOfApprentices"].Should().Be("Not sure"); }
public void And_No_ProviderWebsite_Then_Alternative_Text( string recipientEmail, string recipientName, string standardName, int standardLevel, string location, int numberOfApprentices, string providerName, string providerEmail, string providerPhone, string fatUrl, string stopSharingUrl) { var email = new ProviderIsInterestedEmail( recipientEmail, recipientName, standardName, standardLevel, location, numberOfApprentices, providerName, providerEmail, providerPhone, null, fatUrl, stopSharingUrl); email.Tokens["AEDProviderWebsite"].Should().Be("-"); }
public async Task And_ResponseCode_Is_Created_Then_Sends_Emails( CreateProviderInterestsCommand command, PostCreateProviderInterestsResponse responseBody, List <GetEmployerDemandResponse> employerDemandsFromApi, [Frozen] Mock <IEmployerDemandApiClient <EmployerDemandApiConfiguration> > mockApiClient, [Frozen] Mock <INotificationService> mockNotificationService, CreateProviderInterestsCommandHandler handler) { //Arrange var apiResponse = new ApiResponse <PostCreateProviderInterestsResponse>(responseBody, HttpStatusCode.Created, null); mockApiClient .Setup(client => client.PostWithResponseCode <PostCreateProviderInterestsResponse>(It.IsAny <PostCreateProviderInterestsRequest>())) .ReturnsAsync(apiResponse); mockNotificationService .Setup(service => service.Send(It.IsAny <SendEmailCommand>())) .Returns(Task.CompletedTask); mockApiClient .SetupSequence(client => client.Get <GetEmployerDemandResponse>(It.IsAny <GetEmployerDemandRequest>())) .ReturnsAsync(employerDemandsFromApi[0]) .ReturnsAsync(employerDemandsFromApi[1]) .ReturnsAsync(employerDemandsFromApi[2]); //Act var response = await handler.Handle(command, CancellationToken.None); //Assert response.Should().Be(responseBody.Id); var employerDemandIds = command.EmployerDemandIds.ToList(); for (var i = 0; i < employerDemandIds.Count; i++) { var providerInterestedEmail = new ProviderIsInterestedEmail( employerDemandsFromApi[i].ContactEmailAddress, employerDemandsFromApi[i].OrganisationName, employerDemandsFromApi[i].Course.Title, employerDemandsFromApi[i].Course.Level, employerDemandsFromApi[i].Location.Name, employerDemandsFromApi[i].NumberOfApprentices, command.ProviderName, command.Email, command.Phone, command.Website, command.FatUrl, employerDemandsFromApi[i].StopSharingUrl); mockApiClient.Verify(client => client.Get <GetEmployerDemandResponse>(It.Is <GetEmployerDemandRequest>(request => request.GetUrl.Contains(employerDemandIds[i].ToString())))); mockNotificationService.Verify(service => service.Send(It.Is <SendEmailCommand>(emailCommand => emailCommand.TemplateId == EmailConstants.ProviderInterestedTemplateId && emailCommand.RecipientsAddress == employerDemandsFromApi[i].ContactEmailAddress && emailCommand.Tokens.Count == providerInterestedEmail.Tokens.Count && !emailCommand.Tokens.Except(providerInterestedEmail.Tokens).Any()))); } }
public void Then_Values_Are_Set_Correctly( string recipientEmail, string recipientName, string standardName, int standardLevel, string location, int numberOfApprentices, string providerName, string providerEmail, string providerPhone, string providerWebsite, string fatUrl, string stopSharingUrl) { var expectedTokens = new Dictionary <string, string> { { "AEDEmployerName", recipientName }, { "AEDApprenticeshipTrainingCourse", $"{standardName} (level {standardLevel})" }, { "AEDApprenticeshipLocation", location }, { "AEDNumberOfApprentices", numberOfApprentices.ToString() }, { "AEDProviderName", providerName }, { "AEDProviderEmail", providerEmail }, { "AEDProviderTelephone", providerPhone }, { "AEDProviderWebsite", providerWebsite }, { "FatURL", $"You can find out more about this training provider at {fatUrl}" }, { "AEDStopSharingURL", stopSharingUrl } }; var email = new ProviderIsInterestedEmail( recipientEmail, recipientName, standardName, standardLevel, location, numberOfApprentices, providerName, providerEmail, providerPhone, providerWebsite, fatUrl, stopSharingUrl); email.TemplateId.Should().Be(EmailConstants.ProviderInterestedTemplateId); email.RecipientAddress.Should().Be(recipientEmail); email.ReplyToAddress.Should().Be(EmailConstants.ReplyToAddress); email.Tokens.Should().BeEquivalentTo(expectedTokens); }