Example #1
0
        public async Task CacheReloadServiceReloadIsSuccessfulForCreate()
        {
            // arrange
            var cancellationToken = new CancellationToken(false);
            var expectedValidCmsApiSharedContentModel = BuildValidCmsApiSharedContentModel();

            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <string> .Ignored, A <Guid> .Ignored)).Returns(expectedValidCmsApiSharedContentModel);
            A.CallTo(() => fakeEventMessageService.UpdateAsync(A <CmsApiSharedContentModel> .Ignored))
            .Returns(HttpStatusCode.NotFound);
            A.CallTo(() => fakeEventMessageService.CreateAsync(A <CmsApiSharedContentModel> .Ignored))
            .Returns(HttpStatusCode.Created);

            A.CallTo(() => fakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).Returns(HttpStatusCode.OK);

            var cacheReloadService = new CacheReloadService(fakeLogger, fakeEventMessageService, fakeCmsApiService,
                                                            fakeContentTypeMappingService, _config);

            // act
            await cacheReloadService.Reload(cancellationToken).ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeContentTypeMappingService.AddMapping(A <string> .Ignored, A <Type> .Ignored))
            .MustHaveHappenedOnceOrMore();
            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <string> .Ignored, A <Guid> .Ignored))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeEventMessageService.UpdateAsync(A <CmsApiSharedContentModel> .Ignored))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeEventMessageService.CreateAsync(A <CmsApiSharedContentModel> .Ignored))
            .MustHaveHappenedOnceExactly();
        }
Example #2
0
        public async Task Reload(CancellationToken stoppingToken)
        {
            try
            {
                logger.LogInformation("Reload cache started");

                apiCacheService.StartCache();

                contentTypeMappingService.AddMapping(Constants.ContentTypeHtml, typeof(CmsApiHtmlModel));
                contentTypeMappingService.AddMapping(Constants.ContentTypeHtmlShared, typeof(CmsApiHtmlSharedModel));
                contentTypeMappingService.AddMapping(Constants.ContentTypeSharedContent, typeof(CmsApiSharedContentModel));
                contentTypeMappingService.AddMapping(Constants.ContentTypePageLocation, typeof(CmsApiPageLocationModel));
                contentTypeMappingService.AddMapping(Constants.ContentTypePageLocationParent, typeof(CmsApiPageLocationParentModel));

                await RemoveDuplicateCacheItems().ConfigureAwait(false);

                var summaryList = await GetSummaryListAsync().ConfigureAwait(false);

                if (stoppingToken.IsCancellationRequested)
                {
                    logger.LogWarning("Reload cache cancelled");

                    return;
                }

                if (summaryList != null && summaryList.Any())
                {
                    await ProcessSummaryListAsync(summaryList, stoppingToken).ConfigureAwait(false);

                    if (stoppingToken.IsCancellationRequested)
                    {
                        logger.LogWarning("Reload cache cancelled");

                        return;
                    }

                    await DeleteStaleCacheEntriesAsync(summaryList, stoppingToken).ConfigureAwait(false);
                }

                await PostAppRegistryRefresh().ConfigureAwait(false);

                logger.LogInformation("Reload cache completed");
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error in cache reload");
            }
            finally
            {
                apiCacheService.StopCache();
            }
        }
        public async Task Reload(CancellationToken stoppingToken)
        {
            try
            {
                logger.LogInformation("Reload cache started");

                contentTypeMappingService.AddMapping(Constants.ContentTypeSharedContent, typeof(CmsApiSharedContentModel));

                var sharedContent = await GetSharedContentAsync().ConfigureAwait(false);

                if (stoppingToken.IsCancellationRequested)
                {
                    logger.LogWarning("Reload cache cancelled");

                    return;
                }

                if (sharedContent != null)
                {
                    await ProcessSummaryListAsync(sharedContent, stoppingToken).ConfigureAwait(false);
                }

                logger.LogInformation("Reload cache completed");
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error in cache reload");
            }
        }
