Пример #1
0
        public static async Task SetEmailTemplate(
            MatchingDbContext dbContext,
            EmailTemplate emailTemplate)
        {
            await dbContext.AddAsync(emailTemplate);

            await dbContext.SaveChangesAsync();

            dbContext.DetachAllEntities();
        }
Пример #2
0
        public static async Task SetTestData(MatchingDbContext dbContext,
                                             Provider provider,
                                             ProviderVenue venue,
                                             Opportunity opportunity,
                                             BackgroundProcessHistory backgroundProcessHistory,
                                             bool isSaved = true, bool isSelectedForReferral = true)
        {
            backgroundProcessHistory.Status = BackgroundProcessHistoryStatus.Pending.ToString();

            await dbContext.AddAsync(provider);

            await dbContext.AddAsync(venue);

            await dbContext.AddAsync(opportunity);

            await dbContext.AddAsync(backgroundProcessHistory);

            await dbContext.SaveChangesAsync();

            dbContext.DetachAllEntities();

            var items = dbContext.OpportunityItem
                        .AsNoTracking()
                        .Where(oi => oi.OpportunityId == opportunity.Id)
                        .ToList();

            foreach (var opportunityItem in items)
            {
                opportunityItem.IsSaved               = isSaved;
                opportunityItem.IsCompleted           = false;
                opportunityItem.OpportunityType       = "Referral";
                opportunityItem.IsSelectedForReferral = isSelectedForReferral;

                dbContext.Entry(opportunityItem).Property("IsSaved").IsModified               = true;
                dbContext.Entry(opportunityItem).Property("IsCompleted").IsModified           = true;
                dbContext.Entry(opportunityItem).Property("IsSelectedForReferral").IsModified = true;
                dbContext.Entry(opportunityItem).Property("OpportunityType").IsModified       = true;
            }

            await dbContext.SaveChangesAsync();

            dbContext.DetachAllEntities();
        }
Пример #3
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>());
        }
        private static async Task SetProvisionGapData(
            MatchingDbContext dbContext,
            OpportunityItem opportunityItem,
            bool hasBadExperience,
            bool hasNoSuitableStudent,
            bool areProvidersTooFarAway)
        {
            opportunityItem.OpportunityType = "ProvisionGap";
            opportunityItem.IsSaved         = true;
            opportunityItem.IsCompleted     = false;

            //Need to remove extra referral/provision gap rows created as AutoDomainData
            foreach (var x in opportunityItem.ProvisionGap.Where(pg => pg.Id != opportunityItem.ProvisionGap.First().Id).ToList())
            {
                opportunityItem.ProvisionGap.Remove(x);
            }
            opportunityItem.Referral.Clear();

            await dbContext.OpportunityItem.AddAsync(opportunityItem);

            await dbContext.SaveChangesAsync();

            dbContext.DetachAllEntities();

            //Set up the provision gap record
            var provisionGap = await dbContext.ProvisionGap.AsNoTracking().FirstOrDefaultAsync();

            provisionGap.HadBadExperience    = hasBadExperience;
            provisionGap.NoSuitableStudent   = hasNoSuitableStudent;
            provisionGap.ProvidersTooFarAway = areProvidersTooFarAway;

            dbContext.Entry(provisionGap).Property("HadBadExperience").IsModified    = true;
            dbContext.Entry(provisionGap).Property("NoSuitableStudent").IsModified   = true;
            dbContext.Entry(provisionGap).Property("ProvidersTooFarAway").IsModified = true;

            await dbContext.SaveChangesAsync();

            dbContext.DetachAllEntities();
        }
Пример #5
0
        public static async Task SetEmailHistory(
            MatchingDbContext dbContext,
            EmailHistory emailHistory)
        {
            emailHistory.Status     = null;
            emailHistory.ModifiedBy = null;
            emailHistory.ModifiedOn = null;

            await dbContext.AddAsync(emailHistory);

            await dbContext.SaveChangesAsync();

            dbContext.DetachAllEntities();
        }
Пример #6
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>());
        }
Пример #7
0
        public virtual async Task <int> CreateManyAsync(IList <T> entities)
        {
            await _dbContext.AddRangeAsync(entities);

            int createdRecordsCount;

            try
            {
                createdRecordsCount = await _dbContext.SaveChangesAsync();
            }
            catch (DbUpdateException due)
            {
                _logger.LogError(due.Message, due.InnerException);
                throw;
            }

            return(createdRecordsCount);
        }
Пример #8
0
        public async Task Then_Make_TLevel_Provider_Flag_To_True(
            MatchingDbContext dbContext,
            Domain.Models.Provider provider,
            List <ProviderVenueViewModel> venueViewModels,
            MatchingConfiguration config,
            ILogger <GenericRepository <Domain.Models.Provider> > providerLogger,
            ILogger <GenericRepository <ProviderReference> > providerReferenceLogger,
            IHttpContextAccessor httpContextAccessor,
            IDateTimeProvider dateTimeProvider
            )
        {
            //Arrange
            provider.IsTLevelProvider = false;

            await dbContext.AddAsync(provider);

            await dbContext.SaveChangesAsync();

            dbContext.Entry(provider).State = EntityState.Detached;

            var viewModel = new ProviderDetailViewModel
            {
                Id = provider.Id,
                IsTLevelProvider = true,
                ProviderVenues   = venueViewModels
            };

            httpContextAccessor.HttpContext.Returns(new DefaultHttpContext
            {
                User = new ClaimsPrincipal(new ClaimsIdentity(new[]
                {
                    new Claim(ClaimTypes.GivenName, "System")
                }))
            });

            var mapperConfig = new MapperConfiguration(c =>
            {
                c.AddMaps(typeof(ProviderMapper).Assembly);
                c.ConstructServicesUsing(type =>
                                         type.Name.Contains("LoggedInUserNameResolver")
                        ? (object)new LoggedInUserNameResolver <ProviderDetailViewModel, Domain.Models.Provider>(httpContextAccessor)
                        : type.Name.Contains("UtcNowResolver")
                                ? new UtcNowResolver <ProviderDetailViewModel, Domain.Models.Provider>(dateTimeProvider)
                                : null);
            });

            var mapper = new Mapper(mapperConfig);

            var providerReferenceRepo = new GenericRepository <ProviderReference>(providerReferenceLogger, dbContext);
            var repo            = new GenericRepository <Domain.Models.Provider>(providerLogger, dbContext);
            var providerService = new ProviderService(mapper, repo, providerReferenceRepo);

            var sut = new ProviderController(providerService, config);

            //Act
            await sut.SaveProviderDetailAsync(viewModel);

            //Assert
            var result = await repo.GetSingleOrDefaultAsync(x => x.Id == provider.Id);

            provider.IsTLevelProvider.Should().BeFalse();
            result.IsTLevelProvider.Should().BeTrue();
        }