public void GetAllSpecifications_Returns_BadRequestObjectResult_WithInValidCall_MissingVariable() { var data = new SpecificationSearchRequestViewModel() { SearchText = null, FundingPeriods = null, FundingStreams = null, Status = null }; _mockSpecificationsApiClient.Setup(x => x.FindSpecifications(null)).ReturnsAsync(Builder <PagedResult <SpecificationSearchResultItem> > .CreateNew().Build); _sut = new SpecificationController(_mockSpecificationsApiClient.Object, _mockAuthorizationHelper.Object); var actual = _sut.GetAllSpecifications(data); actual.Result.Should().BeOfType <BadRequestResult>(); }
public async Task <IActionResult> GetAllSpecifications([FromQuery] SpecificationSearchRequestViewModel viewModel) { var searchFilterRequest = new SearchFilterRequest { Filters = new Dictionary <string, string[]>(), ErrorToggle = false, SearchMode = SearchMode.All, FacetCount = 0, PageSize = viewModel.PageSize, Page = viewModel.Page, IncludeFacets = true, SearchFields = new List <string>(), SearchTerm = "" }; if (viewModel.Status?.Length > 0) { searchFilterRequest.Filters.Add("status", viewModel.Status.ToArray()); } if (viewModel.FundingPeriods?.Length > 0) { searchFilterRequest.Filters.Add("fundingPeriodName", viewModel.FundingPeriods.ToArray()); } if (viewModel.FundingStreams?.Length > 0) { searchFilterRequest.Filters.Add("fundingStreamNames", viewModel.FundingStreams.ToArray()); } if (!string.IsNullOrEmpty(viewModel.SearchText)) { searchFilterRequest.SearchTerm = viewModel.SearchText; } PagedResult <SpecificationSearchResultItem> result = await _specificationsApiClient.FindSpecifications(searchFilterRequest); if (result != null) { int totalPages = result.Items.Count() / viewModel.PageSize; if (result.Items.Count() % viewModel.PageSize > 0) { totalPages++; } int startNumber = ((viewModel.PageSize * viewModel.Page) - viewModel.PageSize) + 1; int endNumber = (viewModel.PageSize * viewModel.Page); if (endNumber > result.TotalItems) { endNumber = result.TotalItems; } PagedSpecficationSearchResults searchPagedResult = new PagedSpecficationSearchResults { Items = result.Items, TotalCount = result.TotalItems, PagerState = new PagerState(viewModel.Page, result.TotalPages), StartItemNumber = startNumber, EndItemNumber = endNumber, Facets = result.Facets }; return(Ok(searchPagedResult)); } return(new BadRequestResult()); }