Beispiel #1
0
        public async Task JobGroupApiConnectorTestsGetSummaryReturnsSuccess()
        {
            // arrange
            var expectedResults = new List <JobGroupSummaryItemModel>
            {
                new JobGroupSummaryItemModel
                {
                    Id    = Guid.NewGuid(),
                    Soc   = 3543,
                    Title = "A title",
                },
            };

            A.CallTo(() => fakeApiDataConnector.GetAsync <IList <JobGroupSummaryItemModel> >(A <HttpClient> .Ignored, A <Uri> .Ignored)).Returns(expectedResults);

            // act
            var results = await jobGroupApiConnector.GetSummaryAsync(new Uri("https://somewhere.com", UriKind.Absolute)).ConfigureAwait(false);

            // assert
            A.CallTo(() => fakeApiDataConnector.GetAsync <IList <JobGroupSummaryItemModel> >(A <HttpClient> .Ignored, A <Uri> .Ignored)).MustHaveHappenedOnceExactly();
            Assert.NotNull(results);
            Assert.Equal(expectedResults.Count, results !.Count);
            Assert.Equal(expectedResults.First().Soc, results.First().Soc);
            Assert.Equal(expectedResults.First().Title, results.First().Title);
        }
Beispiel #2
0
        public async Task <HttpStatusCode> ReloadAsync(Uri url)
        {
            logger.LogInformation($"Refreshing all Job Groups from {url}");
            var summaries = await jobGroupApiConnector.GetSummaryAsync(url).ConfigureAwait(false);

            if (summaries != null && summaries.Any())
            {
                await PurgeAsync().ConfigureAwait(false);

                foreach (var item in summaries)
                {
                    await ReloadItemAsync(new Uri($"{url}/{item.Id}", UriKind.Absolute)).ConfigureAwait(false);
                }

                logger.LogInformation($"Refreshed all Job Groups from {url}");

                return(HttpStatusCode.OK);
            }

            return(HttpStatusCode.NoContent);
        }
        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);
        }