public async Task OnGetAsync_WhenGettingProviderResultsIsNotSuccess_AllocationDetails_NotPopulated() { // Arrange IResultsApiClient resultsApiClient = CreateApiClient(); ISpecsApiClient specsClient = CreateSpecsApiClient(); IMapper mapper = CreateMapper(); ILogger logger = CreateLogger(); ProviderAllocationLinePageModel providerAllocPageModel = CreatePageModel(resultsApiClient, specsClient, mapper, logger); IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") }; Provider provider = CreateProvider(); IEnumerable <string> specSummary = GetSpecificationsWithResults(); IList <CalculationResultItem> calResult = GetCalcResults(); IList <AllocationLineResultItem> allocResult = GetAllocationResults(); ProviderResults providerResults = null; resultsApiClient.GetProviderByProviderId(Arg.Any <string>()) .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider)); specsClient.GetFundingPeriods() .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods)); resultsApiClient.GetProviderResults(Arg.Is("2"), Arg.Is("2")) .Returns(new ApiResponse <ProviderResults>(HttpStatusCode.NoContent, providerResults)); resultsApiClient.GetSpecificationIdsForProvider("2") .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary)); specsClient .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>())); specsClient .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>())); // Act IActionResult result = await providerAllocPageModel.OnGetAsync("2", "1617", "2"); // Assert PageResult pageResult = result as PageResult; pageResult.Should().NotBeNull(); providerAllocPageModel.ViewModel.AllocationLineItems.Should().HaveCount(0); providerAllocPageModel.ViewModel.CalculationItems.Should().HaveCount(0); }
public async Task OnGetAsync_WhenGettingProviderResultsIsSuccess_CalculationDetails_Populated() { // Arrange IResultsApiClient resultsApiClient = CreateApiClient(); ISpecsApiClient specsClient = CreateSpecsApiClient(); IMapper mapper = CreateMapper(); ILogger logger = CreateLogger(); IFeatureToggle featureToggle = Substitute.For <IFeatureToggle>(); ProviderCalcsResultsPageModel provideCalcPageModel = CreatePageModel(resultsApiClient, specsClient, mapper, logger, featureToggle); IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") }; Provider provider = CreateProvider(); IEnumerable <string> specSummary = GetSpecificationsWithResults(); IList <CalculationResultItem> calResult = GetCalcResults(); IList <AllocationLineResultItem> allocResult = GetAllocationResults(); ProviderResults providerResults = new ProviderResults() { AllocationResults = allocResult, CalculationResults = calResult }; resultsApiClient.GetProviderByProviderId(Arg.Any <string>()) .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider)); specsClient.GetFundingPeriods() .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods)); resultsApiClient.GetProviderResults(Arg.Is("2"), Arg.Is("2")) .Returns(new ApiResponse <ProviderResults>(HttpStatusCode.OK, providerResults)); resultsApiClient.GetSpecificationIdsForProvider("2") .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary)); specsClient .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>())); // Act IActionResult result = await provideCalcPageModel.OnGetAsync("2", "1617", "2"); // Assert provideCalcPageModel.CalculationErrorCount.Equals(1); provideCalcPageModel.ViewModel.CalculationItems.Should().HaveSameCount(calResult); provideCalcPageModel.ViewModel.CalculationItems.First().CalculationType.Should().Be(Clients.SpecsClient.Models.CalculationSpecificationType.Number); provideCalcPageModel.ViewModel.CalculationItems.Last().CalculationType.Should().Be(Clients.SpecsClient.Models.CalculationSpecificationType.Funding); }
public void TestScenarioResultsService_PerformSearch_WhenRowCountsApiCallContentIsNull_ThenExceptionThrown() { // Arrange IScenarioSearchService searchService = CreateScenarioSearchService(); ISpecsApiClient specsApiClient = CreateSpecsApiClient(); ITestEngineApiClient testEngineApiClient = CreateTestEngineApiClient(); ILogger logger = CreateLogger(); TestScenarioResultRequestViewModel resultRequestViewModel = new TestScenarioResultRequestViewModel() { SearchTerm = "", PageNumber = 1, FundingPeriodId = null, SpecificationId = null, }; TestScenarioResultsService testScenarioResultsService = CreateService(searchService, specsApiClient, testEngineApiClient, logger: logger); searchService.PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(new ScenarioSearchResultViewModel() { Scenarios = new List <ScenarioSearchResultItemViewModel>() { new ScenarioSearchResultItemViewModel() { Id = "s1", Name = "S1", }, new ScenarioSearchResultItemViewModel() { Id = "s2", Name = "S2", }, } }); List <SpecificationSummary> specifications = CreateSpecifications(); specsApiClient .GetSpecificationSummaries() .Returns(new ApiResponse <IEnumerable <SpecificationSummary> >(HttpStatusCode.OK, specifications)); testEngineApiClient .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>()) .Returns(new ApiResponse <IEnumerable <TestScenarioResultCounts> >(HttpStatusCode.OK, null)); // Act Func <Task> action = async() => await testScenarioResultsService.PerformSearch(resultRequestViewModel); // Assert action. Should() .ThrowExactly <InvalidOperationException>() .WithMessage("Row counts api request failed with null content"); logger .Received(1) .Warning(Arg.Is("Row counts api request failed with null content")); }
public async Task OnGetAsync_ReturnsValidFundingPeriodAsync() { // Arrange IResultsApiClient resultsApiClient = CreateApiClient(); ISpecsApiClient specsClient = CreateSpecsApiClient(); IMapper mapper = CreateMapper(); ILogger logger = CreateLogger(); IFeatureToggle featureToggle = Substitute.For <IFeatureToggle>(); ProviderCalcsResultsPageModel provideCalcPageModel = CreatePageModel(resultsApiClient, specsClient, mapper, logger, featureToggle); Provider provider = CreateProvider(); IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") }; IEnumerable <string> specSummary = GetSpecificationsWithResults(); IList <CalculationResultItem> calResult = GetCalcResults(); IList <AllocationLineResultItem> allocResult = GetAllocationResults(); ProviderResults providerResults = new ProviderResults() { AllocationResults = allocResult, CalculationResults = calResult }; resultsApiClient.GetProviderByProviderId(Arg.Any <string>()) .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider)); specsClient.GetFundingPeriods() .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods)); resultsApiClient.GetProviderResults(Arg.Is("2"), Arg.Is("2")) .Returns(new ApiResponse <ProviderResults>(HttpStatusCode.OK, providerResults)); resultsApiClient.GetSpecificationIdsForProvider("2") .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary)); specsClient .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>())); // Act IActionResult result = await provideCalcPageModel.OnGetAsync("2", "1617", "2"); // Assert result.Should() .BeOfType <PageResult>() .Which.Should().NotBeNull("Action result was null"); provideCalcPageModel.FundingPeriods.Should().NotBeNull(); }
public void OnGetAsync_WhenGettingProviderResponseIsNotSuccess_ThrowsException() { // Arrange IResultsApiClient resultsApiClient = CreateApiClient(); ISpecsApiClient specsClient = CreateSpecsApiClient(); IMapper mapper = CreateMapper(); ILogger logger = CreateLogger(); IFeatureToggle featureToggle = Substitute.For <IFeatureToggle>(); ProviderCalcsResultsPageModel provideCalcPageModel = CreatePageModel(resultsApiClient, specsClient, mapper, logger, featureToggle); IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") }; Provider provider = null; IEnumerable <string> specSummary = GetSpecificationsWithResults(); IList <CalculationResultItem> calResult = GetCalcResults(); IList <AllocationLineResultItem> allocResult = GetAllocationResults(); ProviderResults providerResults = new ProviderResults() { AllocationResults = allocResult, CalculationResults = calResult }; resultsApiClient.GetProviderByProviderId(Arg.Any <string>()) .Returns(new ApiResponse <Provider>(HttpStatusCode.NotFound, provider)); specsClient.GetFundingPeriods() .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods)); resultsApiClient.GetProviderResults(Arg.Is("2"), Arg.Is("2")) .Returns(new ApiResponse <ProviderResults>(HttpStatusCode.OK, providerResults)); resultsApiClient.GetSpecificationIdsForProvider("2") .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary)); specsClient .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>())); // Act Func <Task> test = async() => await provideCalcPageModel.OnGetAsync("2", "1617", "2"); // Assert test .Should() .ThrowExactly <System.InvalidOperationException>().WithMessage("Unable to retreive Provider information: Status Code = NotFound"); }
public async Task OnGetAsync_WhenGettingProviderResponseIsSuccess_PopulatesProviderDetails() { // Arrange IResultsApiClient resultsApiClient = CreateApiClient(); ISpecsApiClient specsClient = CreateSpecsApiClient(); IMapper mapper = CreateMapper(); ILogger logger = CreateLogger(); ProviderAllocationLinePageModel providerAllocPageModel = CreatePageModel(resultsApiClient, specsClient, mapper, logger); IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") }; Provider provider = CreateProvider(); IEnumerable <string> specSummary = GetSpecificationsWithResults(); IList <CalculationResultItem> calResult = GetCalcResults(); IList <AllocationLineResultItem> allocResult = GetAllocationResults(); ProviderResults providerResults = new ProviderResults() { AllocationResults = allocResult, CalculationResults = calResult }; resultsApiClient.GetProviderByProviderId(Arg.Any <string>()) .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider)); specsClient.GetFundingPeriods() .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods)); resultsApiClient.GetProviderResults(Arg.Is("2"), Arg.Is("2")) .Returns(new ApiResponse <ProviderResults>(HttpStatusCode.OK, providerResults)); resultsApiClient.GetSpecificationIdsForProvider("2") .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary)); specsClient .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>())); // Act IActionResult result = await providerAllocPageModel.OnGetAsync("2", "1617", "2"); // Assert providerAllocPageModel.ViewModel.Should().NotBeNull(); providerAllocPageModel.ViewModel.Upin.Should().Be(234234); providerAllocPageModel.ViewModel.Ukprn.Should().Be(345345); providerAllocPageModel.ViewModel.Urn.Should().Be(2234); providerAllocPageModel.ViewModel.ProviderType.Should().Be("Academy"); }
public async Task PopulatePageModel() { ApiResponse <IEnumerable <SpecificationSummary> > apiResponse = await _specsClient.GetSpecificationSummaries(); if (apiResponse.StatusCode != HttpStatusCode.OK && apiResponse.Content == null) { throw new InvalidOperationException($"Unable to retreive Specification information: Status Code = {apiResponse.StatusCode}"); } IEnumerable <SpecificationSummary> trimmedSpecs = await _authorizationHelper.SecurityTrimList(User, apiResponse.Content, SpecificationActionTypes.CanCreateQaTests); IsAuthorizedToCreate = trimmedSpecs.Any(); Specifications = trimmedSpecs.OrderBy(s => s.Name).Select(m => new SelectListItem { Value = m.Id, Text = m.Name }).ToList(); }
public async Task OnGetAsync_WithValidProviderResultsReturned_PopulatesProviderDetails() { // Arrange IResultsApiClient resultsApiClient = CreateApiClient(); ISpecsApiClient specsClient = CreateSpecsApiClient(); ITestScenarioSearchService searchService = CreateTestScenarioSearchService(); ProviderScenarioResultsPageModel providerScenarioResultsPageModel = CreatePageModel(searchService, resultsApiClient, specsApiClient: specsClient); Provider provider = CreateProvider(); IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") }; IEnumerable <string> specSummary = GetSpecificationsWithResults(); specsClient.GetFundingPeriods() .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods)); resultsApiClient.GetSpecificationIdsForProvider("2") .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary)); resultsApiClient.GetProviderByProviderId(Arg.Any <string>()) .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider)); specsClient .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>())); //Act IActionResult actionResult = await providerScenarioResultsPageModel.OnGetAsync("2", 1, "", "1819", "1"); // Assert actionResult .Should() .BeOfType <PageResult>(); providerScenarioResultsPageModel.ProviderInfoModel.Should().NotBeNull(); providerScenarioResultsPageModel.ProviderInfoModel.Upin.Should().Be(234234); providerScenarioResultsPageModel.ProviderInfoModel.Ukprn.Should().Be(345345); providerScenarioResultsPageModel.ProviderInfoModel.Urn.Should().Be(2234); providerScenarioResultsPageModel.ProviderInfoModel.ProviderType.Should().Be("Academy"); }
public void TestScenarioResultsService_PerformSearch_WhenTestScenariosSearchResultsIsNull_ThenExceptionThrown() { // Arrange IScenarioSearchService searchService = CreateScenarioSearchService(); ISpecsApiClient specsApiClient = CreateSpecsApiClient(); ITestEngineApiClient testEngineApiClient = CreateTestEngineApiClient(); ILogger logger = CreateLogger(); string specificationId = "spec1"; TestScenarioResultsService testScenarioResultsService = CreateService(searchService, specsApiClient, testEngineApiClient, logger: logger); TestScenarioResultRequestViewModel resultRequestViewModel = new TestScenarioResultRequestViewModel() { SearchTerm = "", PageNumber = 1, FundingPeriodId = null, SpecificationId = specificationId, }; ScenarioSearchResultViewModel scenarioSearchResultViewModel = null; searchService.PerformSearch(Arg.Is <SearchRequestViewModel>(s => s.SearchTerm == resultRequestViewModel.SearchTerm)) .Returns(scenarioSearchResultViewModel); List <SpecificationSummary> specifications = CreateSpecifications(); specsApiClient .GetSpecificationSummaries() .Returns(new ApiResponse <IEnumerable <SpecificationSummary> >(HttpStatusCode.OK, specifications.AsEnumerable())); // Act Func <Task> action = async() => await testScenarioResultsService.PerformSearch(resultRequestViewModel); // Assert action. Should() .ThrowExactly <InvalidOperationException>() .WithMessage("Scenario Search Results response was null"); logger .Received(1) .Warning(Arg.Is <string>("Scenario Search Results response was null")); }
public async Task TestScenarioResultsService_PerformSearch_WhenGetAllSpecificationsLookupIsNull_ThenExceptionThrown() { // Arrange IScenarioSearchService searchService = CreateScenarioSearchService(); ISpecsApiClient specsApiClient = CreateSpecsApiClient(); ITestEngineApiClient testEngineApiClient = CreateTestEngineApiClient(); ILogger logger = CreateLogger(); TestScenarioResultRequestViewModel resultRequestViewModel = new TestScenarioResultRequestViewModel() { SearchTerm = "", PageNumber = 1, FundingPeriodId = null, SpecificationId = null, }; TestScenarioResultsService testScenarioResultsService = CreateService(searchService, specsApiClient, testEngineApiClient, logger: logger); searchService.PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(new ScenarioSearchResultViewModel()); List <SpecificationSummary> specifications = CreateSpecifications(); specsApiClient .GetSpecificationSummaries() .Returns((ApiResponse <IEnumerable <SpecificationSummary> >)null); // Act Func <Task> action = async() => await testScenarioResultsService.PerformSearch(resultRequestViewModel); // Assert action. Should() .ThrowExactly <InvalidOperationException>() .WithMessage("Specifications API Response was null"); logger .Received(1) .Warning(Arg.Is("Specifications API Response was null")); await specsApiClient .Received(1) .GetSpecificationSummaries(); }
public void TestScenarioResultsService_PerformSearch_WhenGetAllSpecificationsLookupResponseIsNotOk_ThenExceptionThrown() { // Arrange IScenarioSearchService searchService = CreateScenarioSearchService(); ISpecsApiClient specsApiClient = CreateSpecsApiClient(); ITestEngineApiClient testEngineApiClient = CreateTestEngineApiClient(); ILogger logger = CreateLogger(); TestScenarioResultRequestViewModel resultRequestViewModel = new TestScenarioResultRequestViewModel() { SearchTerm = "", PageNumber = 1, FundingPeriodId = null, SpecificationId = null, }; TestScenarioResultsService testScenarioResultsService = CreateService(searchService, specsApiClient, testEngineApiClient, logger: logger); searchService.PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(new ScenarioSearchResultViewModel()); specsApiClient .GetSpecificationSummaries() .Returns(new ApiResponse <IEnumerable <SpecificationSummary> >(HttpStatusCode.InternalServerError, null)); // Act Func <Task> action = async() => await testScenarioResultsService.PerformSearch(resultRequestViewModel); // Assert action. Should() .ThrowExactly <InvalidOperationException>() .WithMessage("Specifications API Response content did not return OK, but instead 'InternalServerError'"); logger .Received(1) .Warning(Arg.Is("Specifications API Response content did not return OK, but instead {specificationsApiResponse.StatusCode}"), Arg.Is(HttpStatusCode.InternalServerError)); }
public async Task OnGetAsync_WithNullProviderResultsReturned_ReturnsStatusCode500() { // Arrange IResultsApiClient resultsApiClient = CreateApiClient(); ISpecsApiClient specsClient = CreateSpecsApiClient(); ITestScenarioSearchService searchService = CreateTestScenarioSearchService(); ProviderScenarioResultsPageModel providerScenarioResultsPageModel = CreatePageModel(searchService, resultsApiClient, specsApiClient: specsClient); Provider provider = null; IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") }; IEnumerable <string> specSummary = GetSpecificationsWithResults(); specsClient.GetFundingPeriods() .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods)); resultsApiClient.GetSpecificationIdsForProvider("2") .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary)); resultsApiClient.GetProviderByProviderId(Arg.Any <string>()) .Returns(new ApiResponse <Provider>(HttpStatusCode.NotFound, provider)); specsClient .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>())); //Act IActionResult actionResult = await providerScenarioResultsPageModel.OnGetAsync("2", 1, "", "1819", "1"); // Assert actionResult .Should() .BeOfType <StatusCodeResult>().Which.StatusCode.Should().Be(500); }
public async Task OnGetAsync_WhenTestScenariosSearchResultsFound_ThenSuccessfullyShown() { // Arrange IResultsApiClient resultsApiClient = CreateApiClient(); ISpecsApiClient specsClient = CreateSpecsApiClient(); ITestScenarioSearchService searchService = CreateTestScenarioSearchService(); Provider provider = CreateProvider(); IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") }; IEnumerable <string> specSummary = GetSpecificationsWithResults(); specsClient.GetFundingPeriods() .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods)); resultsApiClient.GetSpecificationIdsForProvider(Arg.Any <string>()) .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary)); resultsApiClient.GetProviderByProviderId(Arg.Any <string>()) .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider)); specsClient .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>())); IList <TestScenarioSearchResultItemViewModel> testScenarioSearchResultItems = GetTestScenarioSearchResults(); string specificationId = "2"; TestScenarioSearchResultViewModel results = new TestScenarioSearchResultViewModel() { TestScenarios = testScenarioSearchResultItems, TotalResults = 2, CurrentPage = 1, }; SearchRequestViewModel searchRequest = CreateSearchRequest(); searchRequest.Filters["specificationId"][0] = specificationId; searchService.PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(results); ProviderScenarioResultsPageModel providerScenarioResultsPageModel = CreatePageModel(searchService, resultsApiClient, specsApiClient: specsClient); //Act IActionResult actionResult = await providerScenarioResultsPageModel.OnGetAsync("1", 1, "", "1819", specificationId); // Assert actionResult .Should() .BeOfType <PageResult>(); providerScenarioResultsPageModel.TestScenarioSearchResults.Should().NotBeNull(); providerScenarioResultsPageModel.FundingPeriods.Count().Should().Be(3); await searchService.Received(1).PerformSearch(Arg.Is <SearchRequestViewModel>(r => r.PageNumber == searchRequest.PageNumber && r.IncludeFacets == searchRequest.IncludeFacets && r.SearchTerm == searchRequest.SearchTerm && r.Filters["providerId"][0] == searchRequest.Filters["providerId"][0] && r.Filters["specificationId"][0] == searchRequest.Filters["specificationId"][0] )); }
public async Task TestScenarioResultsService_PerformSearch_WhenTestScenariosExist_ThenResultsAreReturned() { // Arrange IScenarioSearchService searchService = CreateScenarioSearchService(); ISpecsApiClient specsApiClient = CreateSpecsApiClient(); ITestEngineApiClient testEngineApiClient = CreateTestEngineApiClient(); TestScenarioResultsService testScenarioResultsService = CreateService(searchService, specsApiClient, testEngineApiClient); TestScenarioResultRequestViewModel resultRequestViewModel = new TestScenarioResultRequestViewModel() { SearchTerm = "", PageNumber = 1, FundingPeriodId = null, SpecificationId = null, }; ScenarioSearchResultViewModel scenarioSearchResultViewModel = new ScenarioSearchResultViewModel() { CurrentPage = 1, TotalResults = 1, StartItemNumber = 1, EndItemNumber = 1, Scenarios = new List <ScenarioSearchResultItemViewModel>() { new ScenarioSearchResultItemViewModel() { Id = "ts1", Name = "Test Scenario 1", FundingPeriodName = "2018/2019", Status = "Passed", SpecificationName = "Specifcation 1", LastUpdatedDate = new DateTime(2018, 1, 5, 7, 8, 9), } } }; searchService.PerformSearch(Arg.Is <SearchRequestViewModel>(s => s.SearchTerm == resultRequestViewModel.SearchTerm)) .Returns(scenarioSearchResultViewModel); List <SpecificationSummary> specifications = CreateSpecifications(); specsApiClient .GetSpecificationSummaries() .Returns(new ApiResponse <IEnumerable <SpecificationSummary> >(HttpStatusCode.OK, specifications.AsEnumerable())); List <TestScenarioResultCounts> testScenarioResultCounts = new List <TestScenarioResultCounts>(); testScenarioResultCounts.Add(new TestScenarioResultCounts() { Passed = 5, Failed = 10, Ignored = 50, LastUpdatedDate = new DateTime(2018, 10, 5, 7, 8, 9), TestScenarioId = "ts1", TestScenarioName = "Test Scenario 1", }); testEngineApiClient .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>()) .Returns(new ApiResponse <IEnumerable <TestScenarioResultCounts> >(HttpStatusCode.OK, testScenarioResultCounts)); // Act TestScenarioResultViewModel resultViewModel = await testScenarioResultsService.PerformSearch(resultRequestViewModel); // Assert resultViewModel.Should().NotBeNull(); TestScenarioResultViewModel expectedResult = new TestScenarioResultViewModel() { CurrentPage = 1, EndItemNumber = 1, Facets = new List <SearchFacetViewModel>(), FundingPeriodId = null, Specifications = new List <ReferenceViewModel>() { new ReferenceViewModel("spec1", "Specification 1"), new ReferenceViewModel("spec2", "Specification 2"), new ReferenceViewModel("spec3", "Specification for 2018/2019"), }, StartItemNumber = 1, TotalResults = 1, TestResults = new List <TestScenarioResultItemViewModel>() { new TestScenarioResultItemViewModel() { Id = "ts1", Name = "Test Scenario 1", Passes = 5, Failures = 10, Ignored = 50, LastUpdatedDate = new DateTime(2018, 1, 5, 7, 8, 9), } } }; resultViewModel.Should().BeEquivalentTo(expectedResult); await specsApiClient .Received(1) .GetSpecificationSummaries(); }
private async Task PopulateSpecifications(string providerId, string specificationId = null) { ApiResponse <IEnumerable <string> > specResponse = await _resultsApiClient.GetSpecificationIdsForProvider(providerId); if (specResponse.Content != null && specResponse.StatusCode == HttpStatusCode.OK) { IEnumerable <string> specificationIds = specResponse.Content; if (string.IsNullOrWhiteSpace(specificationId)) { specificationId = SpecificationId; } Dictionary <string, Clients.SpecsClient.Models.SpecificationSummary> specificationSummaries = new Dictionary <string, Clients.SpecsClient.Models.SpecificationSummary>(); if (specificationIds.Any()) { ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> > specificationSummaryLookup = await _specsApiClient.GetSpecificationSummaries(specificationIds); if (specificationSummaryLookup == null) { throw new InvalidOperationException("Specification Summary Lookup returned null"); } if (specificationSummaryLookup.StatusCode != HttpStatusCode.OK) { throw new InvalidOperationException($"Specification Summary lookup returned HTTP Status code {specificationSummaryLookup.StatusCode}"); } if (!specificationSummaryLookup.Content.IsNullOrEmpty()) { foreach (Clients.SpecsClient.Models.SpecificationSummary specSummary in specificationSummaryLookup.Content) { specificationSummaries.Add(specSummary.Id, specSummary); } } } List <SelectListItem> selectListItems = new List <SelectListItem>(); foreach (string specId in specificationIds) { string specName = specId; if (specificationSummaries.ContainsKey(specId)) { if (specificationSummaries[specId].FundingPeriod.Id != FundingPeriodId) { continue; } specName = specificationSummaries[specId].Name; } else { continue; } selectListItems.Add(new SelectListItem { Value = specId, Text = specName, Selected = specId == specificationId }); } Specifications = selectListItems.OrderBy(o => o.Text); } else { throw new InvalidOperationException($"Unable to retrieve provider result Specifications: Status Code = {specResponse.StatusCode}"); } }
public async Task OnGetAsync_WhenTestScenariosSearchResultsFoundThenTestCoverageIsCalculated_ThenSuccessfullyShown() { // Arrange IResultsApiClient resultsApiClient = CreateApiClient(); ISpecsApiClient specsClient = CreateSpecsApiClient(); ITestScenarioSearchService searchService = CreateTestScenarioSearchService(); Provider provider = CreateProvider(); IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") }; IEnumerable <string> specSummary = GetSpecificationsWithResults(); specsClient.GetFundingPeriods() .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods)); resultsApiClient.GetSpecificationIdsForProvider(Arg.Any <string>()) .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary)); resultsApiClient.GetProviderByProviderId(Arg.Any <string>()) .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider)); IList <TestScenarioSearchResultItemViewModel> testScenarioSearchResultItems = GetTestScenarioSearchResults(); TestScenarioSearchResultItemViewModel ignoredItem = new TestScenarioSearchResultItemViewModel() { Id = "3", LastUpdatedDate = new DateTime(12, 01, 23), ProviderId = "1", ProviderName = "Provider 1", SpecificationId = "2", SpecificationName = "Spec 02", TestResult = "Ignored", TestScenarioId = "2", TestScenarioName = "Test Scenario 02", LastUpdatedDateDisplay = "1", }; testScenarioSearchResultItems.Add(ignoredItem); TestScenarioSearchResultItemViewModel failedItem = new TestScenarioSearchResultItemViewModel() { Id = "4", LastUpdatedDate = new DateTime(12, 01, 23), ProviderId = "1", ProviderName = "Provider 1", SpecificationId = "2", SpecificationName = "Spec 02", TestResult = "Failed", TestScenarioId = "2", TestScenarioName = "Test Scenario 02", LastUpdatedDateDisplay = "1", }; testScenarioSearchResultItems.Add(failedItem); string specificationId = "2"; TestScenarioSearchResultViewModel results = new TestScenarioSearchResultViewModel() { TestScenarios = testScenarioSearchResultItems, TotalResults = 4, CurrentPage = 1, }; SearchRequestViewModel searchRequest = CreateSearchRequest(); searchRequest.Filters["specificationId"][0] = specificationId; searchService.PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(results); specsClient .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>())); ProviderScenarioResultsPageModel providerScenarioResultsPageModel = CreatePageModel(searchService, resultsApiClient, specsApiClient: specsClient); //Act IActionResult actionResult = await providerScenarioResultsPageModel.OnGetAsync("1", 1, "", "1819", specificationId); // Assert actionResult .Should() .BeOfType <PageResult>(); providerScenarioResultsPageModel.Passed.Should().Be(2); providerScenarioResultsPageModel.Failed.Should().Be(1); providerScenarioResultsPageModel.Ignored.Should().Be(1); providerScenarioResultsPageModel.TestCoverage.Should().Be(75); }
public async Task OnGetAsync_GivenCalculationFoundWithEmptySearchResults_ReturnsPage() { //Arrange const string calculationId = "calc-id"; const string specificationId = "spec-id"; Calculation calculation = new Calculation { Id = calculationId, SpecificationId = specificationId }; CalculationViewModel calculationViewModel = new CalculationViewModel { Id = calculationId, SpecificationId = specificationId }; IEnumerable <DatasetSchemasAssigned> datasetSchemasAssignedList = new[] { new DatasetSchemasAssigned { IsSetAsProviderData = true } }; ApiResponse <IEnumerable <DatasetSchemasAssigned> > datasetSchemaResponse = new ApiResponse <IEnumerable <DatasetSchemasAssigned> >(HttpStatusCode.OK, datasetSchemasAssignedList); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); datasetsApiClient .GetAssignedDatasetSchemasForSpecification(Arg.Is(specificationId)) .Returns(datasetSchemaResponse); CalculationProviderResultSearchResultViewModel calculationProviderResultSearchResultViewModel = new CalculationProviderResultSearchResultViewModel { CalculationProviderResults = Enumerable.Empty <CalculationProviderResultSearchResultItemViewModel>() }; ApiResponse <Calculation> CalculationResponse = new ApiResponse <Calculation>(HttpStatusCode.OK, calculation); ICalculationsApiClient calculationsApiClient = CreateCalculationsApiClient(); calculationsApiClient .GetCalculationById(Arg.Is(calculationId)) .Returns(CalculationResponse); IMapper mapper = CreateMapper(); mapper .Map <CalculationViewModel>(Arg.Is(calculation)) .Returns(calculationViewModel); ICalculationProviderResultsSearchService calculationProviderResultsSearchService = CreateResultsSearchService(); calculationProviderResultsSearchService .PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(calculationProviderResultSearchResultViewModel); ISpecsApiClient specsApiClient = CreateSpecsApiClient(); specsApiClient.GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, Enumerable.Empty <Clients.SpecsClient.Models.SpecificationSummary>())); Clients.SpecsClient.Models.SpecificationSummary specificationSummary = new Clients.SpecsClient.Models.SpecificationSummary() { Id = specificationId, }; specsApiClient .GetSpecificationSummary(Arg.Is(specificationId)) .Returns(new ApiResponse <Clients.SpecsClient.Models.SpecificationSummary>(HttpStatusCode.OK, specificationSummary)); CalculationProviderResultsPageModel pageModel = CreatePageModel( calculationProviderResultsSearchService, calculationsApiClient, mapper: mapper, datasetsApiClient: datasetsApiClient, specsApiClient: specsApiClient); //Act IActionResult result = await pageModel.OnGetAsync(calculationId, null, ""); //Assert result .Should() .BeOfType <PageResult>(); pageModel .CalculationProviderResults .CalculationProviderResults .Any() .Should() .BeFalse(); }
public async Task OnPostAsync_GivenCalculationFoundButGettingAssignedSchemasForSpecRetunsOKWithNullContent_ReturnsStatusCode500() { const string calculationId = "calc-id"; const string specificationId = "spec-id"; Calculation calculation = new Calculation { Id = calculationId, SpecificationId = specificationId }; CalculationViewModel calculationViewModel = new CalculationViewModel { Id = calculationId, SpecificationId = specificationId }; ApiResponse <Calculation> CalculationResponse = new ApiResponse <Calculation>(HttpStatusCode.OK, calculation); ICalculationsApiClient calculationsApiClient = CreateCalculationsApiClient(); calculationsApiClient .GetCalculationById(Arg.Is(calculationId)) .Returns(CalculationResponse); IMapper mapper = CreateMapper(); mapper .Map <CalculationViewModel>(Arg.Is(calculation)) .Returns(calculationViewModel); ICalculationProviderResultsSearchService calculationProviderResultsSearchService = CreateResultsSearchService(); IEnumerable <DatasetSchemasAssigned> datasetSchemasAssignedList = new[] { new DatasetSchemasAssigned { IsSetAsProviderData = true } }; ApiResponse <IEnumerable <DatasetSchemasAssigned> > datasetSchemaResponse = new ApiResponse <IEnumerable <DatasetSchemasAssigned> >(HttpStatusCode.OK); IDatasetsApiClient datasetsApiClient = CreateDatasetsApiClient(); datasetsApiClient .GetAssignedDatasetSchemasForSpecification(Arg.Is(specificationId)) .Returns(datasetSchemaResponse); ISpecsApiClient specsApiClient = CreateSpecsApiClient(); specsApiClient.GetSpecificationSummaries(Arg.Any <IEnumerable <string> >()) .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, Enumerable.Empty <Clients.SpecsClient.Models.SpecificationSummary>())); Clients.SpecsClient.Models.SpecificationSummary specificationSummary = new Clients.SpecsClient.Models.SpecificationSummary() { Id = specificationId, }; specsApiClient .GetSpecificationSummary(Arg.Is(specificationId)) .Returns(new ApiResponse <Clients.SpecsClient.Models.SpecificationSummary>(HttpStatusCode.OK, specificationSummary)); CalculationProviderResultsPageModel pageModel = CreatePageModel( calculationProviderResultsSearchService, calculationsApiClient, mapper: mapper, datasetsApiClient: datasetsApiClient, specsApiClient: specsApiClient); //Act IActionResult result = await pageModel.OnPostAsync(calculationId, null, ""); //Assert result .Should() .BeOfType <StatusCodeResult>(); StatusCodeResult statusCodeResult = result as StatusCodeResult; statusCodeResult .StatusCode .Should() .Be(500); }
public async Task <TestScenarioResultViewModel> PerformSearch(TestScenarioResultRequestViewModel request) { Guard.ArgumentNotNull(request, nameof(request)); SearchRequestViewModel searchRequest = new SearchRequestViewModel() { IncludeFacets = false, SearchTerm = request.SearchTerm, Filters = request.Filters, PageNumber = request.PageNumber, PageSize = 20, SearchMode = _featureToggle.IsSearchModeAllEnabled() ? SearchMode.All : SearchMode.Any }; if (searchRequest.Filters == null) { searchRequest.Filters = new Dictionary <string, string[]>(); } SetFilterValue(searchRequest, "specificationId", request.SpecificationId); SetFilterValue(searchRequest, "fundingPeriodId", request.FundingPeriodId); Task <ScenarioSearchResultViewModel> scenarioSearchResultsTask = _scenariosSearchService.PerformSearch(searchRequest); Task <ApiResponse <IEnumerable <SpecificationSummary> > > specificationsLookupTask; if (string.IsNullOrWhiteSpace(request.FundingPeriodId)) { specificationsLookupTask = _specsClient.GetSpecificationSummaries(); } else { specificationsLookupTask = _specsClient.GetSpecifications(request.FundingPeriodId); } await TaskHelper.WhenAllAndThrow(scenarioSearchResultsTask, specificationsLookupTask); ScenarioSearchResultViewModel scenarioSearchResults = scenarioSearchResultsTask.Result; if (scenarioSearchResults == null) { _logger.Warning("Scenario Search Results response was null"); throw new InvalidOperationException("Scenario Search Results response was null"); } ApiResponse <IEnumerable <SpecificationSummary> > specificationsApiResponse = specificationsLookupTask.Result; if (specificationsApiResponse == null) { _logger.Warning("Specifications API Response was null"); throw new InvalidOperationException("Specifications API Response was null"); } if (specificationsApiResponse.StatusCode != System.Net.HttpStatusCode.OK) { _logger.Warning("Specifications API Response content did not return OK, but instead {specificationsApiResponse.StatusCode}", specificationsApiResponse.StatusCode); throw new InvalidOperationException($"Specifications API Response content did not return OK, but instead '{specificationsApiResponse.StatusCode}'"); } if (specificationsApiResponse.Content == null) { _logger.Warning("Specifications API Response content was null"); throw new InvalidOperationException("Specifications API Response content was null"); } IEnumerable <string> testScenarioIds = scenarioSearchResults.Scenarios.Select(s => s.Id); TestScenarioResultViewModel result = _mapper.Map <TestScenarioResultViewModel>(scenarioSearchResults); List <ReferenceViewModel> specifications = new List <ReferenceViewModel>(); foreach (SpecificationSummary specification in specificationsApiResponse.Content.OrderBy(s => s.Name)) { specifications.Add(new ReferenceViewModel(specification.Id, specification.Name)); } result.Specifications = specifications; if (testScenarioIds.Any()) { ApiResponse <IEnumerable <TestScenarioResultCounts> > rowCounts = await _testEngineClient.GetTestResultCounts(new TestScenarioResultCountsRequestModel() { TestScenarioIds = testScenarioIds, }); if (rowCounts == null) { _logger.Warning("Row counts api request failed with null response"); throw new InvalidOperationException($"Row counts api request failed with null response"); } if (rowCounts.StatusCode != System.Net.HttpStatusCode.OK) { _logger.Warning("Row counts api request failed with status code: {rowCounts.StatusCode}", rowCounts.StatusCode); throw new InvalidOperationException($"Row counts api request failed with status code: {rowCounts.StatusCode}"); } if (rowCounts.Content == null) { _logger.Warning("Row counts api request failed with null content"); throw new InvalidOperationException($"Row counts api request failed with null content"); } foreach (TestScenarioResultItemViewModel vm in result.TestResults) { TestScenarioResultCounts counts = rowCounts.Content.Where(r => r.TestScenarioId == vm.Id).FirstOrDefault(); if (counts != null) { vm.Failures = counts.Failed; vm.Passes = counts.Passed; vm.Ignored = counts.Ignored; } } } return(result); }