Пример #1
0
        public async Task CacheReloadServiceGetAndSaveItemIsSuccessfulForUpdate()
        {
            // arrange
            var cancellationToken = new CancellationToken(false);
            var expectedValidPagesSummaryItemModel = BuildValidPagesSummaryItemModel();
            var expectedValidPagesApiDataModel     = BuildValidPagesApiDataModel();
            var expectedValidContentPageModel      = BuildValidContentPageModel();

            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiDataModel>(A <Uri> .Ignored)).Returns(expectedValidPagesApiDataModel);
            A.CallTo(() => fakeMapper.Map <ContentPageModel>(A <CmsApiDataModel> .Ignored)).Returns(expectedValidContentPageModel);
            A.CallTo(() => fakeEventMessageService.UpdateAsync(A <ContentPageModel> .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.GetAndSaveItemAsync(expectedValidPagesSummaryItemModel, cancellationToken).ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiDataModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeMapper.Map <ContentPageModel>(A <CmsApiDataModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeEventMessageService.UpdateAsync(A <ContentPageModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeEventMessageService.CreateAsync(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeContentCacheService.AddOrReplace(A <Guid> .Ignored, A <List <Guid> > .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
        }
Пример #2
0
        public async Task CacheReloadServiceReloadIsCancelled()
        {
            // arrange
            const int NumerOfSummaryItems         = 2;
            const int NumberOfDeletions           = 1;
            var       cancellationToken           = new CancellationToken(true);
            var       fakePagesSummaryItemModels  = BuldFakePagesSummaryItemModel(NumerOfSummaryItems);
            var       fakeCachedContentPageModels = BuldFakeContentPageModels(NumberOfDeletions);

            A.CallTo(() => fakeEventMessageService.GetAllCachedItemsAsync()).Returns(fakeCachedContentPageModels);
            A.CallTo(() => fakeCmsApiService.GetSummaryAsync <CmsApiSummaryItemModel>()).Returns(fakePagesSummaryItemModels);

            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()).MustNotHaveHappened();
            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiDataModel>(A <Uri> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeMapper.Map <ContentPageModel>(A <CmsApiDataModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeEventMessageService.UpdateAsync(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeEventMessageService.CreateAsync(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeEventMessageService.GetAllCachedItemsAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeContentCacheService.AddOrReplace(A <Guid> .Ignored, A <List <Guid> > .Ignored, A <string> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeAppRegistryService.PagesDataLoadAsync()).MustNotHaveHappened();
        }
Пример #3
0
        public async Task CacheReloadServiceReloadIsCancelled()
        {
            // arrange
            const int NumerOfSummaryItems = 2;
            const int NumberOfDeletions   = 1;
            var       cancellationToken   = new CancellationToken(true);
            var       expectedValidCmsApiSharedContentModel = BuildValidCmsApiSharedContentModel();
            var       fakeCmsApiSharedContentModel          = BuldFakeCmsApiSharedContentModel();


            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <string> .Ignored, A <Guid> .Ignored)).Returns(expectedValidCmsApiSharedContentModel);

            A.CallTo(() => fakeEventMessageService.GetAllCachedItemsAsync()).Returns(fakeCmsApiSharedContentModel);

            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)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <string> .Ignored, A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeEventMessageService.UpdateAsync(A <CmsApiSharedContentModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeEventMessageService.CreateAsync(A <CmsApiSharedContentModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();
        }
Пример #4
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();
        }
Пример #5
0
        public void CacheReloadServiceTryValidateModelForValidAndInvalid(ContentPageModel contentPageModel, bool expectedResult)
        {
            // arrange
            var cacheReloadService = new CacheReloadService(fakeLogger, fakeMapper, fakeEventMessageService, fakeCmsApiService, fakeContentCacheService, fakeAppRegistryService, fakeContentTypeMappingService, fakeApiCacheService);

            // act
            var result = cacheReloadService.TryValidateModel(contentPageModel);

            // assert
            A.Equals(result, expectedResult);
        }
Пример #6
0
        public async Task CacheReloadServicePostAppRegistryRefreshIsSuccessful()
        {
            // arrange
            var cacheReloadService = new CacheReloadService(fakeLogger, fakeMapper, fakeEventMessageService, fakeCmsApiService, fakeContentCacheService, fakeAppRegistryService, fakeContentTypeMappingService, fakeApiCacheService);

            // act
            await cacheReloadService.PostAppRegistryRefresh().ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeAppRegistryService.PagesDataLoadAsync()).MustHaveHappenedOnceExactly();
        }
Пример #7
0
        public async Task CacheReloadServiceDeleteStaleItemsIsCancelled()
        {
            // arrange
            const int NumberOfDeletions     = 2;
            var       cancellationToken     = new CancellationToken(true);
            var       fakeContentPageModels = BuldFakeContentPageModels(NumberOfDeletions);

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

            // act
            await cacheReloadService.DeleteStaleItemsAsync(fakeContentPageModels, cancellationToken).ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();
        }
Пример #8
0
        public async Task CacheReloadServiceRemoveDuplicateCacheItemsNoData()
        {
            // arrange
            const int NumberOfItems = 0;
            var       fakeCachedContentPageModels = BuldFakeContentPageModels(NumberOfItems);

            A.CallTo(() => fakeEventMessageService.GetAllCachedItemsAsync()).Returns(fakeCachedContentPageModels);

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

            // act
            await cacheReloadService.RemoveDuplicateCacheItems().ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeEventMessageService.GetAllCachedItemsAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();
        }
Пример #9
0
        public async Task CacheReloadServiceGetAndSaveItemIsCancelled()
        {
            // arrange
            var cancellationToken = new CancellationToken(true);
            var expectedValidCmsApiSharedContentModel = BuildValidCmsApiSharedContentModel();

            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <string> .Ignored, A <Guid> .Ignored)).Returns(expectedValidCmsApiSharedContentModel);

            var cacheReloadService = new CacheReloadService(fakeLogger, fakeEventMessageService, fakeCmsApiService, fakeContentTypeMappingService, _config);
            // act
            await cacheReloadService.GetAndSaveItemAsync(expectedValidCmsApiSharedContentModel, cancellationToken).ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <string> .Ignored, A <Guid> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeEventMessageService.UpdateAsync(A <CmsApiSharedContentModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeEventMessageService.CreateAsync(A <CmsApiSharedContentModel> .Ignored)).MustNotHaveHappened();
        }
Пример #10
0
        public async Task CacheReloadServiceDeleteStaleCacheEntriesIsCancelled()
        {
            // arrange
            const int NumerOfSummaryItems         = 2;
            const int NumberOfDeletions           = 3;
            var       cancellationToken           = new CancellationToken(true);
            var       fakePagesSummaryItemModels  = BuldFakePagesSummaryItemModel(NumerOfSummaryItems);
            var       fakeCachedContentPageModels = BuldFakeContentPageModels(NumberOfDeletions);

            A.CallTo(() => fakeEventMessageService.GetAllCachedItemsAsync()).Returns(fakeCachedContentPageModels);

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

            // act
            await cacheReloadService.DeleteStaleCacheEntriesAsync(fakePagesSummaryItemModels, cancellationToken).ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeEventMessageService.GetAllCachedItemsAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();
        }