public async Task <FullDeltaReportModel> GetAllAsync() { logger.LogInformation("Loading SOC delta"); var fullDeltaReportModel = new FullDeltaReportModel { Id = Guid.NewGuid() }; var draftSummaries = await draftJobGroupApiConnector.GetSummaryAsync().ConfigureAwait(false) ?? new List <JobGroupSummaryItemModel>(); var publishedSummaries = await publishedJobGroupApiConnector.GetSummaryAsync().ConfigureAwait(false) ?? new List <JobGroupSummaryItemModel>(); var draftSocs = (from a in draftSummaries select a.Soc).ToList(); var publishedSocs = (from a in publishedSummaries select a.Soc).ToList(); var allSocs = draftSocs.Union(publishedSocs).Distinct().ToList(); fullDeltaReportModel.DeltaReportSocs = (from soc in allSocs select new DeltaReportSocModel { Soc = soc, }).ToList(); foreach (var deltaReportSocModel in fullDeltaReportModel.DeltaReportSocs) { deltaReportSocModel.DraftJobGroup = await draftJobGroupApiConnector.GetDetailAsync(deltaReportSocModel.Soc).ConfigureAwait(false); deltaReportSocModel.PublishedJobGroup = await publishedJobGroupApiConnector.GetDetailAsync(deltaReportSocModel.Soc).ConfigureAwait(false); } SetState(fullDeltaReportModel.Id.Value, fullDeltaReportModel.DeltaReportSocs); return(fullDeltaReportModel); }
public async Task JobGroupDataServiceGetAllReturnsSuccessfully() { A.CallTo(() => fakeDraftJobGroupApiConnector.GetSummaryAsync()).Returns(draftJobGroupSummaryItemModels); A.CallTo(() => fakePublishedJobGroupApiConnector.GetSummaryAsync()).Returns(publishedJobGroupSummaryItemModels); A.CallTo(() => fakeDraftJobGroupApiConnector.GetDetailAsync(A <int> .Ignored)).ReturnsNextFromSequence(dummyDraftJobGroupModels); A.CallTo(() => fakePublishedJobGroupApiConnector.GetDetailAsync(A <int> .Ignored)).ReturnsNextFromSequence(dummyPublishedJobGroupModels); // Act var result = await jobGroupDataService.GetAllAsync().ConfigureAwait(false); // Assert A.CallTo(() => fakeDraftJobGroupApiConnector.GetSummaryAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => fakePublishedJobGroupApiConnector.GetSummaryAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDraftJobGroupApiConnector.GetDetailAsync(A <int> .Ignored)).MustHaveHappened(expectedGetAllResult.DeltaReportSocs !.Count, Times.Exactly); A.CallTo(() => fakePublishedJobGroupApiConnector.GetDetailAsync(A <int> .Ignored)).MustHaveHappened(expectedGetAllResult.DeltaReportSocs.Count, Times.Exactly); Assert.NotNull(result.DeltaReportSocs); Assert.Equal(expectedGetAllResult.DeltaReportSocs.Count, result.DeltaReportSocs?.Count); Assert.NotNull(result?.DeltaReportSocs?[0].PublishedJobGroup); Assert.NotNull(result?.DeltaReportSocs?[2].DraftJobGroup); Assert.Equal(expectedGetAllResult.DeltaReportSocs[0].Soc, result?.DeltaReportSocs?[0].Soc); Assert.Equal(expectedGetAllResult.DeltaReportSocs[1].Soc, result?.DeltaReportSocs?[1].Soc); Assert.Equal(expectedGetAllResult.DeltaReportSocs[2].Soc, result?.DeltaReportSocs?[2].Soc); }