public async Task OnGetAsync_GivenDatasetPageModelSearchTermRequested_ReturnsPageResult() { //Arrange IDatasetSearchService searchService = CreateSearchService(); const string searchTerm = "testTerm"; DatasetSearchResultViewModel searchResult = new DatasetSearchResultViewModel() { CurrentPage = 2, EndItemNumber = 0, Facets = new List <SearchFacetViewModel>(), PagerState = new PagerState(1, 1), Datasets = new List <DatasetSearchResultItemViewModel>(), StartItemNumber = 1, TotalResults = 0 }; searchService .PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(searchResult); ManageDatasetsPageModel DatasetModel = CreateDatasetPageModel(searchService); //Act IActionResult result = await DatasetModel.OnGetAsync(2, searchTerm); //Assert result .Should() .BeOfType <PageResult>() .Which .Should() .NotBeNull(); await searchService .Received(1) .PerformSearch(Arg.Is <SearchRequestViewModel>( c => c.PageNumber == 2 && c.SearchTerm == searchTerm)); }
public async Task OnGetAsync_GivenDatasetPerformSearchReturnsNullResults_ThenErrorReturned() { //Arrange IDatasetSearchService searchService = CreateSearchService(); DatasetSearchResultViewModel searchResult = null; searchService .PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(searchResult); ManageDatasetsPageModel DatasetModel = CreateDatasetPageModel(searchService); //Act IActionResult result = await DatasetModel.OnGetAsync(null, null); //Assert result .Should() .BeOfType <InternalServerErrorResult>(); InternalServerErrorResult statusCodeResult = result as InternalServerErrorResult; statusCodeResult .StatusCode .Should() .Be(500); statusCodeResult .Value .Should() .Equals("There was an error retrieving data sources from the Search Index."); await searchService .Received(1) .PerformSearch(Arg.Is <SearchRequestViewModel>( c => c.PageNumber == null && c.SearchTerm == null)); }
public async Task OnGetAsync_GivenDatasetPageModelPerformSearchReturnsResults_ReturnsPageResult() { //Arrange IDatasetSearchService searchService = CreateSearchService(); DatasetSearchResultViewModel searchResult = new DatasetSearchResultViewModel() { CurrentPage = 1, EndItemNumber = 0, Facets = new List <SearchFacetViewModel>(), PagerState = new PagerState(1, 1), Datasets = new List <DatasetSearchResultItemViewModel>() { new DatasetSearchResultItemViewModel() { Id = "Search1", Name = "Search One", Description = "Description", LastUpdated = new DateTime(2018, 3, 5, 12, 34, 52), Status = "Draft" } }, StartItemNumber = 1, TotalResults = 0 }; searchService .PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(searchResult); ManageDatasetsPageModel DatasetModel = CreateDatasetPageModel(searchService); //Act IActionResult result = await DatasetModel.OnGetAsync(null, null); //Assert result .Should() .BeOfType <PageResult>() .Which .Should() .NotBeNull(); DatasetModel .SearchResults .Should() .BeEquivalentTo(new DatasetSearchResultViewModel() { CurrentPage = 1, EndItemNumber = 0, Facets = new List <SearchFacetViewModel>(), PagerState = new PagerState(1, 1), Datasets = new List <DatasetSearchResultItemViewModel>() { new DatasetSearchResultItemViewModel() { Id = "Search1", Name = "Search One", Description = "Description", LastUpdated = new DateTime(2018, 3, 5, 12, 34, 52), Status = "Draft" } }, StartItemNumber = 1, TotalResults = 0 }); await searchService .Received(1) .PerformSearch(Arg.Is <SearchRequestViewModel>( c => c.PageNumber == null && c.SearchTerm == null)); }