Пример #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 StopSharingEmployerDemandEmail(
                recipientEmail,
                recipientName,
                standardName,
                standardLevel,
                location,
                0,
                startSharingUrl);

            email.Tokens.Should().BeEquivalentTo(expectedTokens);
        }
Пример #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 StopSharingEmployerDemandEmail(
                recipientEmail,
                recipientName,
                standardName,
                standardLevel,
                location,
                numberOfApprentices,
                startSharingUrl);

            email.TemplateId.Should().Be(EmailConstants.StopSharingEmployerDemandTemplateId);
            email.RecipientAddress.Should().Be(recipientEmail);
            email.ReplyToAddress.Should().Be(EmailConstants.ReplyToAddress);
            email.Tokens.Should().BeEquivalentTo(expectedTokens);
        }
Пример #3
0
        public async Task <StopEmployerDemandCommandResult> Handle(StopEmployerDemandCommand request, CancellationToken cancellationToken)
        {
            var getEmployerDemandResponse = await _demandApiClient.Get <GetEmployerDemandResponse>(
                new GetEmployerDemandRequest(request.EmployerDemandId));

            if (getEmployerDemandResponse == null)
            {
                return(new StopEmployerDemandCommandResult());
            }

            if (getEmployerDemandResponse.Stopped)
            {
                return(new StopEmployerDemandCommandResult
                {
                    EmployerDemand = getEmployerDemandResponse
                });
            }

            var stopDemandResponse = await _demandApiClient.PatchWithResponseCode(
                new PatchCourseDemandRequest(request.EmployerDemandId, new PatchOperation
            {
                Path = "Stopped",
                Value = true
            }));

            if (stopDemandResponse.StatusCode != HttpStatusCode.OK)
            {
                throw new HttpRequestContentException($"Response status code does not indicate success: {(int)stopDemandResponse.StatusCode} ({stopDemandResponse.StatusCode})", stopDemandResponse.StatusCode, stopDemandResponse.ErrorContent);
            }

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

            var stopDemandResponseBody =
                JsonConvert.DeserializeObject <GetEmployerDemandResponse>(stopDemandResponse.Body);

            var emailArgs = new StopSharingEmployerDemandEmail(
                stopDemandResponseBody.ContactEmailAddress,
                stopDemandResponseBody.OrganisationName,
                stopDemandResponseBody.Course.Title,
                stopDemandResponseBody.Course.Level,
                stopDemandResponseBody.Location.Name,
                stopDemandResponseBody.NumberOfApprentices,
                stopDemandResponseBody.StartSharingUrl);
            await _notificationService.Send(new SendEmailCommand(
                                                EmailConstants.StopSharingEmployerDemandTemplateId,
                                                stopDemandResponseBody.ContactEmailAddress,
                                                emailArgs.Tokens));

            return(new StopEmployerDemandCommandResult
            {
                EmployerDemand = stopDemandResponseBody
            });
        }
Пример #4
0
        public async Task Then_The_Api_Is_Called_And_Email_Sent_If_ResponseCode_Is_Ok_And_Audit_Created(
            StopEmployerDemandCommand command,
            GetEmployerDemandResponse getDemandResponse,
            GetEmployerDemandResponse stopResponseBody,
            [Frozen] Mock <IEmployerDemandApiClient <EmployerDemandApiConfiguration> > mockApiClient,
            [Frozen] Mock <INotificationService> mockNotificationService,
            StopEmployerDemandCommandHandler handler)
        {
            //Arrange
            getDemandResponse.Stopped = false;
            var stopResponse = new ApiResponse <string>(JsonConvert.SerializeObject(stopResponseBody), HttpStatusCode.OK, "");

            mockApiClient
            .Setup(client => client.PatchWithResponseCode(
                       It.Is <PatchCourseDemandRequest>(c => c.PatchUrl.Contains(command.EmployerDemandId.ToString()) &&
                                                        c.Data.FirstOrDefault().Path.Equals("Stopped") &&
                                                        c.Data.FirstOrDefault().Value.Equals(true)
                                                        )))
            .ReturnsAsync(stopResponse);
            mockApiClient
            .Setup(client => client.Get <GetEmployerDemandResponse>(
                       It.Is <GetEmployerDemandRequest>(request => request.GetUrl.Contains($"demand/{command.EmployerDemandId}"))))
            .ReturnsAsync(getDemandResponse);

            SendEmailCommand actualEmail = null;

            mockNotificationService
            .Setup(service => service.Send(It.IsAny <SendEmailCommand>()))
            .Callback((SendEmailCommand args) => actualEmail = args)
            .Returns(Task.CompletedTask);
            var expectedEmail = new StopSharingEmployerDemandEmail(
                stopResponseBody.ContactEmailAddress,
                stopResponseBody.OrganisationName,
                stopResponseBody.Course.Title,
                stopResponseBody.Course.Level,
                stopResponseBody.Location.Name,
                stopResponseBody.NumberOfApprentices,
                stopResponseBody.StartSharingUrl);

            //Act
            var actual = await handler.Handle(command, CancellationToken.None);

            //Assert
            actual.EmployerDemand.Should().BeEquivalentTo(stopResponseBody);
            actualEmail.Tokens.Should().BeEquivalentTo(expectedEmail.Tokens);
            actualEmail.RecipientsAddress.Should().BeEquivalentTo(expectedEmail.RecipientAddress);
            actualEmail.TemplateId.Should().BeEquivalentTo(expectedEmail.TemplateId);
            mockApiClient.Verify(
                x => x.PostWithResponseCode <object>(It.Is <PostEmployerDemandNotificationAuditRequest>(c =>
                                                                                                        c.PostUrl.Contains($"{command.EmployerDemandId}/notification-audit/{command.Id}?notificationType={(short)NotificationType.StoppedByUser}"))), Times.Once);
        }