Exemplo n.º 1
0
        public async Task PerformSearch_StartAndEndItemsNumbersDisplayedCorrectlyOnSecondPageOfItemsWithMorePagesAvailable()
        {
            // Arrange
            IDatasetsApiClient datasetClient = Substitute.For <IDatasetsApiClient>();
            ILogger            logger        = Substitute.For <ILogger>();
            IMapper            mapper        = MappingHelper.CreateFrontEndMapper();

            IDatasetSearchService datasetSearchService = new DatasetSearchService(datasetClient, mapper, logger);

            int numberOfItems = 50;

            ApiResponse <SearchResults <DatasetIndex> > itemResult = GenerateSearchResult(numberOfItems);

            itemResult.Content.TotalCount = 175;

            datasetClient
            .SearchDatasets(Arg.Any <SearchModel>())
            .Returns(itemResult);

            SearchRequestViewModel request = new SearchRequestViewModel()
            {
                PageNumber = 2,
                PageSize   = 50
            };

            // Act
            DatasetSearchResultViewModel results = await datasetSearchService.PerformSearch(request);

            // Assert
            results.StartItemNumber.Should().Be(51);
            results.EndItemNumber.Should().Be(100);
        }
Exemplo n.º 2
0
        public async Task PerformSearch_FirstSearchResultReturnedCorrectly()
        {
            // Arrange
            IDatasetsApiClient datasetClient = Substitute.For <IDatasetsApiClient>();
            ILogger            logger        = Substitute.For <ILogger>();
            IMapper            mapper        = MappingHelper.CreateFrontEndMapper();

            IDatasetSearchService datasetSearchService = new DatasetSearchService(datasetClient, mapper, logger);

            int numberOfItems = 25;

            ApiResponse <SearchResults <DatasetIndex> > itemResult = GenerateSearchResult(numberOfItems);

            datasetClient
            .SearchDatasets(Arg.Any <SearchModel>())
            .Returns(itemResult);

            SearchRequestViewModel request = new SearchRequestViewModel();

            // Act
            DatasetSearchResultViewModel results = await datasetSearchService.PerformSearch(request);

            // Assert
            DatasetSearchResultItemViewModel first = results.Datasets.First();

            first.Should().NotBeNull();
            first.Id.Should().Be("10");
            first.Status.Should().Be("Unknown");
            first.LastUpdated.Should().Be(new DateTime(2018, 2, 6, 15, 31, 0));
            first.Name.Should().Be("Dataset 1");
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public async Task PerformSearch_StartAndEndItemsNumbersDisplayedCorrectlyOnZeroItems()
        {
            // Arrange
            IDatasetsApiClient datasetClient = Substitute.For <IDatasetsApiClient>();
            ILogger            logger        = Substitute.For <ILogger>();
            IMapper            mapper        = MappingHelper.CreateFrontEndMapper();

            IDatasetSearchService datasetSearchService = new DatasetSearchService(datasetClient, mapper, logger);

            int numberOfItems = 0;

            ApiResponse <SearchResults <DatasetIndex> > itemResult = GenerateSearchResult(numberOfItems);

            datasetClient
            .SearchDatasets(Arg.Any <SearchModel>())
            .Returns(itemResult);

            SearchRequestViewModel request = new SearchRequestViewModel();

            // Act
            DatasetSearchResultViewModel results = await datasetSearchService.PerformSearch(request);

            // Assert
            results.StartItemNumber.Should().Be(0);
            results.EndItemNumber.Should().Be(0);
        }
Exemplo n.º 5
0
        public async Task PerformSearch_StartAndEndItemsNumbersDisplayedCorrectlyOnSecondPageOfItemsWithMorePagesAvailable()
        {
            // Arrange
            IDatasetsApiClient datasetClient = Substitute.For <IDatasetsApiClient>();
            ILogger            logger        = Substitute.For <ILogger>();
            IMapper            mapper        = MappingHelper.CreateFrontEndMapper();
            IFeatureToggle     featureToggle = CreateFeatureToggle();

            IDatasetSearchService datasetSearchService = new DatasetSearchService(datasetClient, mapper, logger, featureToggle);

            int numberOfItems = 50;

            PagedResult <DatasetSearchResultItem> itemResult = GeneratePagedResult(numberOfItems);

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

            datasetClient
            .FindDatasets(Arg.Any <SearchFilterRequest>())
            .Returns(itemResult);

            SearchRequestViewModel request = new SearchRequestViewModel()
            {
                PageNumber = 2,
            };

            // Act
            DatasetSearchResultViewModel results = await datasetSearchService.PerformSearch(request);

            // Assert
            results.StartItemNumber.Should().Be(51);
            results.EndItemNumber.Should().Be(100);
        }
Exemplo n.º 6
0
        public void PerformSearch_WhenFindDatasetsServiceUnavailable_ThenHttpExceptionThrown()
        {
            // Arrange
            IDatasetsApiClient datasetClient = Substitute.For <IDatasetsApiClient>();
            ILogger            logger        = Substitute.For <ILogger>();
            IMapper            mapper        = MappingHelper.CreateFrontEndMapper();
            IFeatureToggle     featureToggle = CreateFeatureToggle();

            IDatasetSearchService datasetSearchService = new DatasetSearchService(datasetClient, mapper, logger, featureToggle);

            datasetClient
            .When(a => a.FindDatasets(Arg.Any <SearchFilterRequest>()))
            .Do(x => { throw new HttpRequestException(); });

            SearchRequestViewModel request = new SearchRequestViewModel();

            // Act
            Action pageAction = new Action(() =>
            {
                DatasetSearchResultViewModel result = datasetSearchService.PerformSearch(request).Result;
            });

            // Assert
            pageAction.Should().Throw <HttpRequestException>();
        }
Exemplo n.º 7
0
        public async Task PerformSearchDatasetVersion_GivenClientReturnsEmptyResult_ShouldReturnCorrectlyMappedResult()
        {
            // Arrange
            IDatasetsApiClient mockDatasetsApiClient = Substitute.For <IDatasetsApiClient>();
            ILogger            mockLogger            = Substitute.For <ILogger>();
            IMapper            mockMapper            = MappingHelper.CreateFrontEndMapper();

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

            mockDatasetsApiClient
            .SearchDatasets(Arg.Any <SearchModel>())
            .Returns((ApiResponse <SearchResults <DatasetIndex> >)null);

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

            // Assert
            datasetVersionSearchResultViewModel.Should().BeNull();
        }
Exemplo n.º 8
0
        public async Task PerformSearch_GivenIsSearchModeAllEnabledFeatureToggleIdTurnedOn_SearchModeIsAll()
        {
            // Arrange
            IDatasetsApiClient mockDatasetsApiClient = Substitute.For <IDatasetsApiClient>();
            ILogger            mockLogger            = Substitute.For <ILogger>();
            IMapper            mockMapper            = MappingHelper.CreateFrontEndMapper();
            IFeatureToggle     featureToggle         = CreateFeatureToggle(true);

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

            // Act
            DatasetSearchResultViewModel datasetVersionSearchResultViewModel = await datasetSearchService.PerformSearch(new SearchRequestViewModel());

            // Assert
            await
            mockDatasetsApiClient
            .Received(1)
            .FindDatasets(Arg.Is <SearchFilterRequest>(m => m.SearchMode == SearchMode.All));
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
0
        public async Task PerformSearch_FirstSearchResultWithFacets_ReturnedCorrectly()
        {
            // Arrange
            IDatasetsApiClient datasetClient = Substitute.For <IDatasetsApiClient>();
            ILogger            logger        = Substitute.For <ILogger>();
            IMapper            mapper        = MappingHelper.CreateFrontEndMapper();
            IFeatureToggle     featureToggle = CreateFeatureToggle();

            IDatasetSearchService datasetSearchService = new DatasetSearchService(datasetClient, mapper, logger, featureToggle);

            int numberOfItems = 25;

            IEnumerable <SearchFacet> facets = new[]
            {
                new SearchFacet(), new SearchFacet()
            };

            PagedResult <DatasetSearchResultItem> itemResult = GeneratePagedResult(numberOfItems, facets);

            datasetClient
            .FindDatasets(Arg.Any <SearchFilterRequest>())
            .Returns(itemResult);

            SearchRequestViewModel request = new SearchRequestViewModel();

            // Act
            DatasetSearchResultViewModel results = await datasetSearchService.PerformSearch(request);

            // Assert
            DatasetSearchResultItemViewModel first = results.Datasets.First();

            first.Should().NotBeNull();
            first.Id.Should().Be("10");
            first.LastUpdated.Should().Be(new DateTime(2018, 2, 6, 15, 31, 0));
            first.Status.Should().Be("Unknown");
            first.Name.Should().Be("Dataset 1");

            results.Facets.Count().Should().Be(2);
        }
Exemplo n.º 11
0
        public async Task PerformSearch_WhenFindDatasetsServiceReturnsNotFound_ThenNullReturned()
        {
            // Arrange
            IDatasetsApiClient datasetClient = Substitute.For <IDatasetsApiClient>();
            ILogger            logger        = Substitute.For <ILogger>();
            IMapper            mapper        = MappingHelper.CreateFrontEndMapper();

            IDatasetSearchService datasetSearchService = new DatasetSearchService(datasetClient, mapper, logger);

            ApiResponse <SearchResults <DatasetIndex> > expectedServiceResult = null;

            datasetClient
            .SearchDatasets(Arg.Any <SearchModel>())
            .Returns(expectedServiceResult);

            SearchRequestViewModel request = new SearchRequestViewModel();

            // Act
            DatasetSearchResultViewModel result = await datasetSearchService.PerformSearch(request);

            // Assert
            result.Should().BeNull();
        }
Exemplo n.º 12
0
        public async Task PerformSearch_WhenFindDatasetsServiceReturnsNotFound_ThenNullReturned()
        {
            // Arrange
            IDatasetsApiClient datasetClient = Substitute.For <IDatasetsApiClient>();
            ILogger            logger        = Substitute.For <ILogger>();
            IMapper            mapper        = MappingHelper.CreateFrontEndMapper();
            IFeatureToggle     featureToggle = CreateFeatureToggle();

            IDatasetSearchService datasetSearchService = new DatasetSearchService(datasetClient, mapper, logger, featureToggle);

            PagedResult <DatasetSearchResultItem> expectedServiceResult = null;

            datasetClient
            .FindDatasets(Arg.Any <SearchFilterRequest>())
            .Returns(expectedServiceResult);

            SearchRequestViewModel request = new SearchRequestViewModel();

            // Act
            DatasetSearchResultViewModel result = await datasetSearchService.PerformSearch(request);

            // Assert
            result.Should().BeNull();
        }
Exemplo n.º 13
0
        public async Task PerformSearch_FirstSearchResultWithFacets_EnsuresFacetsLoadedCorrectly()
        {
            // Arrange
            IDatasetsApiClient datasetClient = Substitute.For <IDatasetsApiClient>();
            ILogger            logger        = Substitute.For <ILogger>();
            IMapper            mapper        = MappingHelper.CreateFrontEndMapper();

            IDatasetSearchService datasetSearchService = new DatasetSearchService(datasetClient, mapper, logger);

            int numberOfItems = 25;

            IEnumerable <SearchFacet> facets = new[]
            {
                new SearchFacet
                {
                    Name        = "facet 1",
                    FacetValues = new[]
                    {
                        new SearchFacetValue {
                            Name = "f1", Count = 5
                        }
                    }
                },
                new SearchFacet
                {
                    Name        = "facet 2",
                    FacetValues = new[]
                    {
                        new SearchFacetValue {
                            Name = "f2", Count = 11
                        },
                        new SearchFacetValue {
                            Name = "f3", Count = 1
                        }
                    }
                }
            };

            ApiResponse <SearchResults <DatasetIndex> > itemResult = GenerateSearchResult(numberOfItems, facets);

            datasetClient
            .SearchDatasets(Arg.Any <SearchModel>())
            .Returns(itemResult);

            SearchRequestViewModel request = new SearchRequestViewModel();

            // Act
            DatasetSearchResultViewModel results = await datasetSearchService.PerformSearch(request);

            // Assert
            DatasetSearchResultItemViewModel first = results.Datasets.First();

            first.Should().NotBeNull();
            first.Id.Should().Be("10");
            first.LastUpdated.Should().Be(new DateTime(2018, 2, 6, 15, 31, 0));
            first.Status.Should().Be("Unknown");
            first.Name.Should().Be("Dataset 1");

            results.Facets.Count().Should().Be(2);
            results.Facets.First().Name.Should().Be("facet 1");
            results.Facets.First().FacetValues.Count().Should().Be(1);
            results.Facets.First().FacetValues.First().Name.Should().Be("f1");
            results.Facets.First().FacetValues.First().Count.Should().Be(5);
            results.Facets.Last().Name.Should().Be("facet 2");
            results.Facets.Last().FacetValues.Count().Should().Be(2);
            results.Facets.Last().FacetValues.First().Name.Should().Be("f2");
            results.Facets.Last().FacetValues.First().Count.Should().Be(11);
            results.Facets.Last().FacetValues.Last().Name.Should().Be("f3");
            results.Facets.Last().FacetValues.Last().Count.Should().Be(1);
        }