Beispiel #1
0
        public async Task PerformSearchDatasetVersion_GivenClientReturnsResult_ShouldReturnCorrectlyMappedResult()
        {
            // Arrange
            IDatasetsApiClient mockDatasetsApiClient = Substitute.For <IDatasetsApiClient>();
            ILogger            mockLogger            = Substitute.For <ILogger>();
            IMapper            mockMapper            = MappingHelper.CreateFrontEndMapper();
            IFeatureToggle     featureToggle         = CreateFeatureToggle();

            IDatasetSearchService datasetSearchService = new DatasetSearchService(mockDatasetsApiClient, mockMapper, mockLogger, featureToggle);

            PagedResult <DatasetVersionSearchResultModel> itemResult = GeneratedPagedResultsDatasetVersionSearchResultModel(50);

            itemResult.PageNumber = 2;
            itemResult.PageSize   = 50;
            itemResult.TotalItems = 175;

            mockDatasetsApiClient
            .FindDatasetsVersions(Arg.Any <SearchFilterRequest>())
            .Returns(itemResult);

            // Act
            DatasetVersionSearchResultViewModel datasetVersionSearchResultViewModel = await datasetSearchService.PerformSearchDatasetVersion(new SearchRequestViewModel());

            // Assert
            datasetVersionSearchResultViewModel.Should().NotBeNull();
            datasetVersionSearchResultViewModel.Results.Count().Should().Be(50);
            datasetVersionSearchResultViewModel.TotalResults.Should().Be(175);
            datasetVersionSearchResultViewModel.CurrentPage.Should().Be(2);
            datasetVersionSearchResultViewModel.PageSize.Should().Be(50);
        }
Beispiel #2
0
        public async Task PerformSearchDatasetVersion_GivenClientReturnsEmptyResult_ShouldReturnCorrectlyMappedResult()
        {
            // Arrange
            IDatasetsApiClient mockDatasetsApiClient = Substitute.For <IDatasetsApiClient>();
            ILogger            mockLogger            = Substitute.For <ILogger>();
            IMapper            mockMapper            = MappingHelper.CreateFrontEndMapper();
            IFeatureToggle     featureToggle         = CreateFeatureToggle();

            IDatasetSearchService datasetSearchService = new DatasetSearchService(mockDatasetsApiClient, mockMapper, mockLogger, featureToggle);

            mockDatasetsApiClient
            .FindDatasetsVersions(Arg.Any <SearchFilterRequest>())
            .Returns((PagedResult <DatasetVersionSearchResultModel>)null);

            // Act
            DatasetVersionSearchResultViewModel datasetVersionSearchResultViewModel = await datasetSearchService.PerformSearchDatasetVersion(new SearchRequestViewModel());

            // Assert
            datasetVersionSearchResultViewModel.Should().BeNull();
        }
Beispiel #3
0
        public async Task <DatasetVersionSearchResultViewModel> PerformSearchDatasetVersion(SearchRequestViewModel searchRequest)
        {
            SearchFilterRequest requestOptions = new SearchFilterRequest()
            {
                Page          = searchRequest.PageNumber ?? 1,
                PageSize      = searchRequest.PageSize ?? 20,
                SearchTerm    = searchRequest.SearchTerm,
                IncludeFacets = searchRequest.IncludeFacets,
                Filters       = searchRequest.Filters,
                SearchMode    = _featureToggle.IsSearchModeAllEnabled() ? SearchMode.All : SearchMode.Any
            };

            PagedResult <DatasetVersionSearchResultModel> pagedResult = await _datasetsClient.FindDatasetsVersions(requestOptions);

            if (pagedResult == null)
            {
                return(null);
            }

            DatasetVersionSearchResultViewModel datasetVersionSearchResultViewModel =
                new DatasetVersionSearchResultViewModel(pagedResult.Items, pagedResult.TotalItems, pagedResult.PageNumber, pagedResult.TotalPages, pagedResult.PageSize);

            return(datasetVersionSearchResultViewModel);
        }