Ejemplo n.º 1
0
        public async Task OnGetAsync_WhenOperationTypeIsDatasetUpdatedAndDatasetVersionByDatasetIdIsNotReturned_ThenInternalServerErrorResult()
        {
            //Arrange
            IDatasetSearchService searchService = CreateSearchService();

            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(null, null, DatasetPageBannerOperationType.DatasetUpdated, "Dataset1");

            //Assert
            result
            .Should()
            .BeOfType <InternalServerErrorResult>()
            .And
            .Equals("Dataset API response returned null.");
        }
Ejemplo n.º 2
0
        public async Task OnGetAsync_WhenOperationTypeisSpecifiedButNoOperationId_ThenPreconditionFailedReturned()
        {
            //Arrange
            IDatasetSearchService searchService = CreateSearchService();

            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(null, null, DatasetPageBannerOperationType.DatasetUpdated, null);

            //Assert
            result
            .Should()
            .BeOfType <PreconditionFailedResult>()
            .Which
            .Value
            .Should()
            .Be("Operation ID not provided");
        }
Ejemplo n.º 3
0
        public async Task OnGetAsync_WhenOperationTypeIsDatasetCreated_ThenBannerPopulated()
        {
            //Arrange
            IDatasetSearchService searchService     = CreateSearchService();
            IDatasetsApiClient    datasetsApiClient = CreateDatasetApiClient();

            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, datasetsApiClient);

            string datasetId = "Dataset1";

            DatasetVersionResponse datasetVersionResponse = CreateDatasetResponseForBannerChecks(datasetId);

            datasetsApiClient.GetCurrentDatasetVersionByDatasetId(Arg.Any <string>())
            .Returns(new ApiResponse <DatasetVersionResponse>(HttpStatusCode.OK, datasetVersionResponse));

            //Act
            IActionResult result = await DatasetModel.OnGetAsync(null, null, DatasetPageBannerOperationType.DatasetCreated, "Dataset1");

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

            DatasetModel
            .PageBanner
            .Should()
            .BeEquivalentTo(new PageBannerOperation()
            {
                EntityName                    = "Test Dataset",
                EntityType                    = "Data Source",
                OperationId                   = "Dataset1",
                SecondaryActionUrl            = "/datasets/updatedataset?datasetId=" + datasetId,
                CurrentDataSourceRows         = datasetVersionResponse.CurrentDataSourceRows,
                PreviousDataSourceRows        = datasetVersionResponse.PreviousDataSourceRows,
                DisplayOperationActionSummary = true,
                OperationActionSummaryText    = "A new data source with " + datasetVersionResponse.CurrentDataSourceRows + " data rows uploaded",
            });
        }
        public async Task <IActionResult> SearchDatasets([FromBody] SearchRequestViewModel request)
        {
            Guard.ArgumentNotNull(request, nameof(request));

            DatasetSearchResultViewModel result = await _datasetSearchService.PerformSearch(request);

            if (result != null)
            {
                return(Ok(result));
            }
            else
            {
                return(new StatusCodeResult(500));
            }
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        public async Task<IActionResult> SearchDatasets([FromBody]DatasetSearchRequestViewModel request)
        {
            Guard.ArgumentNotNull(request, nameof(request));
            
            SearchRequestViewModel searchRequest = new SearchRequestViewModel
            {
                Filters = new Dictionary<string, string[]>(),
                ErrorToggle = request.ErrorToggle,
                FacetCount = request.FacetCount,
                IncludeFacets = request.IncludeFacets,
                PageNumber = request.PageNumber,
                PageSize = request.PageSize,
                SearchMode = request.SearchMode,
                SearchTerm = request.SearchTerm
            };

            if (request.FundingStreams?.Length > 0)
            {
                searchRequest.Filters.Add("fundingStreamName", request.FundingStreams.ToArray());
            }
            
            if (request.DataSchemas?.Length > 0)
            {
                searchRequest.Filters.Add("definitionName", request.DataSchemas.ToArray());
            }
            
            DatasetSearchResultViewModel result = await _datasetSearchService.PerformSearch(searchRequest);
            if (result != null)
            {
                return Ok(result);
            }
            else
            {
                return new StatusCodeResult(500);
            }
        }
Ejemplo n.º 8
0
        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));
        }
        public async Task <IActionResult> OnGetAsync(int?pageNumber, string searchTerm, DatasetPageBannerOperationType?operationType = null, string operationId = null)
        {
            SearchRequestViewModel searchRequest = new SearchRequestViewModel()
            {
                PageNumber    = pageNumber,
                IncludeFacets = false,
                SearchTerm    = searchTerm,
            };

            SearchTerm = searchTerm;

            OperationType = operationType;

            if (operationType.HasValue)
            {
                if (string.IsNullOrWhiteSpace(operationId))
                {
                    return(new PreconditionFailedResult("Operation ID not provided"));
                }

                ApiResponse <DatasetVersionResponse> datasetVersionResponse = await _datasetApiClient.GetCurrentDatasetVersionByDatasetId(operationId);

                IActionResult errorResult = datasetVersionResponse.IsSuccessOrReturnFailureResult("Dataset");

                if (errorResult != null)
                {
                    return(errorResult);
                }

                DatasetVersionResponse DatsetVersion = datasetVersionResponse.Content;

                PageBanner = new PageBannerOperation()
                {
                    EntityName  = DatsetVersion.Name,
                    EntityType  = "Data Source",
                    OperationId = operationId,
                    DisplayOperationActionSummary = true,
                    CurrentDataSourceRows         = DatsetVersion.CurrentDataSourceRows,
                    PreviousDataSourceRows        = DatsetVersion.PreviousDataSourceRows,
                    SecondaryActionUrl            = $"/datasets/updatedataset?datasetId={operationId}",
                };

                switch (operationType)
                {
                case DatasetPageBannerOperationType.DatasetCreated:
                    PageBanner.OperationActionSummaryText = "A new data source with " + PageBanner.CurrentDataSourceRows + " data rows uploaded";
                    break;

                case DatasetPageBannerOperationType.DatasetUpdated:
                    PageBanner.OperationActionSummaryText = "A new version of a data source with " + PageBanner.CurrentDataSourceRows + " data rows uploaded, the previous version contained " + PageBanner.PreviousDataSourceRows + "  data rows";
                    break;
                }
            }

            SearchResults = await _searchService.PerformSearch(searchRequest);

            if (SearchResults == null)
            {
                return(new InternalServerErrorResult("There was an error retrieving data sources from the Search Index."));
            }

            return(Page());
        }