Esempio n. 1
0
        public async Task ReloadSharedContent(CancellationToken stoppingToken)
        {
            var contentItemKeys = SharedContentKeyHelper.GetSharedContentKeys();

            foreach (var key in contentItemKeys)
            {
                if (stoppingToken.IsCancellationRequested)
                {
                    logger.LogWarning("Reload shared content cache cancelled");

                    return;
                }

                var apiDataModel = await cmsApiService.GetItemAsync <SharedContentItemApiDataModel>("sharedcontent", key).ConfigureAwait(false);

                if (apiDataModel == null)
                {
                    logger.LogError($"shared content: {key} not found in API response");
                }
                else
                {
                    var mappedContentItem = mapper.Map <SharedContentItemModel>(apiDataModel);

                    await sharedContentDocumentService.UpsertAsync(mappedContentItem).ConfigureAwait(false);
                }
            }
        }
        public async Task SharedContentCacheReloadServiceReloadSharedContentNullApiResponse()
        {
            //Arrange
            SharedContentItemApiDataModel?nullContentItem = null;

            A.CallTo(() => fakeCmsApiService.GetItemAsync <SharedContentItemApiDataModel>(A <string> .Ignored, A <Guid> .Ignored)).Returns(nullContentItem);
            var sharedContentCacheReloadService = new SharedContentCacheReloadService(A.Fake <ILogger <SharedContentCacheReloadService> >(), fakeMapper, fakeSharedContentItemDocumentService, fakeCmsApiService);

            //Act
            await sharedContentCacheReloadService.ReloadSharedContent(CancellationToken.None).ConfigureAwait(false);

            //Assert
            A.CallTo(() => fakeCmsApiService.GetItemAsync <SharedContentItemApiDataModel>(A <string> .Ignored, A <Guid> .Ignored)).MustHaveHappened(SharedContentKeyHelper.GetSharedContentKeys().Count(), Times.Exactly);
            A.CallTo(() => fakeSharedContentItemDocumentService.UpsertAsync(A <SharedContentItemModel> .Ignored)).MustNotHaveHappened();
        }