예제 #1
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();
        }
예제 #2
0
        public async Task ProcessSummaryListAsync(IList <CmsApiSummaryItemModel>?summaryList, CancellationToken stoppingToken)
        {
            logger.LogInformation("Process summary list started");

            contentCacheService.Clear();

            foreach (var item in summaryList.OrderByDescending(o => o.Published).ThenBy(o => o.Title))
            {
                if (stoppingToken.IsCancellationRequested)
                {
                    logger.LogWarning("Process summary list cancelled");

                    return;
                }

                await GetAndSaveItemAsync(item, stoppingToken).ConfigureAwait(false);
            }

            logger.LogInformation("Process summary list completed");
        }