public async Task <HttpStatusCode> ReloadItemAsync(Uri url) { logger.LogInformation($"Getting Job Group item: {url}"); var jobGroupModel = await jobGroupApiConnector.GetDetailsAsync(url).ConfigureAwait(false); if (jobGroupModel != null) { var existingJobGroup = await jobGroupDocumentService.GetAsync(w => w.Soc == jobGroupModel.Soc, jobGroupModel.PartitionKey !).ConfigureAwait(false); if (existingJobGroup != null) { jobGroupModel.Etag = existingJobGroup.Etag; if (jobGroupModel.Id != existingJobGroup.Id) { logger.LogInformation($"Deleting previous Job Groups item: {existingJobGroup.Id} / {jobGroupModel.Soc} / {url}"); await jobGroupDocumentService.DeleteAsync(existingJobGroup.Id).ConfigureAwait(false); } } logger.LogInformation($"Upserting Job Groups item: {jobGroupModel.Soc} / {url}"); return(await jobGroupDocumentService.UpsertAsync(jobGroupModel).ConfigureAwait(false)); } return(HttpStatusCode.BadRequest); }
public async Task JobGroupPublishedRefreshServiceReloadIsSuccessful() { // arrange const HttpStatusCode expectedResult = HttpStatusCode.OK; var existingJobGroup = A.Dummy <JobGroupModel>(); var getSummaryResponse = new List <JobGroupSummaryItemModel> { new JobGroupSummaryItemModel { Id = Guid.NewGuid(), Soc = 1, Title = "A title 1", }, new JobGroupSummaryItemModel { Id = Guid.NewGuid(), Soc = 2, Title = "A title 2", }, }; var getDetailResponse = new JobGroupModel { Id = Guid.NewGuid(), Soc = 2, Title = "A title 2", }; A.CallTo(() => fakeJobGroupApiConnector.GetSummaryAsync(A <Uri> .Ignored)).Returns(getSummaryResponse); A.CallTo(() => fakeJobGroupDocumentService.PurgeAsync()).Returns(true); A.CallTo(() => fakeJobGroupApiConnector.GetDetailsAsync(A <Uri> .Ignored)).Returns(getDetailResponse); A.CallTo(() => fakeJobGroupDocumentService.GetAsync(A <Expression <Func <JobGroupModel, bool> > > .Ignored, A <string> .Ignored)).Returns(existingJobGroup); A.CallTo(() => fakeJobGroupDocumentService.UpsertAsync(A <JobGroupModel> .Ignored)).Returns(HttpStatusCode.OK); // act var result = await jobGroupPublishedRefreshService.ReloadAsync(new Uri("https://somewhere.com", UriKind.Absolute)).ConfigureAwait(false); // assert A.CallTo(() => fakeJobGroupApiConnector.GetSummaryAsync(A <Uri> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeJobGroupDocumentService.PurgeAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeJobGroupApiConnector.GetDetailsAsync(A <Uri> .Ignored)).MustHaveHappened(getSummaryResponse.Count, Times.Exactly); A.CallTo(() => fakeJobGroupDocumentService.GetAsync(A <Expression <Func <JobGroupModel, bool> > > .Ignored, A <string> .Ignored)).MustHaveHappened(getSummaryResponse.Count, Times.Exactly); A.CallTo(() => fakeJobGroupDocumentService.UpsertAsync(A <JobGroupModel> .Ignored)).MustHaveHappened(getSummaryResponse.Count, Times.Exactly); Assert.Equal(expectedResult, result); }
public async Task JobGroupApiConnectorTestsGetDetailsReturnsSuccess() { // arrange var expectedResult = new JobGroupModel { Id = Guid.NewGuid(), Soc = 3543, Title = "A title", }; A.CallTo(() => fakeApiDataConnector.GetAsync <JobGroupModel>(A <HttpClient> .Ignored, A <Uri> .Ignored)).Returns(expectedResult); // act var result = await jobGroupApiConnector.GetDetailsAsync(new Uri("https://somewhere.com", UriKind.Absolute)).ConfigureAwait(false); // assert A.CallTo(() => fakeApiDataConnector.GetAsync <JobGroupModel>(A <HttpClient> .Ignored, A <Uri> .Ignored)).MustHaveHappenedOnceExactly(); Assert.NotNull(result); Assert.Equal(expectedResult.Soc, result?.Soc); Assert.Equal(expectedResult.Title, result?.Title); }