public async Task SearchDatasetDefinition_GivenValidModelAndDoesntIncludeGettingFacets_CallsSearchOnce()
        {
            //Arrange
            SearchModel model = new SearchModel
            {
                PageNumber = 1,
                Top        = 50
            };

            SearchResults <DatasetDefinitionIndex> searchResults = new SearchResults <DatasetDefinitionIndex>();

            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(model);

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

            await
            searchRepository
            .Received(1)
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>());
        }
        public async Task SearchDatasetDefinition_SearchRequestFails_ThenBadRequestReturned()
        {
            //Arrange
            SearchModel model = new SearchModel()
            {
                SearchTerm    = "SearchTermTest",
                PageNumber    = 1,
                IncludeFacets = false,
                Top           = 50,
            };

            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .When(s => s.Search(Arg.Any <string>(), Arg.Any <SearchParameters>()))
            .Do(x => { throw new FailedToQuerySearchException("Test Message", null); });


            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(model);

            //Assert
            logger
            .Received(1)
            .Error(Arg.Any <FailedToQuerySearchException>(), "Failed to query search with term: SearchTermTest");

            result
            .Should()
            .BeOfType <StatusCodeResult>()
            .Which.StatusCode.Should().Be(500);
        }
        public async Task SearchDatasetDefinition_GivenPageTopIsZero_LogsAndReturnsBadRequest()
        {
            //Arrange
            SearchModel model = new SearchModel
            {
                PageNumber = 1,
                Top        = 0
            };

            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(model);

            //Assert
            logger
            .Received(1)
            .Error("A null or invalid search model was provided for searching datasets");

            result
            .Should()
            .BeOfType <BadRequestObjectResult>();
        }
Beispiel #4
0
        public async Task SearchDatasetDefinition_GivenPageNumberIsZero_LogsAndReturnsBadRequest()
        {
            //Arrange
            SearchModel model = new SearchModel();
            string      json  = JsonConvert.SerializeObject(model);

            byte[]       byteArray = Encoding.UTF8.GetBytes(json);
            MemoryStream stream    = new MemoryStream(byteArray);

            HttpRequest request = Substitute.For <HttpRequest>();

            request
            .Body
            .Returns(stream);

            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(request);

            //Assert
            logger
            .Received(1)
            .Error("A null or invalid search model was provided for searching datasets");

            result
            .Should()
            .BeOfType <BadRequestObjectResult>();
        }
Beispiel #5
0
        public async Task SearchDatasetDefinition_GivenValidModel_CallsSearchWithCorrectSkipValue()
        {
            //Arrange
            SearchModel model = new SearchModel
            {
                PageNumber    = 10,
                Top           = 50,
                IncludeFacets = true
            };

            string json = JsonConvert.SerializeObject(model);

            byte[]       byteArray = Encoding.UTF8.GetBytes(json);
            MemoryStream stream    = new MemoryStream(byteArray);

            HttpRequest request = Substitute.For <HttpRequest>();

            request
            .Body
            .Returns(stream);

            SearchResults <DatasetDefinitionIndex> searchResults = new SearchResults <DatasetDefinitionIndex>
            {
                Facets = new List <Facet>
                {
                    new Facet
                    {
                        Name = "specificationNames"
                    }
                }
            };

            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(request);

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

            await
            searchRepository
            .Received(2)
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>());
        }
Beispiel #6
0
        public async Task SearchDatasetDefinition_GivenValidModelWithNullFilterWithMultipleOfSameFilter_ThenSearchIsPerformed()
        {
            //Arrange
            SearchModel model = new SearchModel
            {
                PageNumber    = 1,
                Top           = 50,
                IncludeFacets = true,
                Filters       = new Dictionary <string, string[]>()
                {
                    { "providerIdentifier", new string [] { "test", "" } }
                },
                SearchTerm = "testTerm",
            };

            string json = JsonConvert.SerializeObject(model);

            byte[]       byteArray = Encoding.UTF8.GetBytes(json);
            MemoryStream stream    = new MemoryStream(byteArray);

            HttpRequest request = Substitute.For <HttpRequest>();

            request
            .Body
            .Returns(stream);

            SearchResults <DatasetDefinitionIndex> searchResults = new SearchResults <DatasetDefinitionIndex>();

            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(request);

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

            await
            searchRepository
            .Received(1)
            .Search(model.SearchTerm, Arg.Is <SearchParameters>(c =>
                                                                model.Filters.Keys.All(f => c.Filter.Contains(f)) &&
                                                                !string.IsNullOrWhiteSpace(c.Filter)
                                                                ));
        }
