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

            var email = new CreateDemandConfirmationEmail(
                recipientEmail,
                recipientName,
                standardName,
                standardLevel,
                location,
                0,
                stopSharingUrl);

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

            var email = new CreateDemandConfirmationEmail(
                recipientEmail,
                recipientName,
                standardName,
                standardLevel,
                location,
                numberOfApprentices,
                stopSharingUrl);

            email.TemplateId.Should().Be(EmailConstants.CreateDemandConfirmationTemplateId);
            email.RecipientAddress.Should().Be(recipientEmail);
            email.ReplyToAddress.Should().Be(EmailConstants.ReplyToAddress);
            email.Tokens.Should().BeEquivalentTo(expectedTokens);
        }
        public async Task <VerifyEmployerDemandCommandResult> Handle(VerifyEmployerDemandCommand request, CancellationToken cancellationToken)
        {
            var getEmployerDemandResponse =
                await _apiClient.Get <GetEmployerDemandResponse>(new GetEmployerDemandRequest(request.Id));

            if (getEmployerDemandResponse == null)
            {
                return(new VerifyEmployerDemandCommandResult
                {
                    EmployerDemand = null
                });
            }

            if (getEmployerDemandResponse.EmailVerified ||
                getEmployerDemandResponse.ContactEmailAddress == string.Empty)
            {
                return(new VerifyEmployerDemandCommandResult
                {
                    EmployerDemand = getEmployerDemandResponse
                });
            }

            var verifyEmailResponse = await _apiClient.PatchWithResponseCode(new PatchCourseDemandRequest(
                                                                                 request.Id, new PatchOperation
            {
                Path = "EmailVerified",
                Value = true
            }));

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

            if (verifyEmailResponse.StatusCode == HttpStatusCode.OK)
            {
                var emailModel = new CreateDemandConfirmationEmail(
                    getEmployerDemandResponse.ContactEmailAddress,
                    getEmployerDemandResponse.OrganisationName,
                    getEmployerDemandResponse.Course.Title,
                    getEmployerDemandResponse.Course.Level,
                    getEmployerDemandResponse.Location.Name,
                    getEmployerDemandResponse.NumberOfApprentices,
                    getEmployerDemandResponse.StopSharingUrl
                    );
                await _notificationService.Send(new SendEmailCommand(emailModel.TemplateId, emailModel.RecipientAddress, emailModel.Tokens));

                getEmployerDemandResponse.EmailVerified = true;
            }

            return(new VerifyEmployerDemandCommandResult
            {
                EmployerDemand = getEmployerDemandResponse
            });
        }
Example #4
0
        public async Task Then_The_Api_Is_Called_And_Email_Sent_If_ResponseCode_Is_Created(
            RegisterDemandCommand command,
            PostCreateCourseDemand responseBody,
            [Frozen] Mock <IEmployerDemandApiClient <EmployerDemandApiConfiguration> > apiClient,
            [Frozen] Mock <INotificationService> mockNotificationService,
            RegisterDemandCommandHandler handler)
        {
            //Arrange
            var apiResponse = new ApiResponse <PostCreateCourseDemand>(responseBody, HttpStatusCode.Created);

            apiClient.Setup(x => x.PostWithResponseCode <PostCreateCourseDemand>(It.Is <PostCreateCourseDemandRequest>(c =>

                                                                                                                       ((CreateCourseDemandData)c.Data).Id.Equals(command.Id) &&
                                                                                                                       ((CreateCourseDemandData)c.Data).ContactEmailAddress.Equals(command.ContactEmailAddress) &&
                                                                                                                       ((CreateCourseDemandData)c.Data).OrganisationName.Equals(command.OrganisationName) &&
                                                                                                                       ((CreateCourseDemandData)c.Data).NumberOfApprentices.Equals(command.NumberOfApprentices) &&
                                                                                                                       ((CreateCourseDemandData)c.Data).Location.LocationPoint.GeoPoint.First() == command.Lat &&
                                                                                                                       ((CreateCourseDemandData)c.Data).Location.LocationPoint.GeoPoint.Last() == command.Lon &&
                                                                                                                       ((CreateCourseDemandData)c.Data).Location.Name.Equals(command.LocationName) &&
                                                                                                                       ((CreateCourseDemandData)c.Data).Course.Title.Equals(command.CourseTitle) &&
                                                                                                                       ((CreateCourseDemandData)c.Data).Course.Level.Equals(command.CourseLevel) &&
                                                                                                                       ((CreateCourseDemandData)c.Data).Course.Id.Equals(command.CourseId) &&
                                                                                                                       ((CreateCourseDemandData)c.Data).Course.Route.Equals(command.CourseSector)
                                                                                                                       )))
            .ReturnsAsync(apiResponse);

            SendEmailCommand actualEmail = null;

            mockNotificationService
            .Setup(service => service.Send(It.IsAny <SendEmailCommand>()))
            .Callback((SendEmailCommand args) => actualEmail = args)
            .Returns(Task.CompletedTask);
            var expectedEmail = new CreateDemandConfirmationEmail(
                command.ContactEmailAddress,
                command.OrganisationName,
                command.CourseTitle,
                command.CourseLevel,
                command.LocationName,
                command.NumberOfApprentices);

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

            //Assert
            actual.Should().Be(apiResponse.Body.Id);
            actualEmail.Tokens.Should().BeEquivalentTo(expectedEmail.Tokens);
            actualEmail.RecipientsAddress.Should().BeEquivalentTo(expectedEmail.RecipientAddress);
            actualEmail.TemplateId.Should().BeEquivalentTo(expectedEmail.TemplateId);
        }
