예제 #1
0
        public async Task PagesDataLoadServiceLoadAsyncNullRegistrationDocumentNoUpdate()
        {
            // Arrange
            AppRegistrationModel?model = null;
            var serviceToTest          = new PagesDataLoadService(logger, fakeHttpClient, pagesClientOptions, fakeApiDataService, fakeDataLoadService);

            A.CallTo(() => fakeDataLoadService.GetAppRegistrationByPathAsync(A <string> .Ignored)).Returns(model);

            // Act
            await serviceToTest.LoadAsync().ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeDataLoadService.GetAppRegistrationByPathAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeDataLoadService.UpdateAppRegistrationAsync(A <AppRegistrationModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeApiDataService.GetAsync <PageLocationModel>(A <HttpClient> .Ignored, A <Uri> .Ignored)).MustNotHaveHappened();
        }
        public async Task <HttpStatusCode> CreateOrUpdateAsync(Guid contentId)
        {
            logger.LogInformation($"Load page location {contentId} into App Registration started");

            var appRegistration = await dataLoadService.GetAppRegistrationByPathAsync(AppRegistryPathNameForPagesApp).ConfigureAwait(false);

            if (appRegistration == null)
            {
                return(HttpStatusCode.NotFound);
            }

            var pageLocation = await GetPageAsync(contentId).ConfigureAwait(false);

            if (pageLocation == null)
            {
                logger.LogError($"Page {contentId} returned null from Pages API");
                return(HttpStatusCode.NotFound);
            }

            appRegistration.PageLocations?.Remove(contentId);

            if (pageLocation.Locations.Any())
            {
                if (appRegistration.PageLocations == null)
                {
                    appRegistration.PageLocations = new Dictionary <Guid, PageLocationModel>();
                }

                appRegistration.PageLocations.Add(contentId, pageLocation);

                appRegistration.LastModifiedDate = DateTime.UtcNow;

                await dataLoadService.UpdateAppRegistrationAsync(appRegistration).ConfigureAwait(false);
            }

            logger.LogInformation($"Load page location {contentId} into App Registration completed");

            return(HttpStatusCode.OK);
        }