public async Task OnGetAsync_GivenCountTaskReturnsNoItems_ThenCoverageIsSetCorrectly() { //Arrange ApiResponse <TestScenario> scenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario()); IScenariosApiClient apiClient = CreateScenariosClient(); apiClient .GetCurrentTestScenarioById(Arg.Is(Scenarioid)) .Returns(scenario); ProviderTestsSearchResultViewModel viewModel = new ProviderTestsSearchResultViewModel(); ITestResultsSearchService resultsService = CreateResultsService(); resultsService .PerformProviderTestResultsSearch(Arg.Any <SearchRequestViewModel>()) .Returns(viewModel); ITestEngineApiClient testEngineApiClient = CreateTestEngineClient(); testEngineApiClient .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>()) .Returns(new ApiResponse <IEnumerable <TestScenarioResultCounts> >(HttpStatusCode.OK, Enumerable.Empty <TestScenarioResultCounts>())); ISpecsApiClient specsApiClient = CreateSpecsClient(); specsApiClient .GetSpecificationSummary(Arg.Any <string>()) .Returns(new ApiResponse <Clients.SpecsClient.Models.SpecificationSummary>(HttpStatusCode.OK, new Clients.SpecsClient.Models.SpecificationSummary())); ViewProviderTestResultsPageModel pageModel = CreatePageModel( resultsService, testEngineApiClient, scenariosApiClient: apiClient, specsApiClient: specsApiClient); //Act IActionResult result = await pageModel.OnGetAsync(Scenarioid, null, ""); //Assert result .Should() .BeOfType <PageResult>() .Which .Should() .NotBeNull(); await testEngineApiClient .Received(1) .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>()); pageModel .TestCoverage .Should() .Be(0); }
public async Task <IActionResult> SearchProviders([FromBody] SearchRequestViewModel request) { Guard.ArgumentNotNull(request, nameof(request)); ProviderTestsSearchResultViewModel result = await _testResultsSearchService.PerformProviderTestResultsSearch(request); if (result != null) { return(Ok(result)); } else { return(new StatusCodeResult(500)); } }
public async Task OnGetAsync_GivenResultsReturned_ReturnsPage() { //Arrange ApiResponse <TestScenario> scenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario()); IScenariosApiClient scenariosClient = CreateScenariosClient(); scenariosClient .GetCurrentTestScenarioById(Arg.Is(Scenarioid)) .Returns(scenario); TestScenarioViewModel scenarioViewModel = new TestScenarioViewModel(); ProviderTestsSearchResultViewModel viewModel = new ProviderTestsSearchResultViewModel(); ITestResultsSearchService resultsService = CreateResultsService(); resultsService .PerformProviderTestResultsSearch(Arg.Any <SearchRequestViewModel>()) .Returns(viewModel); ITestEngineApiClient testEngineClient = CreateTestEngineClient(); List <TestScenarioResultCounts> countResults = new List <TestScenarioResultCounts>(); testEngineClient .GetTestResultCounts(Arg.Is <TestScenarioResultCountsRequestModel>(c => c.TestScenarioIds.Count() == 1 && c.TestScenarioIds.First() == Scenarioid)) .Returns(new ApiResponse <IEnumerable <TestScenarioResultCounts> >(HttpStatusCode.OK, countResults)); ISpecsApiClient specsApiClient = CreateSpecsClient(); specsApiClient .GetSpecificationSummary(Arg.Any <string>()) .Returns(new ApiResponse <Clients.SpecsClient.Models.SpecificationSummary>(HttpStatusCode.OK, new Clients.SpecsClient.Models.SpecificationSummary())); ViewProviderTestResultsPageModel pageModel = CreatePageModel(resultsService, testEngineClient, scenariosClient, specsApiClient: specsApiClient); //Act IActionResult result = await pageModel.OnGetAsync(Scenarioid, null, ""); //Assert result .Should() .BeAssignableTo <PageResult>(); }
public async Task OnGetAsync_GivenCountTaskReturnsNullContent_ThenErrorIsReturned() { //Arrange ApiResponse <TestScenario> scenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario()); IScenariosApiClient apiClient = CreateScenariosClient(); apiClient .GetCurrentTestScenarioById(Arg.Is(Scenarioid)) .Returns(scenario); ProviderTestsSearchResultViewModel viewModel = new ProviderTestsSearchResultViewModel(); ITestResultsSearchService resultsService = CreateResultsService(); resultsService .PerformProviderTestResultsSearch(Arg.Any <SearchRequestViewModel>()) .Returns(viewModel); ITestEngineApiClient testEngineApiClient = CreateTestEngineClient(); testEngineApiClient .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>()) .Returns(new ApiResponse <IEnumerable <TestScenarioResultCounts> >(HttpStatusCode.OK, null)); ViewProviderTestResultsPageModel pageModel = CreatePageModel(resultsService, testEngineApiClient, scenariosApiClient: apiClient); //Act IActionResult result = await pageModel.OnGetAsync(Scenarioid, null, ""); //Assert result .Should() .BeOfType <InternalServerErrorResult>() .Which .Value .Should() .Be("Count Task result content was null"); await testEngineApiClient .Received(1) .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>()); }
public async Task SearchProvider_GivenNResultReturnedFromSearch_ReturnsOKResult() { //Arrange SearchRequestViewModel requestModel = new SearchRequestViewModel(); ProviderTestsSearchResultViewModel viewModel = new ProviderTestsSearchResultViewModel(); ITestResultsSearchService resultsSearchService = CreateResultsSearchService(); resultsSearchService .PerformProviderTestResultsSearch(Arg.Is(requestModel)) .Returns(viewModel); TestEngineController testEngineController = CreateController(testResultsSearchService: resultsSearchService); //Act IActionResult result = await testEngineController.SearchProviders(requestModel); //Assert result .Should() .BeAssignableTo <OkObjectResult>(); }
public async Task <ProviderTestsSearchResultViewModel> PerformProviderTestResultsSearch(SearchRequestViewModel request) { SearchFilterRequest requestOptions = new SearchFilterRequest() { Page = request.PageNumber.HasValue ? request.PageNumber.Value : 1, PageSize = request.PageSize.HasValue ? request.PageSize.Value : 50, SearchTerm = request.SearchTerm, IncludeFacets = true, Filters = request.Filters, SearchFields = new[] { "providerName" } }; if (request.PageNumber.HasValue && request.PageNumber.Value > 0) { requestOptions.Page = request.PageNumber.Value; } PagedResult <ProviderTestSearchResultItem> ScenariosResult = await _testsApiClient.FindTestResults(requestOptions); if (ScenariosResult == null) { _logger.Error("Find test results HTTP request failed"); return(null); } ProviderTestsSearchResultViewModel results = new ProviderTestsSearchResultViewModel { TotalResults = ScenariosResult.TotalItems, CurrentPage = ScenariosResult.PageNumber }; IList <SearchFacetViewModel> searchFacets = new List <SearchFacetViewModel>(); if (ScenariosResult.Facets != null) { foreach (SearchFacet facet in ScenariosResult.Facets) { searchFacets.Add(_mapper.Map <SearchFacetViewModel>(facet)); } } results.Facets = searchFacets.AsEnumerable(); List <ProviderTestSearchResultItemViewModel> itemResults = new List <ProviderTestSearchResultItemViewModel>(); foreach (ProviderTestSearchResultItem searchResult in ScenariosResult.Items) { itemResults.Add(_mapper.Map <ProviderTestSearchResultItemViewModel>(searchResult)); } results.Providers = itemResults.AsEnumerable(); if (results.TotalResults == 0) { results.StartItemNumber = 0; results.EndItemNumber = 0; } else { results.StartItemNumber = ((requestOptions.Page - 1) * requestOptions.PageSize) + 1; results.EndItemNumber = results.StartItemNumber + requestOptions.PageSize - 1; } if (results.EndItemNumber > ScenariosResult.TotalItems) { results.EndItemNumber = ScenariosResult.TotalItems; } results.PagerState = new PagerState(requestOptions.Page, ScenariosResult.TotalPages, 4); return(results); }