Example #5
0
        public async Task Then_The_Command_Is_Handled_And_Api_Called(
            VerifyEmployerDemandCommand command,
            string patchResponse,
            GetEmployerDemandResponse getDemandResponse,
            [Frozen] Mock <IEmployerDemandApiClient <EmployerDemandApiConfiguration> > apiClient,
            [Frozen] Mock <INotificationService> notificationService,
            VerifyEmployerDemandCommandHandler handler)
        {
            //Arrange
            getDemandResponse.EmailVerified = false;
            var apiResponse = new ApiResponse <string>(patchResponse, HttpStatusCode.OK, null);

            apiClient.Setup(
                x => x.PatchWithResponseCode(It.Is <PatchCourseDemandRequest>(c =>
                                                                              c.PatchUrl.Contains($"api/demand/{command.Id}") &&
                                                                              c.Data.FirstOrDefault().Path.Equals("EmailVerified") &&
                                                                              c.Data.FirstOrDefault().Value.Equals(true)
                                                                              ))).ReturnsAsync(apiResponse);

            apiClient.Setup(x =>
                            x.Get <GetEmployerDemandResponse>(
                                It.Is <GetEmployerDemandRequest>(c => c.GetUrl.Contains($"demand/{command.Id}"))))
            .ReturnsAsync(getDemandResponse);
            SendEmailCommand actualEmail = null;

            notificationService
            .Setup(service => service.Send(It.IsAny <SendEmailCommand>()))
            .Callback((SendEmailCommand args) => actualEmail = args)
            .Returns(Task.CompletedTask);
            var expectedEmail = new CreateDemandConfirmationEmail(
                getDemandResponse.ContactEmailAddress,
                getDemandResponse.OrganisationName,
                getDemandResponse.Course.Title,
                getDemandResponse.Course.Level,
                getDemandResponse.Location.Name,
                getDemandResponse.NumberOfApprentices,
                getDemandResponse.StopSharingUrl);

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

            //Assert
            actual.EmployerDemand.Should().BeEquivalentTo(getDemandResponse, options => options.Excluding(c => c.EmailVerified));
            actual.EmployerDemand.EmailVerified.Should().BeTrue();
            actualEmail.Tokens.Should().BeEquivalentTo(expectedEmail.Tokens);
            actualEmail.RecipientsAddress.Should().BeEquivalentTo(expectedEmail.RecipientAddress);
            actualEmail.TemplateId.Should().BeEquivalentTo(expectedEmail.TemplateId);
        }
Example #6
0
        public async Task <Guid> Handle(RegisterDemandCommand request, CancellationToken cancellationToken)
        {
            var result = await _apiClient.PostWithResponseCode <PostCreateCourseDemand>(new PostCreateCourseDemandRequest(new CreateCourseDemandData
            {
                Id = request.Id,
                ContactEmailAddress = request.ContactEmailAddress,
                OrganisationName = request.OrganisationName,
                NumberOfApprentices = request.NumberOfApprentices,
                Location = new Location
                {
                    Name = request.LocationName,
                    LocationPoint = new LocationPoint
                    {
                        GeoPoint = new List <double> {
                            request.Lat, request.Lon
                        }
                    }
                },
                Course = new Course
                {
                    Id = request.CourseId,
                    Title = request.CourseTitle,
                    Level = request.CourseLevel,
                    Route = request.CourseSector,
                }
            }));

            if (result.StatusCode == HttpStatusCode.Created)
            {
                var emailModel = new CreateDemandConfirmationEmail(
                    request.ContactEmailAddress,
                    request.OrganisationName,
                    request.CourseTitle,
                    request.CourseLevel,
                    request.LocationName,
                    request.NumberOfApprentices);


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

            return(result.Body.Id);
        }