Ejemplo n.º 1
0
        public async Task PagesDataLoadServiceRemoveAsyncRegistrationDocumentUpdated()
        {
            // Arrange
            const HttpStatusCode expectedResult = HttpStatusCode.OK;
            var testGuid = Guid.NewGuid();
            AppRegistrationModel model = new AppRegistrationModel {
                Path = "/pages", PageLocations = new Dictionary <Guid, PageLocationModel> {
                    { testGuid, new PageLocationModel {
                          Locations = new List <string> {
                              "http://somewhere.com/a-place-a-page"
                          }
                      } }
                }
            };
            var serviceToTest = new PagesDataLoadService(logger, fakeHttpClient, pagesClientOptions, fakeApiDataService, fakeDataLoadService);

            A.CallTo(() => fakeDataLoadService.GetAppRegistrationByPathAsync(A <string> .Ignored)).Returns(model);
            A.CallTo(() => fakeApiDataService.GetAsync <PageLocationModel>(A <HttpClient> .Ignored, A <Uri> .Ignored)).Returns(PageLocationModels.FirstOrDefault().Value);

            // Act
            var result = await serviceToTest.RemoveAsync(testGuid).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeDataLoadService.GetAppRegistrationByPathAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeDataLoadService.UpdateAppRegistrationAsync(A <AppRegistrationModel> .Ignored)).MustHaveHappenedOnceExactly();

            Assert.Equal(expectedResult, result);
        }
        public async Task PagesDataLoadServiceCreateOrUpdateAsyncRegistrationDocumentlocationsUpdated()
        {
            // Arrange
            var testGuid = Guid.NewGuid();
            AppRegistrationModel model = new AppRegistrationModel {
                Path = "/pages", PageLocations = new Dictionary <Guid, PageLocationModel> {
                    { testGuid, new PageLocationModel {
                          Locations = new List <string> {
                              "http://somewhere.com/a-place-a-page"
                          }
                      } }
                }
            };
            int expectedPageLocationCount = model.PageLocations.Count;
            var serviceToTest             = new PagesDataLoadService(logger, fakeHttpClient, pagesClientOptions, fakeApiDataService, fakeLegacyDataLoadService);

            A.CallTo(() => fakeLegacyDataLoadService.GetAppRegistrationByPathAsync(A <string> .Ignored)).Returns(model);
            A.CallTo(() => fakeApiDataService.GetAsync <PageLocationModel>(A <HttpClient> .Ignored, A <Uri> .Ignored)).Returns(PageLocationModels.FirstOrDefault().Value);

            // Act
            await serviceToTest.CreateOrUpdateAsync(testGuid).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeLegacyDataLoadService.GetAppRegistrationByPathAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeLegacyDataLoadService.UpdateAppRegistrationAsync(A <AppRegistrationModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeApiDataService.GetAsync <PageLocationModel>(A <HttpClient> .Ignored, A <Uri> .Ignored)).MustHaveHappenedOnceExactly();

            Assert.NotNull(model.PageLocations);
            Assert.Equal(expectedPageLocationCount, model.PageLocations !.Count);
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        public async Task PagesDataLoadServiceRemoveAsyncNullRegistrationDocumentNoUpdate()
        {
            // Arrange
            const HttpStatusCode expectedResult = HttpStatusCode.NotFound;
            AppRegistrationModel?model          = null;
            var serviceToTest = new PagesDataLoadService(logger, fakeHttpClient, pagesClientOptions, fakeApiDataService, fakeDataLoadService);

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

            // Act
            var result = await serviceToTest.RemoveAsync(Guid.NewGuid()).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();

            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 5
0
        public async Task PagesDataLoadServiceLoadAsyncRegistrationDocumentUpdated()
        {
            // Arrange
            AppRegistrationModel model = new AppRegistrationModel {
                Path = "/pages"
            };
            var serviceToTest = new PagesDataLoadService(logger, fakeHttpClient, pagesClientOptions, fakeApiDataService, fakeDataLoadService);

            A.CallTo(() => fakeDataLoadService.GetAppRegistrationByPathAsync(A <string> .Ignored)).Returns(model);
            A.CallTo(() => fakeApiDataService.GetAsync <Dictionary <Guid, PageLocationModel> >(A <HttpClient> .Ignored, A <Uri> .Ignored)).Returns(PageLocationModels);

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

            // Assert
            A.CallTo(() => fakeDataLoadService.GetAppRegistrationByPathAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeDataLoadService.UpdateAppRegistrationAsync(A <AppRegistrationModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeApiDataService.GetAsync <Dictionary <Guid, PageLocationModel> >(A <HttpClient> .Ignored, A <Uri> .Ignored)).MustHaveHappenedOnceExactly();

            Assert.NotNull(model.PageLocations);
            Assert.Equal(PageLocationModels.Count, model.PageLocations !.Count);
        }
Ejemplo n.º 6
0
        public async Task PagesDataLoadServiceCreateOrUpdateAsyncNullPagesNoRegistrationDocumentUpdated()
        {
            // Arrange
            AppRegistrationModel model = new AppRegistrationModel {
                Path = "/pages"
            };
            var serviceToTest = new PagesDataLoadService(logger, fakeHttpClient, pagesClientOptions, fakeApiDataService, fakeDataLoadService);

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

            PageLocationModel?pageModel = null;

            A.CallTo(() => fakeApiDataService.GetAsync <PageLocationModel>(A <HttpClient> .Ignored, A <Uri> .Ignored)).Returns(pageModel);

            // Act
            var result = await serviceToTest.CreateOrUpdateAsync(Guid.Parse("66088614-5c55-4698-8382-42b47ec0be10")).ConfigureAwait(false);

            // Assert
            Assert.Equal(HttpStatusCode.NotFound, result);
            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)).MustHaveHappenedOnceExactly();
        }
Ejemplo n.º 7
0
        public async Task PagesDataLoadServiceCreateOrUpdateAsyncRegistrationDocumentLocationsReplaced()
        {
            // Arrange
            var testGuid = Guid.NewGuid();
            AppRegistrationModel model = new AppRegistrationModel {
                Path = "/pages", PageLocations = null,
            };
            var serviceToTest = new PagesDataLoadService(logger, fakeHttpClient, pagesClientOptions, fakeApiDataService, fakeDataLoadService);

            A.CallTo(() => fakeDataLoadService.GetAppRegistrationByPathAsync(A <string> .Ignored)).Returns(model);
            A.CallTo(() => fakeApiDataService.GetAsync <PageLocationModel>(A <HttpClient> .Ignored, A <Uri> .Ignored)).Returns(PageLocationModels.FirstOrDefault().Value);

            // Act
            await serviceToTest.CreateOrUpdateAsync(testGuid).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeDataLoadService.GetAppRegistrationByPathAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeDataLoadService.UpdateAppRegistrationAsync(A <AppRegistrationModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeApiDataService.GetAsync <PageLocationModel>(A <HttpClient> .Ignored, A <Uri> .Ignored)).MustHaveHappenedOnceExactly();

            Assert.NotNull(model.PageLocations);
            Assert.Single(model.PageLocations !);
        }