public async Task Then_Do_Not_Add_To_Failed_Queue_If_Status_Is_Delivered(
            string status,
            MatchingConfiguration configuration,
            IEmailService emailService,
            IOpportunityRepository opportunityRepository,
            IMessageQueueService messageQueueService,
            ILogger <Application.Services.EmailDeliveryStatusService> logger,
            EmailDeliveryStatusPayLoad payload
            )
        {
            //Arrange
            var sut = new Application.Services.EmailDeliveryStatusService(configuration,
                                                                          emailService, opportunityRepository, messageQueueService, logger);

            payload.Status = status;
            var serializedPayLoad = JsonConvert.SerializeObject(payload);

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

            //Act
            await sut.HandleEmailDeliveryStatusAsync(serializedPayLoad);

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

            await messageQueueService.DidNotReceive().PushEmailDeliveryStatusMessageAsync(Arg.Any <SendEmailDeliveryStatus>());
        }
        public async Task Then_Do_Not_Update_Email_History_If_PayLoad_Is_Null_Or_Empty(
            string payload,
            MatchingConfiguration configuration,
            IRepository <Domain.Models.EmailHistory> emailHistoryRepository,
            IEmailService emailService,
            IOpportunityRepository opportunityRepository,
            IMessageQueueService messageQueueService,
            ILogger <Application.Services.EmailDeliveryStatusService> logger,
            Domain.Models.EmailHistory emailHistory
            )
        {
            //Arrange
            emailHistoryRepository
            .GetFirstOrDefaultAsync(Arg.Any <Expression <Func <Domain.Models.EmailHistory, bool> > >())
            .Returns(emailHistory);

            var sut = new Application.Services.EmailDeliveryStatusService(configuration,
                                                                          emailService, opportunityRepository, messageQueueService, logger);

            //Act
            var result = await sut.HandleEmailDeliveryStatusAsync(payload);

            //Assert
            result.Should().Be(-1);

            await emailHistoryRepository.DidNotReceive().GetFirstOrDefaultAsync(Arg.Any <Expression <Func <Domain.Models.EmailHistory, bool> > >());

            await emailHistoryRepository.DidNotReceive().UpdateWithSpecifiedColumnsOnlyAsync(
                Arg.Any <Domain.Models.EmailHistory>(),
                Arg.Any <Expression <Func <Domain.Models.EmailHistory, object> >[]>());

            await messageQueueService.DidNotReceive().PushEmailDeliveryStatusMessageAsync(Arg.Any <SendEmailDeliveryStatus>());
        }
        public async Task Then_Do_Not_Update_Email_History_If_Notification_Id_Does_Not_Exists_In_Callback_PayLoad(
            string status,
            MatchingConfiguration configuration,
            IEmailService emailService,
            IOpportunityRepository opportunityRepository,
            IMessageQueueService messageQueueService,
            ILogger <Application.Services.EmailDeliveryStatusService> logger,
            EmailDeliveryStatusPayLoad payload
            )
        {
            //Arrange
            payload.Id     = Guid.Empty;
            payload.Status = status;

            var sut = new Application.Services.EmailDeliveryStatusService(configuration,
                                                                          emailService, opportunityRepository, messageQueueService, logger);

            var serializedPayLoad = JsonConvert.SerializeObject(payload);

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

            //Act
            var result = await sut.HandleEmailDeliveryStatusAsync(serializedPayLoad);

            //Assert
            result.Should().Be(-1);

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

            await messageQueueService.DidNotReceive().PushEmailDeliveryStatusMessageAsync(Arg.Any <SendEmailDeliveryStatus>());
        }
