Beispiel #1
0
        public async Task OnGetAsync_GivenSearchReturnsNull_ShouldReturnInternalServerError()
        {
            // Arrange
            const int              pageSize              = 20;
            const string           datasetidvalue        = "datasetIdValue";
            SearchRequestViewModel expectedSearchRequest = new SearchRequestViewModel()
            {
                PageSize   = pageSize,
                PageNumber = 1,
                Filters    = new Dictionary <string, string[]>()
                {
                    { "datasetId", new[] { datasetidvalue } }
                },
                IncludeFacets = false,
                FacetCount    = 0,
                SearchTerm    = null
            };

            IDatasetSearchService mockDatasetSearchService = Substitute.For <IDatasetSearchService>();

            mockDatasetSearchService
            .PerformSearchDatasetVersion(Arg.Is <SearchRequestViewModel>(sr => sr.PageSize == 20))
            .Returns((DatasetVersionSearchResultViewModel)null);
            mockDatasetSearchService
            .PerformSearchDatasetVersion(Arg.Is <SearchRequestViewModel>(sr => sr.PageSize == 1))
            .Returns((DatasetVersionSearchResultViewModel)null);

            DatasetHistoryModel datasetHistoryModel = new DatasetHistoryModel(mockDatasetSearchService);

            // Act
            IActionResult result = await datasetHistoryModel.OnGetAsync(datasetidvalue, 1, 20);

            // Assert
            result.Should().BeOfType <InternalServerErrorResult>();
        }
Beispiel #2
0
        public async Task OnGetAsync_GivenSearchIsOk_ShouldReturnPageResult()
        {
            // Arrange
            const int              pageSize              = 20;
            const string           datasetidvalue        = "datasetIdValue";
            SearchRequestViewModel expectedSearchRequest = new SearchRequestViewModel()
            {
                PageSize   = pageSize,
                PageNumber = 1,
                Filters    = new Dictionary <string, string[]>()
                {
                    { "datasetId", new[] { datasetidvalue } }
                },
                IncludeFacets = false,
                FacetCount    = 0,
                SearchTerm    = null
            };

            IEnumerable <DatasetVersionSearchResultModel> datasetVersionModels = new List <DatasetVersionSearchResultModel>()
            {
                new DatasetVersionSearchResultModel()
            };

            IDatasetSearchService mockDatasetSearchService = Substitute.For <IDatasetSearchService>();

            mockDatasetSearchService
            .PerformSearchDatasetVersion(Arg.Is <SearchRequestViewModel>(sr => sr.PageSize == 20))
            .Returns(new DatasetVersionSearchResultViewModel(datasetVersionModels, 1, 1, 1, 20));
            mockDatasetSearchService
            .PerformSearchDatasetVersion(Arg.Is <SearchRequestViewModel>(sr => sr.PageSize == 1))
            .Returns(new DatasetVersionSearchResultViewModel(datasetVersionModels, 20, 1, 1, 1));

            DatasetHistoryModel datasetHistoryModel = new DatasetHistoryModel(mockDatasetSearchService);

            // Act
            IActionResult result = await datasetHistoryModel.OnGetAsync(datasetidvalue, 1, 20);

            // Assert
            result.Should().BeOfType <PageResult>();

            datasetHistoryModel
            .Current
            .Should().NotBeNull();

            datasetHistoryModel
            .DatasetSearchResultViewModel
            .Should().NotBeNull();

            datasetHistoryModel
            .DatasetId
            .Should().Be(datasetidvalue);
        }
Beispiel #3
0
        public async Task<IActionResult> GetDatasetVersions(string datasetId, [FromQuery]int pageNumber, [FromQuery]int pageSize)
        {
            Guard.IsNullOrWhiteSpace(datasetId, nameof(datasetId));

            Dictionary<string, string[]> datasetIdFilter = new Dictionary<string, string[]>
                {{"datasetId", new[] {datasetId}}};

            SearchRequestViewModel searchRequest = new SearchRequestViewModel()
            {
                PageNumber = pageNumber,
                PageSize = pageSize,
                Filters = datasetIdFilter,
                IncludeFacets = true
            };

            DatasetVersionSearchResultViewModel searchResult =
                await _datasetSearchService.PerformSearchDatasetVersion(searchRequest);
            
            if (searchResult != null)
            {
                return new OkObjectResult(searchResult);
            }
            else
            {
                return new InternalServerErrorResult(
                    "There was an error retrieving data sources from the Search Version Index.");
            }
        }
        public async Task <IActionResult> OnGetAsync(string datasetId, int pageNumber = 1, int pageSize = 20)
        {
            Guard.IsNullOrWhiteSpace(datasetId, nameof(datasetId));

            DatasetId = datasetId;

            Dictionary <string, string[]> datasetIdFilter = new Dictionary <string, string[]> {
                { "datasetId", new[] { datasetId } }
            };

            SearchRequestViewModel searchRequest = new SearchRequestViewModel()
            {
                PageNumber    = pageNumber,
                PageSize      = pageSize,
                Filters       = datasetIdFilter,
                IncludeFacets = false
            };

            SearchRequestViewModel searchRequestForCurrent = new SearchRequestViewModel()
            {
                PageNumber    = 1,
                PageSize      = 1,
                Filters       = datasetIdFilter,
                IncludeFacets = false,
            };

            DatasetVersionSearchResultViewModel searchResult = await _searchService.PerformSearchDatasetVersion(searchRequest);

            DatasetVersionSearchResultViewModel currentSearchResult = (await _searchService.PerformSearchDatasetVersion(searchRequestForCurrent));

            if (searchResult?.Results?.AnyWithNullCheck() == true && currentSearchResult?.Results?.AnyWithNullCheck() == true)
            {
                Current = currentSearchResult.Results.First();

                DatasetSearchResultViewModel = searchResult;

                return(Page());
            }
            else
            {
                return(new InternalServerErrorResult("There was an error retrieving data sources from the Search Version Index."));
            }
        }