Exemple #1
0
        public void And_No_NumberOfApprentices_Then_NotSure_Text(
            string recipientEmail,
            string recipientName,
            string standardName,
            int standardLevel,
            string location,
            string startSharingUrl)
        {
            var expectedTokens = new Dictionary <string, string>
            {
                { "AEDEmployerName", recipientName },
                { "AEDApprenticeshipTrainingCourse", $"{standardName} (level {standardLevel})" },
                { "AEDApprenticeshipLocation", location },
                { "AEDNumberOfApprentices", "Not sure" },
                { "AEDStartSharingURL", startSharingUrl }
            };

            var email = new StopSharingExpiredEmployerDemandEmail(
                recipientEmail,
                recipientName,
                standardName,
                standardLevel,
                location,
                0,
                startSharingUrl);

            email.Tokens.Should().BeEquivalentTo(expectedTokens);
        }
Exemple #2
0
        public void Then_Values_Are_Set_Correctly(
            string recipientEmail,
            string recipientName,
            string standardName,
            int standardLevel,
            string location,
            int numberOfApprentices,
            string startSharingUrl)
        {
            var expectedTokens = new Dictionary <string, string>
            {
                { "AEDEmployerName", recipientName },
                { "AEDApprenticeshipTrainingCourse", $"{standardName} (level {standardLevel})" },
                { "AEDApprenticeshipLocation", location },
                { "AEDNumberOfApprentices", numberOfApprentices.ToString() },
                { "AEDStartSharingURL", startSharingUrl }
            };

            var email = new StopSharingExpiredEmployerDemandEmail(
                recipientEmail,
                recipientName,
                standardName,
                standardLevel,
                location,
                numberOfApprentices,
                startSharingUrl);

            email.TemplateId.Should().Be(EmailConstants.StopSharingExpiredEmployerDemandTemplateId);
            email.RecipientAddress.Should().Be(recipientEmail);
            email.ReplyToAddress.Should().Be(EmailConstants.ReplyToAddress);
            email.Tokens.Should().BeEquivalentTo(expectedTokens);
        }
        public async Task <Unit> Handle(SendAutomaticEmployerDemandDemandCutOffCommand request, CancellationToken cancellationToken)
        {
            var courseDemand =
                await _employerDemandApiClient.Get <GetEmployerDemandResponse>(
                    new GetEmployerDemandRequest(request.EmployerDemandId));

            var emailModel = new StopSharingExpiredEmployerDemandEmail(courseDemand.ContactEmailAddress,
                                                                       courseDemand.OrganisationName, courseDemand.Course.Title, courseDemand.Course.Level,
                                                                       courseDemand.Location.Name, courseDemand.NumberOfApprentices, courseDemand.StartSharingUrl);

            await _notificationService.Send(new SendEmailCommand(emailModel.TemplateId, emailModel.RecipientAddress, emailModel.Tokens));

            var auditTask = _employerDemandApiClient.PostWithResponseCode <object>(
                new PostEmployerDemandNotificationAuditRequest(request.Id, request.EmployerDemandId, NotificationType.StoppedAutomaticCutOff));
            var patchTask = _employerDemandApiClient.PatchWithResponseCode(new PatchCourseDemandRequest(
                                                                               request.EmployerDemandId, new PatchOperation
            {
                Path  = "Stopped",
                Value = true
            }));

            await Task.WhenAll(auditTask, patchTask);

            return(Unit.Value);
        }
Exemple #4
0
        public async Task Then_The_Command_Is_Handled_And_EmailSent_And_Demand_Updated(
            GetEmployerDemandResponse response,
            SendAutomaticEmployerDemandDemandCutOffCommand command,
            [Frozen] Mock <IEmployerDemandApiClient <EmployerDemandApiConfiguration> > employerDemandApiClient,
            [Frozen] Mock <INotificationService> notificationService,
            SendAutomaticEmployerDemandDemandCutOffCommandHandler 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 StopSharingExpiredEmployerDemandEmail(
                response.ContactEmailAddress,
                response.OrganisationName,
                response.Course.Title,
                response.Course.Level,
                response.Location.Name,
                response.NumberOfApprentices,
                response.StartSharingUrl);

            //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.StoppedAutomaticCutOff}"))), 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);
        }