public void And_No_NumberOfApprentices_Then_NotSure_Text( string recipientEmail, string recipientName, string standardName, int standardLevel, string location) { var expectedTokens = new Dictionary <string, string> { { "AEDEmployerName", recipientName }, { "AEDApprenticeshipTrainingCourse", $"{standardName} (level {standardLevel})" }, { "AEDApprenticeshipLocation", location }, { "AEDNumberOfApprentices", "Not sure" } }; var email = new StopSharingEmployerDemandCourseClosedEmail( recipientEmail, recipientName, standardName, standardLevel, location, 0); email.Tokens.Should().BeEquivalentTo(expectedTokens); }
public async Task <Unit> Handle(CourseStoppedCommand request, CancellationToken cancellationToken) { var courseDemand = await _employerDemandApiClient.Get <GetEmployerDemandResponse>( new GetEmployerDemandRequest(request.EmployerDemandId)); var emailModel = new StopSharingEmployerDemandCourseClosedEmail( courseDemand.ContactEmailAddress, courseDemand.OrganisationName, courseDemand.Course.Title, courseDemand.Course.Level, courseDemand.Location.Name, courseDemand.NumberOfApprentices); await _notificationService.Send(new SendEmailCommand(emailModel.TemplateId, emailModel.RecipientAddress, emailModel.Tokens)); var auditTask = _employerDemandApiClient.PostWithResponseCode <object>( new PostEmployerDemandNotificationAuditRequest(request.Id, request.EmployerDemandId, NotificationType.StoppedCourseClosed)); var patchTask = _employerDemandApiClient.PatchWithResponseCode(new PatchCourseDemandRequest( request.EmployerDemandId, new PatchOperation { Path = "Stopped", Value = true })); await Task.WhenAll(auditTask, patchTask); return(Unit.Value); }
public void Then_Values_Are_Set_Correctly( string recipientEmail, string recipientName, string standardName, int standardLevel, string location, int numberOfApprentices) { var expectedTokens = new Dictionary <string, string> { { "AEDEmployerName", recipientName }, { "AEDApprenticeshipTrainingCourse", $"{standardName} (level {standardLevel})" }, { "AEDApprenticeshipLocation", location }, { "AEDNumberOfApprentices", numberOfApprentices.ToString() } }; var email = new StopSharingEmployerDemandCourseClosedEmail( recipientEmail, recipientName, standardName, standardLevel, location, numberOfApprentices); email.TemplateId.Should().Be(EmailConstants.StopSharingEmployerDemandCourseClosedTemplateId); email.RecipientAddress.Should().Be(recipientEmail); email.ReplyToAddress.Should().Be(EmailConstants.ReplyToAddress); email.Tokens.Should().BeEquivalentTo(expectedTokens); }
public async Task Then_The_Command_Is_Handled_And_EmailSent_And_Demand_Updated( GetEmployerDemandResponse response, CourseStoppedCommand command, [Frozen] Mock <IEmployerDemandApiClient <EmployerDemandApiConfiguration> > employerDemandApiClient, [Frozen] Mock <INotificationService> notificationService, CourseStoppedCommandHandler handler) { //Arrange employerDemandApiClient.Setup(x => x.Get <GetEmployerDemandResponse>(It.Is <GetEmployerDemandRequest>(c => c.GetUrl.Contains(command.EmployerDemandId.ToString())))) .ReturnsAsync(response); SendEmailCommand actualEmail = null; notificationService .Setup(service => service.Send(It.IsAny <SendEmailCommand>())) .Callback((SendEmailCommand args) => actualEmail = args) .Returns(Task.CompletedTask); var expectedEmail = new StopSharingEmployerDemandCourseClosedEmail( response.ContactEmailAddress, response.OrganisationName, response.Course.Title, response.Course.Level, response.Location.Name, response.NumberOfApprentices); //Act await handler.Handle(command, CancellationToken.None); //Assert employerDemandApiClient.Verify( x => x.PostWithResponseCode <object>(It.Is <PostEmployerDemandNotificationAuditRequest>(c => c.PostUrl.Contains($"{command.EmployerDemandId}/notification-audit/{command.Id}?notificationType={(short)NotificationType.StoppedCourseClosed}"))), Times.Once); employerDemandApiClient.Verify( x => x.PatchWithResponseCode(It.Is <PatchCourseDemandRequest>(c => c.PatchUrl.Contains($"api/demand/{command.EmployerDemandId}") && c.Data.FirstOrDefault().Path.Equals("Stopped") && c.Data.FirstOrDefault().Value.Equals(true) )), Times.Once); actualEmail.Tokens.Should().BeEquivalentTo(expectedEmail.Tokens); actualEmail.RecipientsAddress.Should().BeEquivalentTo(expectedEmail.RecipientAddress); actualEmail.TemplateId.Should().BeEquivalentTo(expectedEmail.TemplateId); }