Beispiel #1
0
 public void Then_MessageQueueService_PushProviderQuarterlyRequestMessageAsync_Is_Called_Exactly_Once()
 {
     _messageQueueService
     .Received(1)
     .PushProviderQuarterlyRequestMessageAsync(Arg.Is <SendProviderQuarterlyUpdateEmail>(message =>
                                                                                         message.BackgroundProcessHistoryId == 1));
 }
        public async Task Then_Add_To_Failed_Queue_If_Status_Is_Not_Delivered(
            string status,
            MatchingConfiguration configuration,
            IEmailService emailService,
            IOpportunityRepository opportunityRepository,
            IMessageQueueService messageQueueService,
            ILogger <Application.Services.EmailDeliveryStatusService> logger,
            EmailDeliveryStatusPayLoad payload
            )
        {
            //Arrange
            payload.Status = status;
            var sut = new Application.Services.EmailDeliveryStatusService(configuration,
                                                                          emailService, opportunityRepository, messageQueueService, logger);

            var serializedPayLoad = JsonConvert.SerializeObject(payload);

            //Act
            await sut.HandleEmailDeliveryStatusAsync(serializedPayLoad);

            //Assert
            await emailService.Received(1).UpdateEmailStatus(Arg.Is <EmailDeliveryStatusPayLoad>(data => data.Status == status));

            await messageQueueService.Received(1).PushEmailDeliveryStatusMessageAsync(Arg.Any <SendEmailDeliveryStatus>());
        }
        public void Then_The_Employer_Record_Should_NOT_Be_Created_OR_Updated()
        {
            _employerRepository.DidNotReceive().CreateAsync(Arg.Any <Domain.Models.Employer>());
            _employerRepository.DidNotReceive().UpdateAsync(Arg.Any <Domain.Models.Employer>());

            _messageQueueService.Received(1)
            .PushEmployerAupaBlankEmailMessageAsync(Arg.Any <SendEmployerAupaBlankEmail>());
        }
Beispiel #4
0
        public async Task Then_Update_Email_History_With_Status_And_Push_To_Email_Delivery_Status_Queue(
            string status,
            MatchingDbContext dbContext,
            MatchingConfiguration configuration,
            [Frozen] Domain.Models.Opportunity opportunity,
            [Frozen] Domain.Models.Provider provider,
            [Frozen] Domain.Models.ProviderVenue venue,
            [Frozen] EmailHistory emailHistory,
            [Frozen] BackgroundProcessHistory backgroundProcessHistory,
            ILogger <OpportunityRepository> opportunityRepoLogger,
            IMessageQueueService messageQueueService,
            EmailDeliveryStatusPayLoad payload,
            ILogger <GenericRepository <EmailTemplate> > emailTemplateLogger,
            ILogger <GenericRepository <EmailHistory> > emailHistoryLogger,
            ILogger <GenericRepository <FunctionLog> > functionLogLogger,
            ILogger <Application.Services.EmailDeliveryStatusService> emailDeliveryServiceStatusLogger,
            ILogger <EmailService> emailServiceLogger,
            IAsyncNotificationClient notificationClient
            )
        {
            //Arrange
            await DataBuilder.SetTestData(dbContext, provider, venue, opportunity, backgroundProcessHistory);

            dbContext.Add(emailHistory);
            await dbContext.SaveChangesAsync();

            dbContext.DetachAllEntities();

            payload.Status = status;
            payload.Id     = emailHistory.NotificationId.GetValueOrDefault();

            var sut = SutSetUp(dbContext, opportunityRepoLogger, emailTemplateLogger, emailHistoryLogger, functionLogLogger,
                               emailDeliveryServiceStatusLogger, emailServiceLogger, notificationClient, configuration, messageQueueService);

            var serializedPayLoad = JsonConvert.SerializeObject(payload);

            //Act
            await sut.HandleEmailDeliveryStatusAsync(serializedPayLoad);

            //Assert
            var data = dbContext.EmailHistory.FirstOrDefault(em => em.NotificationId == payload.Id);

            data.Should().NotBeNull();
            data?.NotificationId.Should().Be(payload.Id);
            data?.Status.Should().Be(payload.Status);
            data?.ModifiedBy.Should().Be("System");

            await messageQueueService.Received(1).PushEmailDeliveryStatusMessageAsync(Arg.Any <SendEmailDeliveryStatus>());
        }
