Esempio n. 1
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>());
        }
Esempio n. 2
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>());
        }
Esempio n. 3
0
        public Domain.Models.LocalEnterprisePartnership CreateLocalEnterprisePartnership()
        {
            var lep = new Domain.Models.LocalEnterprisePartnership
            {
                Code      = "LEP000001",
                Name      = "LEP Name",
                CreatedBy = "Sfa.Tl.Matching.Application.IntegrationTests"
            };

            _context.Add(lep);

            _context.SaveChanges();

            return(lep);
        }
Esempio n. 4
0
        public When_SqlSearchProvider_Search_Opportunities_Is_Called_With_Valid_Parameters()
        {
            var logger = Substitute.For <ILogger <Data.SearchProviders.SqlSearchProvider> >();

            _dbContext = new TestConfiguration().GetDbContext();

            _providerVenue = new ValidProviderVenueSearchBuilder().BuildOneVenue();
            _dbContext.Add(_providerVenue);
            _dbContext.SaveChanges();

            var provider = new Data.SearchProviders.SqlSearchProvider(logger, _dbContext);

            _results = provider.SearchOpportunitiesByPostcodeProximityAsync(new OpportunityProximitySearchParametersDto {
                Postcode = "CV1 2WT", SearchRadius = 5, SelectedRouteId = 7, Latitude = "52.400997", Longitude = "-1.508122"
            }).GetAwaiter().GetResult();
        }
        public When_SqlSearchProvider_Search_Opportunities_Is_Called_With_Valid_Postcode_But_Provider_Is_Disabled_For_Selected_Route()
        {
            var logger = Substitute.For <ILogger <Data.SearchProviders.SqlSearchProvider> >();

            _dbContext = new TestConfiguration().GetDbContext();

            _providerVenue = new ValidProviderVenueSearchBuilder().BuildWithOneDisabledVenue();
            _dbContext.Add(_providerVenue);
            _dbContext.SaveChanges();

            var provider = new Data.SearchProviders.SqlSearchProvider(logger, _dbContext);

            _results = provider.SearchOpportunitiesByPostcodeProximityAsync(new OpportunityProximitySearchParametersDto {
                Postcode = "MK1 1AD", SelectedRouteId = 7, Latitude = "52.010709", Longitude = "-0.736412"
            }).GetAwaiter().GetResult();
        }
        public Domain.Models.Opportunity CreateOpportunity(Guid employerCrmId, List <OpportunityItem> opportunityItems)
        {
            var opportunity = new Domain.Models.Opportunity
            {
                EmployerCrmId        = employerCrmId,
                EmployerContact      = "test",
                EmployerContactEmail = "*****@*****.**",
                EmployerContactPhone = "01234567890",
                OpportunityItem      = opportunityItems,
                CreatedBy            = "Sfa.Tl.Matching.Application.IntegrationTests",
            };

            _context.Add(opportunity);

            _context.SaveChanges();

            return(opportunity);
        }
        public Domain.Models.Employer CreateEmployer(Guid crmId)
        {
            var employer = new Domain.Models.Employer
            {
                AlsoKnownAs    = "test aka",
                Aupa           = "test aupa",
                CompanyName    = "test company name",
                CrmId          = Guid.NewGuid(),
                Email          = "*****@*****.**",
                Owner          = "test owner",
                Phone          = "01234567890",
                PrimaryContact = "test contact",
                CreatedBy      = "Sfa.Tl.Matching.Application.IntegrationTests",
            };

            _context.Add(employer);
            _context.SaveChanges();

            return(employer);
        }
Esempio n. 8
0
        public Provider CreateProvider(int venueCount = 1)
        {
            var provider = new Provider
            {
                DisplayName           = "test provider display name",
                Name                  = "test provider",
                OfstedRating          = 1,
                PrimaryContact        = "test primary contact",
                PrimaryContactEmail   = "*****@*****.**",
                PrimaryContactPhone   = "01234567890",
                SecondaryContact      = "test secondary contact",
                SecondaryContactEmail = "*****@*****.**",
                SecondaryContactPhone = "01234567891",
                Source                = "test",
                UkPrn                 = 12345678,
                IsCdfProvider         = true,
                IsEnabledForReferral  = true,
                IsTLevelProvider      = true,
                CreatedBy             = "Sfa.Tl.Matching.Application.IntegrationTests",
                ProviderVenue         = Enumerable.Range(1, venueCount).Select(venue =>
                                                                               new ProviderVenue
                {
                    IsRemoved            = true,
                    IsEnabledForReferral = true,
                    County                = $"test county{venue}",
                    Name                  = $"test name{venue}",
                    Postcode              = $"POST PO{venue}",
                    Source                = $"test{venue}",
                    Town                  = $"test town{venue}",
                    CreatedBy             = "Sfa.Tl.Matching.Application.IntegrationTests",
                    ProviderQualification = new List <ProviderQualification>
                    {
                        new ProviderQualification
                        {
                            CreatedBy     = "Sfa.Tl.Matching.Application.IntegrationTests",
                            Source        = "test",
                            Qualification = new Qualification
                            {
                                CreatedBy  = "Sfa.Tl.Matching.Application.IntegrationTests",
                                LarId      = "12345678",
                                ShortTitle = "test short title",
                                Title      = "test title",
                                QualificationRouteMapping = new List <QualificationRouteMapping>
                                {
                                    new QualificationRouteMapping
                                    {
                                        RouteId   = 1,
                                        CreatedBy = "Sfa.Tl.Matching.Application.IntegrationTests",
                                        Source    = "test"
                                    }
                                }
                            }
                        }
                    }
                }).ToList()
            };

            _context.Add(provider);

            _context.SaveChanges();

            return(provider);
        }