コード例 #1
0
        public void Then_The_Values_Are_Set_Correctly(
            string recipientEmail,
            string employerName,
            string standardName,
            int standardLevel,
            string location,
            int numberOfApprentices,
            string stopSharingUrl)
        {
            //Arrange
            var expectedTokens = new Dictionary <string, string>
            {
                { "AEDEmployerName", employerName },
                { "AEDApprenticeshipTrainingCourse", $"{standardName} (level {standardLevel})" },
                { "AEDApprenticeshipLocation", location },
                { "AEDNumberOfApprentices", numberOfApprentices > 0 ? numberOfApprentices.ToString() : "Not sure" },
                { "AEDStopSharingURL", stopSharingUrl }
            };

            //Act
            var actual = new CreateEmployerDemandReminderEmail(
                recipientEmail,
                employerName,
                standardName,
                standardLevel,
                location,
                numberOfApprentices,
                stopSharingUrl);

            //Assert
            actual.TemplateId.Should().Be(EmailConstants.EmployerDemandReminderTemplateId);
            actual.Tokens.Should().BeEquivalentTo(expectedTokens);
            actual.RecipientAddress.Should().Be(recipientEmail);
        }
コード例 #2
0
        public async Task <Unit> Handle(SendEmployerDemandEmailReminderCommand request, CancellationToken cancellationToken)
        {
            var courseDemand =
                await _employerDemandApiClient.Get <GetEmployerDemandResponse>(
                    new GetEmployerDemandRequest(request.EmployerDemandId));

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

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

            await _employerDemandApiClient.PostWithResponseCode <object>(
                new PostEmployerDemandNotificationAuditRequest(request.Id, request.EmployerDemandId, NotificationType.Reminder));

            return(Unit.Value);
        }
        public async Task Then_A_Notification_Is_Sent_And_Api_Called(
            GetEmployerDemandResponse response,
            SendEmployerDemandEmailReminderCommand command,
            [Frozen] Mock <IEmployerDemandApiClient <EmployerDemandApiConfiguration> > employerDemandApiClient,
            [Frozen] Mock <INotificationService> notificationService,
            SendEmployerDemandEmailReminderCommandHandler 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 CreateEmployerDemandReminderEmail(
                response.ContactEmailAddress,
                response.OrganisationName,
                response.Course.Title,
                response.Course.Level,
                response.Location.Name,
                response.NumberOfApprentices,
                response.StopSharingUrl);


            //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.Reminder}"))), Times.Once);
            actualEmail.Tokens.Should().BeEquivalentTo(expectedEmail.Tokens);
            actualEmail.RecipientsAddress.Should().BeEquivalentTo(expectedEmail.RecipientAddress);
            actualEmail.TemplateId.Should().BeEquivalentTo(expectedEmail.TemplateId);
        }