Beispiel #5
0
        public async Task Then_Send_Referral_Email_To_Employers_Queue(
            MatchingDbContext dbContext,
            [Frozen] Domain.Models.Opportunity opportunity,
            [Frozen] Domain.Models.Provider provider,
            [Frozen] Domain.Models.ProviderVenue venue,
            [Frozen] BackgroundProcessHistory backgroundProcessHistory,
            IMessageQueueService messageQueueService,
            IRepository <OpportunityItem> repo,
            IRepository <BackgroundProcessHistory> backgroundProcessHistoryRepository
            )
        {
            //Arrange
            backgroundProcessHistory.Status = BackgroundProcessHistoryStatus.Pending.ToString();

            await DataBuilder.SetTestData(dbContext, provider, venue, opportunity, backgroundProcessHistory);

            var sut = new ReferralService(messageQueueService, repo, backgroundProcessHistoryRepository);

            repo.GetManyAsync(Arg.Any <Expression <Func <OpportunityItem, bool> > >()).Returns(opportunity.OpportunityItem.AsQueryable());

            //Act
            await sut.ConfirmOpportunitiesAsync(opportunity.Id, "username");

            //Assert

            var backgroundProcessData =
                dbContext.BackgroundProcessHistory.FirstOrDefault(x => x.Id == backgroundProcessHistory.Id);

            await messageQueueService.Received(1)
            .PushEmployerReferralEmailMessageAsync(Arg.Any <SendEmployerReferralEmail>());

            await messageQueueService.Received(1)
            .PushProviderReferralEmailMessageAsync(Arg.Any <SendProviderReferralEmail>());

            backgroundProcessData?.Status.Should().Be(BackgroundProcessHistoryStatus.Pending.ToString());
        }
        public async void Then_Update_Email_History_With_Failed_Status_And_Push_To_Email_Delivery_Status_Queue(
            string status,
            MatchingConfiguration matchingConfiguration,
            EmailDeliveryStatusPayLoad payLoad,
            EmailHistory emailHistory,
            ExecutionContext context,
            IRepository <EmailHistory> emailHistoryRepository,
            IMessageQueueService messageQueueService,
            IEmailService emailService,
            IOpportunityRepository opportunityRepository,
            IRepository <FunctionLog> functionLogRepository,
            ILogger <EmailDeliveryStatusService> logger
            )
        {
            //Arrange
            payLoad.Status = status;
            var serializedPayLoad   = JsonConvert.SerializeObject(payLoad);
            var notificationService = new EmailDeliveryStatusService(matchingConfiguration, emailService,
                                                                     opportunityRepository, messageQueueService, logger);

            emailService.UpdateEmailStatus(Arg.Any <EmailDeliveryStatusPayLoad>()).Returns(1);

            var query = new Dictionary <string, StringValues>();

            query.TryAdd("content-type", "application/json");

            emailHistoryRepository.GetFirstOrDefaultAsync(Arg.Any <Expression <Func <EmailHistory, bool> > >())
            .Returns(emailHistory);

            //Act
            var emailDeliveryStatusFunctions = new Functions.EmailDeliveryStatus(matchingConfiguration, notificationService, functionLogRepository);
            var result = await emailDeliveryStatusFunctions.EmailDeliveryStatusHandlerAsync(
                HttpRequestSetup(query, serializedPayLoad),
                context, logger) as OkObjectResult;

            //Assert
            result.Should().NotBeNull();
            result?.StatusCode.Should().Be(200);
            result?.Value.Should().Be("1 records updated.");

            await messageQueueService.Received(1).PushEmailDeliveryStatusMessageAsync(Arg.Is <SendEmailDeliveryStatus>(email => email.NotificationId == payLoad.Id));
        }