Exemple #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>();
        }
Exemple #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);
        }