Пример #4
0
        public async Task Then_Do_Not_Update_Email_History_If_PayLoad_Notification_Id_Is_Null(
            string status,
            MatchingDbContext dbContext,
            [Frozen] Domain.Models.Opportunity opportunity,
            [Frozen] Domain.Models.Provider provider,
            [Frozen] Domain.Models.ProviderVenue venue,
            [Frozen] EmailHistory emailHistory,
            [Frozen] BackgroundProcessHistory backgroundProcessHistory,
            IMessageQueueService messageQueueService,
            EmailDeliveryStatusPayLoad payload,
            MatchingConfiguration configuration,
            ILogger <OpportunityRepository> opportunityRepoLogger,
            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();

            payload.Status = status;
            payload.Id     = Guid.Empty;

            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().BeNull();

            var existingData = dbContext.EmailHistory.Where(history => history.OpportunityId == opportunity.Id).ToList();

            existingData.Select(history => history.ModifiedBy).Should().Equal(new List <string> {
                null, null
            });
            existingData.Select(history => history.ModifiedOn).Should().Equal(new List <string> {
                null, null
            });

            await messageQueueService.DidNotReceive().PushEmailDeliveryStatusMessageAsync(Arg.Any <SendEmailDeliveryStatus>());
        }
        public async void Then_Do_Not_Update_Email_History_If_Authorization_Failed(
            MatchingConfiguration matchingConfiguration,
            EmailDeliveryStatusPayLoad payLoad,
            EmailHistory emailHistory,
            ExecutionContext context,
            IRepository <EmailHistory> emailHistoryRepository,
            IMessageQueueService messageQueueService,
            IEmailService emailService,
            IOpportunityRepository opportunityRepository,
            IRepository <FunctionLog> functionLogRepository,
            ILogger <EmailDeliveryStatusService> logger
            )
        {
            //Arrange
            matchingConfiguration.EmailDeliveryStatusToken = Guid.NewGuid();
            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 BadRequestObjectResult;

            //Assert
            result.Should().NotBeNull();
            result?.StatusCode.Should().Be(400);
            result?.Should().BeOfType <BadRequestObjectResult>();

            await emailHistoryRepository.DidNotReceive().UpdateWithSpecifiedColumnsOnlyAsync(Arg.Any <EmailHistory>(),
                                                                                             Arg.Any <Expression <Func <EmailHistory, object> >[]>());

            await emailHistoryRepository.DidNotReceive().UpdateWithSpecifiedColumnsOnlyAsync(
                Arg.Is <EmailHistory>(eh =>
                                      eh.Status == "delivered" && eh.ModifiedBy == "System"),
                Arg.Any <Expression <Func <EmailHistory, object> >[]>());

            await messageQueueService.DidNotReceive().PushEmailDeliveryStatusMessageAsync(Arg.Any <SendEmailDeliveryStatus>());
        }
Пример #6
0
        public async Task Then_Update_Email_History_With_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 <EmailService> emailServiceLogger,
            ILogger <Application.Services.EmailDeliveryStatusService> emailDeliveryServiceStatusLogger,
            IAsyncNotificationClient notificationClient
            )
        {
            //Arrange
            await DataBuilder.SetTestData(dbContext, provider, venue, opportunity, backgroundProcessHistory);

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

            dbContext.DetachAllEntities();

            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("delivered");
            data?.ModifiedBy.Should().Be("System");

            await messageQueueService.DidNotReceive().PushEmailDeliveryStatusMessageAsync(Arg.Any <SendEmailDeliveryStatus>());
        }