Example #4
0
        public async Task ReloadAsync(CancellationToken stoppingToken)
        {
            try
            {
                logger.LogInformation("Reload shared content started");

                contentTypeMappingService.AddMapping(Constants.ContentTypeSharedContent, typeof(CmsApiSharedContentModel));

                if (stoppingToken.IsCancellationRequested)
                {
                    logger.LogWarning("Reload shared content cancelled");

                    return;
                }

                await ReloadCacheItem(Guid.Parse(Constants.SharedContentAskAdviserItemId), stoppingToken).ConfigureAwait(false);

                logger.LogInformation("Reload All shared content completed");
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error in shared content cache reload");
                throw;
            }
        }
        public async Task Reload(CancellationToken stoppingToken)
        {
            try
            {
                logger.LogInformation("Reload configuration set started");

                contentTypeMappingService.AddMapping(Constants.ContentTypeForConfigurationItem, typeof(ConfigurationItemApiDataModel));

                if (stoppingToken.IsCancellationRequested)
                {
                    logger.LogWarning("Reload configuration set cancelled");

                    return;
                }

                await ReloadConfigurationSetTemplate(stoppingToken).ConfigureAwait(false);

                logger.LogInformation("Reload All configuration set completed");
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error in configuration set reload");
                throw;
            }
        }
Example #6
0
        public async Task JobGroupCacheRefreshServiceReloadIsSuccessful()
        {
            // arrange
            const HttpStatusCode expectedUpsertResult = HttpStatusCode.OK;

            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <Uri> .Ignored)).Returns(A.Dummy <CmsApiSharedContentModel>());
            A.CallTo(() => fakeMapper.Map <ContentItemModel>(A <CmsApiSharedContentModel> .Ignored)).Returns(A.Dummy <ContentItemModel>());
            A.CallTo(() => fakeContentItemDocumentService.UpsertAsync(A <ContentItemModel> .Ignored)).Returns(expectedUpsertResult);

            // act
            await sharedContentCacheReloadService.ReloadAsync(new CancellationToken(false)).ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeContentTypeMappingService.AddMapping(A <string> .Ignored, A <Type> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeMapper.Map <ContentItemModel>(A <CmsApiSharedContentModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeContentItemDocumentService.UpsertAsync(A <ContentItemModel> .Ignored)).MustHaveHappenedOnceExactly();
        }
        public LmiOrchestrationTrigger(
            ILogger <LmiOrchestrationTrigger> logger,
            IMapper mapper,
            IContentTypeMappingService contentTypeMappingService,
            ICmsApiService cmsApiService,
            IDocumentService <JobGroupModel> jobGroupDocumentService,
            IEventGridService eventGridService,
            EventGridClientOptions eventGridClientOptions)
        {
            this.logger = logger;
            this.mapper = mapper;
            this.jobGroupDocumentService = jobGroupDocumentService;
            this.cmsApiService           = cmsApiService;
            this.jobGroupDocumentService = jobGroupDocumentService;
            this.eventGridService        = eventGridService;
            this.eventGridClientOptions  = eventGridClientOptions;

            contentTypeMappingService.AddMapping(nameof(LmiSocJobProfile), typeof(LmiSocJobProfile));
            contentTypeMappingService.AddMapping(nameof(LmiSocPredicted), typeof(LmiSocPredicted));
            contentTypeMappingService.AddMapping(nameof(LmiSocPredictedYear), typeof(LmiSocPredictedYear));
            contentTypeMappingService.AddMapping(nameof(LmiSocBreakdown), typeof(LmiSocBreakdown));
            contentTypeMappingService.AddMapping(nameof(LmiSocBreakdownYear), typeof(LmiSocBreakdownYear));
            contentTypeMappingService.AddMapping(nameof(LmiSocBreakdownYearValue), typeof(LmiSocBreakdownYearValue));

            //TODO: ian: need to initialize the telemetry properly
            Activity?activity = null;

            if (Activity.Current == null)
            {
                activity = new Activity(nameof(LmiWebhookHttpTrigger)).Start();
                activity.SetParentId(Guid.NewGuid().ToString());
            }
        }