Beispiel #7
0
        public async Task SearchDatasetDefinition_GivenValidModelAndPageNumber2_CallsSearchWithCorrectSkipValue()
        {
            //Arrange
            const int skipValue = 50;

            SearchModel model = new SearchModel
            {
                PageNumber = 2,
                Top        = 50
            };

            string json = JsonConvert.SerializeObject(model);

            byte[]       byteArray = Encoding.UTF8.GetBytes(json);
            MemoryStream stream    = new MemoryStream(byteArray);

            HttpRequest request = Substitute.For <HttpRequest>();

            request
            .Body
            .Returns(stream);

            SearchResults <DatasetDefinitionIndex> searchResults = new SearchResults <DatasetDefinitionIndex>();

            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(request);

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

            await
            searchRepository
            .Received(1)
            .Search(Arg.Any <string>(), Arg.Is <SearchParameters>(m => m.Skip == skipValue));
        }
Beispiel #8
0
        public async Task SearchDatasetDefinition_SearchRequestFails_ThenBadRequestReturned()
        {
            //Arrange
            SearchModel model = new SearchModel()
            {
                SearchTerm    = "SearchTermTest",
                PageNumber    = 1,
                IncludeFacets = false,
                Top           = 50,
            };

            string json = JsonConvert.SerializeObject(model);

            byte[]       byteArray = Encoding.UTF8.GetBytes(json);
            MemoryStream stream    = new MemoryStream(byteArray);

            HttpRequest request = Substitute.For <HttpRequest>();

            request
            .Body
            .Returns(stream);

            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .When(s => s.Search(Arg.Any <string>(), Arg.Any <SearchParameters>()))
            .Do(x => { throw new FailedToQuerySearchException("Test Message", null); });


            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(request);

            //Assert
            logger
            .Received(1)
            .Error(Arg.Any <FailedToQuerySearchException>(), "Failed to query search with term: SearchTermTest");

            result
            .Should()
            .BeOfType <StatusCodeResult>()
            .Which.StatusCode.Should().Be(500);
        }
        public async Task SearchDatasetDefinition_GivenValidModel_CallsSearchWithCorrectSkipValue()
        {
            //Arrange
            SearchModel model = new SearchModel
            {
                PageNumber    = 10,
                Top           = 50,
                IncludeFacets = true
            };

            SearchResults <DatasetDefinitionIndex> searchResults = new SearchResults <DatasetDefinitionIndex>
            {
                Facets = new List <Facet>
                {
                    new Facet
                    {
                        Name = "specificationNames"
                    }
                }
            };

            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(model);

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

            await
            searchRepository
            .Received(4)
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>());
        }
        public async Task SearchDatasetDefinition_GivenValidModelWithNullFilterWithMultipleOfSameFilter_ThenSearchIsPerformed()
        {
            //Arrange
            SearchModel model = new SearchModel
            {
                PageNumber    = 1,
                Top           = 50,
                IncludeFacets = true,
                Filters       = new Dictionary <string, string[]>()
                {
                    { "providerIdentifier", new string [] { "test", "" } }
                },
                SearchTerm = "testTerm",
            };

            SearchResults <DatasetDefinitionIndex> searchResults = new SearchResults <DatasetDefinitionIndex>();

            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(model);

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

            await
            searchRepository
            .Received(3)
            .Search(model.SearchTerm, Arg.Is <SearchParameters>(c =>
                                                                model.Filters.Keys.All(f => c.Filter.Contains(f)) &&
                                                                !string.IsNullOrWhiteSpace(c.Filter)
                                                                ));
        }
        public async Task SearchDatasetDefinition_GivenNullSearchModel_LogsAndCreatesDefaultSearchModel()
        {
            //Arrange
            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(null);

            //Assert
            logger
            .Received(1)
            .Error("A null or invalid search model was provided for searching datasets");

            result
            .Should()
            .BeOfType <BadRequestObjectResult>();
        }
        public async Task SearchDatasetDefinition_GivenValidModelAndPageNumber10_CallsSearchWithCorrectSkipValue()
        {
            //Arrange
            const int skipValue = 450;

            SearchModel model = new SearchModel
            {
                PageNumber = 10,
                Top        = 50
            };

            SearchResults <DatasetDefinitionIndex> searchResults = new SearchResults <DatasetDefinitionIndex>();

            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(model);

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

            await
            searchRepository
            .Received(1)
            .Search(Arg.Any <string>(), Arg.Is <SearchParameters>(m => m.Skip == skipValue));
        }
        public async Task SearchDatasetDefinition_GivenValidModelWithNullFilters_ThenSearchIsStillPerformed()
        {
            //Arrange
            SearchModel model = new SearchModel
            {
                PageNumber    = 1,
                Top           = 50,
                IncludeFacets = true,
                Filters       = null,
            };

            SearchResults <DatasetDefinitionIndex> searchResults = new SearchResults <DatasetDefinitionIndex>();

            ILogger logger = CreateLogger();

            ISearchRepository <DatasetDefinitionIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            DatasetDefinitionSearchService service = CreateDatasetSearchService(logger: logger, searchRepository: searchRepository);

            //Act
            IActionResult result = await service.SearchDatasetDefinitions(model);

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

            await
            searchRepository
            .Received(4)
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>());
        }