示例#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.");
        }
示例#2
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>();
        }
示例#3
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");
        }
示例#4
0
 private static ManageDatasetsPageModel CreateDatasetPageModel(
     IDatasetSearchService searchService = null,
     IDatasetsApiClient datasetApiClient = null,
     IFeatureToggle featureToggle        = null)
 {
     return(new ManageDatasetsPageModel(
                searchService ?? CreateSearchService(),
                datasetApiClient ?? CreateDatasetApiClient(),
                featureToggle ?? CreateFeatureToggle()));
 }
示例#5
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 ManageDatasetsPageModel(IDatasetSearchService searchService, IDatasetsApiClient datasetApiClient, IFeatureToggle featureToggle)
        {
            Guard.ArgumentNotNull(searchService, nameof(searchService));
            Guard.ArgumentNotNull(datasetApiClient, nameof(datasetApiClient));
            Guard.ArgumentNotNull(featureToggle, nameof(featureToggle));

            _searchService    = searchService;
            _datasetApiClient = datasetApiClient;
            _featureToggle    = featureToggle;

            ShouldNewManageSourcesPageBeEnabled = _featureToggle.IsNewManageDataSourcesPageEnabled();
        }
示例#7
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);
        }
示例#8
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));
        }
示例#9
0
        public DatasetsController(
            IDefinitionsService definitionService,
            IDatasetService datasetService,
            IDatasetSearchService datasetSearchService,
            IDatasetDefinitionSearchService datasetDefinitionSearchService,
            IDefinitionSpecificationRelationshipService definitionSpecificationRelationshipService,
            IProcessDatasetService processDatasetService)
        {
            Guard.ArgumentNotNull(definitionService, nameof(definitionService));
            Guard.ArgumentNotNull(datasetService, nameof(datasetService));
            Guard.ArgumentNotNull(datasetSearchService, nameof(datasetSearchService));
            Guard.ArgumentNotNull(datasetDefinitionSearchService, nameof(datasetDefinitionSearchService));
            Guard.ArgumentNotNull(definitionSpecificationRelationshipService, nameof(definitionSpecificationRelationshipService));
            Guard.ArgumentNotNull(processDatasetService, nameof(processDatasetService));

            _definitionService                          = definitionService;
            _datasetService                             = datasetService;
            _datasetSearchService                       = datasetSearchService;
            _datasetDefinitionSearchService             = datasetDefinitionSearchService;
            _definitionSpecificationRelationshipService = definitionSpecificationRelationshipService;
            _processDatasetService                      = processDatasetService;
        }
示例#10
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));
        }
        public DatasetSearchController(IDatasetSearchService datasetSearchService)
        {
            Guard.ArgumentNotNull(datasetSearchService, nameof(datasetSearchService));

            _datasetSearchService = datasetSearchService;
        }
示例#12
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 DatasetHistoryModel(IDatasetSearchService searchService)
 {
     _searchService = searchService;
 }