Example #8
0
        public async Task CacheReloadServiceReloadIsSuccessfulForCreate()
        {
            // arrange
            const int NumerOfSummaryItems           = 2;
            const int NumberOfDeletions             = 3;
            var       cancellationToken             = new CancellationToken(false);
            var       expectedValidContentPageModel = BuildValidContentPageModel();
            var       fakePagesSummaryItemModels    = BuldFakePagesSummaryItemModel(NumerOfSummaryItems);
            var       fakeCachedContentPageModels   = BuldFakeContentPageModels(NumberOfDeletions);

            A.CallTo(() => fakeCmsApiService.GetSummaryAsync <CmsApiSummaryItemModel>()).Returns(fakePagesSummaryItemModels);
            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiDataModel>(A <Uri> .Ignored)).Returns(A.Fake <CmsApiDataModel>());
            A.CallTo(() => fakeMapper.Map <ContentPageModel>(A <CmsApiDataModel> .Ignored)).Returns(expectedValidContentPageModel);
            A.CallTo(() => fakeEventMessageService.UpdateAsync(A <ContentPageModel> .Ignored)).Returns(HttpStatusCode.NotFound);
            A.CallTo(() => fakeEventMessageService.CreateAsync(A <ContentPageModel> .Ignored)).Returns(HttpStatusCode.Created);
            A.CallTo(() => fakeEventMessageService.GetAllCachedItemsAsync()).Returns(fakeCachedContentPageModels);
            A.CallTo(() => fakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).Returns(HttpStatusCode.OK);
            A.CallTo(() => fakeContentCacheService.AddOrReplace(A <Guid> .Ignored, A <List <Guid> > .Ignored, A <string> .Ignored));

            var cacheReloadService = new CacheReloadService(fakeLogger, fakeMapper, fakeEventMessageService, fakeCmsApiService, fakeContentCacheService, fakeAppRegistryService, fakeContentTypeMappingService, fakeApiCacheService);

            // act
            await cacheReloadService.Reload(cancellationToken).ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeContentTypeMappingService.AddMapping(A <string> .Ignored, A <Type> .Ignored)).MustHaveHappenedOnceOrMore();
            A.CallTo(() => fakeCmsApiService.GetSummaryAsync <CmsApiSummaryItemModel>()).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeContentCacheService.Clear()).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiDataModel>(A <Uri> .Ignored)).MustHaveHappened(NumerOfSummaryItems, Times.Exactly);
            A.CallTo(() => fakeMapper.Map <ContentPageModel>(A <CmsApiDataModel> .Ignored)).MustHaveHappened(NumerOfSummaryItems, Times.Exactly);
            A.CallTo(() => fakeEventMessageService.UpdateAsync(A <ContentPageModel> .Ignored)).MustHaveHappened(NumerOfSummaryItems, Times.Exactly);
            A.CallTo(() => fakeEventMessageService.CreateAsync(A <ContentPageModel> .Ignored)).MustHaveHappened(NumerOfSummaryItems, Times.Exactly);
            A.CallTo(() => fakeEventMessageService.GetAllCachedItemsAsync()).MustHaveHappenedTwiceExactly();
            A.CallTo(() => fakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappened(NumberOfDeletions, Times.Exactly);
            A.CallTo(() => fakeContentCacheService.AddOrReplace(A <Guid> .Ignored, A <List <Guid> > .Ignored, A <string> .Ignored)).MustHaveHappened(NumerOfSummaryItems, Times.Exactly);
            A.CallTo(() => fakeAppRegistryService.PagesDataLoadAsync()).MustHaveHappenedOnceExactly();
        }