Пример #7
0
 public void Then_The_Employer_Record_Should_Be_Created()
 {
     _employerRepository.DidNotReceive().UpdateAsync(Arg.Any <Domain.Models.Employer>());
     _employerRepository.Received(1).CreateAsync(Arg.Is <Domain.Models.Employer>(e =>
                                                                                 e.CrmId == _employerEventBase.AccountId.ToGuid() &&
                                                                                 e.Aupa == "Aware" &&
                                                                                 e.CompanyName == "Test" &&
                                                                                 e.AlsoKnownAs == "Test" &&
                                                                                 e.CompanyNameSearch == "TestTest" &&
                                                                                 e.PrimaryContact == "Test" &&
                                                                                 e.Email == "*****@*****.**" &&
                                                                                 e.Phone == "0123456789" &&
                                                                                 e.Owner == "Test"
                                                                                 ));
     _messageQueueService.DidNotReceive()
     .PushEmployerAupaBlankEmailMessageAsync(Arg.Any <SendEmployerAupaBlankEmail>());
 }
        public async void Then_Do_Not_Update_Email_History_If_No_Record_Found(
            MatchingConfiguration matchingConfiguration,
            EmailDeliveryStatusPayLoad payLoad,
            ExecutionContext context,
            IRepository <EmailHistory> emailHistoryRepository,
            IMessageQueueService messageQueueService,
            IEmailService emailService,
            IOpportunityRepository opportunityRepository,
            IRepository <FunctionLog> functionLogRepository,
            ILogger <EmailDeliveryStatusService> logger
            )
        {
            //Arrange
            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(Task.FromResult <EmailHistory>(null));

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

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

            await emailHistoryRepository.DidNotReceive().UpdateWithSpecifiedColumnsOnlyAsync(Arg.Any <EmailHistory>(),
                                                                                             Arg.Any <Expression <Func <EmailHistory, object> >[]>());

            await messageQueueService.DidNotReceive().PushEmailDeliveryStatusMessageAsync(Arg.Any <SendEmailDeliveryStatus>());
        }
        public async void Then_Update_Email_History_With_Status_And_Do_Not_Push_To_Email_Delivery_Status_Queue(
            MatchingConfiguration matchingConfiguration,
            EmailDeliveryStatusPayLoad payLoad,
            ExecutionContext context,
            IMessageQueueService messageQueueService,
            IRepository <FunctionLog> functionLogRepository,
            IEmailService emailService,
            IOpportunityRepository opportunityRepository,
            ILogger <EmailDeliveryStatusService> logger
            )
        {
            //Arrange
            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");

            var httpRequest = HttpRequestSetup(query, serializedPayLoad);

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

            //Assert
            httpRequest.Headers.TryGetValue("Authorization", out var token);

            token.Should().Equal($"Bearer {matchingConfiguration.EmailDeliveryStatusToken}");
            result.Should().NotBeNull();
            result?.StatusCode.Should().Be(200);
            result?.Value.Should().Be("1 records updated.");

            await messageQueueService.DidNotReceive().PushEmailDeliveryStatusMessageAsync(Arg.Any <SendEmailDeliveryStatus>());
        }
Пример #10
0
        public async Task Then_Do_Not_Update_Email_History_If_Does_Not_Exsits(
            MatchingDbContext dbContext,
            [Frozen] Domain.Models.Opportunity opportunity,
            [Frozen] Domain.Models.Provider provider,
            [Frozen] Domain.Models.ProviderVenue venue,
            [Frozen] BackgroundProcessHistory backgroundProcessHistory,
            IMessageQueueService messageQueueService,
            EmailDeliveryStatusPayLoad payload,
            MatchingConfiguration configuration,
            ILogger <OpportunityRepository> opportunityRepoLogger,
            ILogger <GenericRepository <EmailTemplate> > emailTemplateLogger,
            ILogger <GenericRepository <EmailHistory> > emailHistoryLogger,
            ILogger <GenericRepository <FunctionLog> > functionLogLogger,
            ILogger <EmailService> emailServiceLogger,
            ILogger <Application.Services.EmailDeliveryStatusService> emailDeliveryServiceStatusLogger,
            IAsyncNotificationClient notificationClient
            )
        {
            //Arrange
            await DataBuilder.SetTestData(dbContext, provider, venue, opportunity, backgroundProcessHistory);

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

            var serializedPayLoad = JsonConvert.SerializeObject(payload);

            //Act
            var result = await sut.HandleEmailDeliveryStatusAsync(serializedPayLoad);

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

            data.Should().BeNull();
            result.Should().Be(-1);

            await messageQueueService.DidNotReceive().PushEmailDeliveryStatusMessageAsync(Arg.Any <SendEmailDeliveryStatus>());
        }