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); }
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 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); }
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); }
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(); }
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 !); }