public async Task <IActionResult> SearchCalculationProviderResults([FromBody] SearchRequestViewModel request, [FromQuery] string calculationValueType = null) { Guard.ArgumentNotNull(request, nameof(request)); CalculationProviderResultSearchResultViewModel searchResults = await _calculationProviderResultsSearchService.PerformSearch(request); if (calculationValueType != null) { CalculationValueTypeViewModel valueType = calculationValueType.AsEnum <CalculationValueTypeViewModel>(); foreach (CalculationProviderResultSearchResultItemViewModel providerResult in searchResults.CalculationProviderResults) { providerResult.SetCalculationResultDisplay(valueType); } } CalculationProviderResultSearchResultViewModel result = searchResults; if (result != null) { return(Ok(result)); } return(new InternalServerErrorResult($"Find provider results HTTP request failed")); }
public async Task SearchCalculationProviderResults_GivenNullResultsReturnedFromSearch_ReturnsStatusCode500() { // Arrange SearchRequestViewModel requestModel = new SearchRequestViewModel(); ICalculationProviderResultsSearchService searchService = CreateCalculationProviderResultsSearchService(); searchService .PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns((CalculationProviderResultSearchResultViewModel)null); ProviderSearchController controller = CreateController(calculationProviderResultsSearchService: searchService); // Act IActionResult actionResult = await controller.SearchCalculationProviderResults(requestModel); // Asserts actionResult .Should() .BeOfType <StatusCodeResult>(); StatusCodeResult statusCodeResult = actionResult as StatusCodeResult; statusCodeResult .StatusCode .Should() .Be(500); }
private async Task PerformSearch(string calculationId, int?pageNumber, string searchTerm) { SearchRequestViewModel searchRequest = new SearchRequestViewModel() { PageNumber = pageNumber ?? 1, IncludeFacets = false, SearchTerm = searchTerm, Filters = new Dictionary <string, string[]> { { "calculationId", new[] { calculationId } } } }; CalculationProviderResults = await _resultsSearchService.PerformSearch(searchRequest); }
public async Task <IActionResult> SearchCalculationProviderResults([FromBody] SearchRequestViewModel request) { Guard.ArgumentNotNull(request, nameof(request)); CalculationProviderResultSearchResultViewModel result = await _calculationProviderResultsSearchService.PerformSearch(request); if (result != null) { return(Ok(result)); } else { return(new StatusCodeResult(500)); } }
public async Task SearchCalculationProviderResults_GivenResultsReturnedFromSearch_ReturnsOK() { // Arrange SearchRequestViewModel requestModel = new SearchRequestViewModel(); CalculationProviderResultSearchResultViewModel results = new CalculationProviderResultSearchResultViewModel(); ICalculationProviderResultsSearchService searchService = CreateCalculationProviderResultsSearchService(); searchService .PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(results); ProviderSearchController controller = CreateController(calculationProviderResultsSearchService: searchService); // Act IActionResult actionResult = await controller.SearchCalculationProviderResults(requestModel); // Asserts actionResult .Should() .BeOfType <OkObjectResult>(); }
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(); }