Beispiel #1
0
        public async Task SearchSpecificationDatasetRelationships_GivenSearchThrowsException_ReturnsStatusCode500()
        {
            //Arrange
            SearchModel model = CreateSearchModel();

            ISearchRepository <SpecificationIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .When(x => x.Search(Arg.Any <string>(), Arg.Any <SearchParameters>()))
            .Do(x => { throw new FailedToQuerySearchException("main", new Exception("inner")); });

            ILogger logger = CreateLogger();

            SpecificationsSearchService service = CreateSearchService(searchRepository, logger);

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

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

            StatusCodeResult statusCodeResult = result as StatusCodeResult;

            statusCodeResult
            .StatusCode
            .Should()
            .Be(500);
        }
Beispiel #2
0
        public async Task SearchSpecificationDatasetRelationships_GivenInvalidTop_ReturnsBadRequest()
        {
            //Arrange
            SearchModel model = new SearchModel
            {
                PageNumber = 1,
                Top        = 0
            };

            ILogger logger = CreateLogger();

            SpecificationsSearchService service = CreateSearchService(logger: logger);

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

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

            result
            .Should()
            .BeOfType <BadRequestObjectResult>();
        }
Beispiel #3
0
        public async Task SearchSpecificationDatasetRelationships_GivenSearchReturnsResultsAndDataDefinitionsHasItems_ReturnsOKResult()
        {
            //Arrange
            SearchModel model = CreateSearchModel();

            SearchResults <SpecificationIndex> searchResults = new SearchResults <SpecificationIndex>
            {
                TotalCount = 1,
                Results    = new List <Repositories.Common.Search.SearchResult <SpecificationIndex> >
                {
                    new Repositories.Common.Search.SearchResult <SpecificationIndex>
                    {
                        Result = new SpecificationIndex
                        {
                            DataDefinitionRelationshipIds = new[] { "def-1", "def-2" }
                        }
                    }
                }
            };

            ISearchRepository <SpecificationIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Is("SearchTermTest"), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            ILogger logger = CreateLogger();

            SpecificationsSearchService service = CreateSearchService(searchRepository, logger);

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

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

            OkObjectResult okObjectResult = result as OkObjectResult;

            SpecificationDatasetRelationshipsSearchResults specificationSearchResults = okObjectResult.Value as SpecificationDatasetRelationshipsSearchResults;

            specificationSearchResults
            .Results
            .Count()
            .Should()
            .Be(1);

            specificationSearchResults
            .TotalCount
            .Should()
            .Be(1);

            specificationSearchResults
            .Results
            .First()
            .DefinitionRelationshipCount
            .Should()
            .Be(2);
        }
Beispiel #4
0
        public async Task SearchSpecificationDatasetRelationships_GivenSearchReturnsResults_ReturnsOKResult(params string[] expectedSearchFields)
        {
            //Arrange
            SearchModel model = CreateSearchModel(expectedSearchFields);

            expectedSearchFields ??= new[]
            {
                "name"
            };

            SearchResults <SpecificationIndex> searchResults = new SearchResults <SpecificationIndex>
            {
                TotalCount = 1
            };

            ISearchRepository <SpecificationIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Is("SearchTermTest"), Arg.Is <SearchParameters>(sp =>
                                                                        sp.SearchFields != null &&
                                                                        sp.SearchFields.SequenceEqual(expectedSearchFields)))
            .Returns(searchResults);

            ILogger logger = CreateLogger();

            SpecificationsSearchService service = CreateSearchService(searchRepository, logger);

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

            //Assert
            result
            .Should()
            .BeOfType <OkObjectResult>();
        }
Beispiel #5
0
        public async Task SearchSpecificationDatasetRelationships_GivenNullSearchModel_ReturnsBadRequest()
        {
            //Arrange
            HttpRequest request = Substitute.For <HttpRequest>();

            ILogger logger = CreateLogger();

            SpecificationsSearchService service = CreateSearchService(logger: logger);

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

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

            result
            .Should()
            .BeOfType <BadRequestObjectResult>();
        }
Beispiel #6
0
        async public Task SearchSpecificationDatasetRelationships_GivenSearchThrowsException_ReturnsStatusCode500()
        {
            //Arrange
            SearchModel model = CreateSearchModel();
            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);

            ISearchRepository <SpecificationIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .When(x => x.Search(Arg.Any <string>(), Arg.Any <SearchParameters>()))
            .Do(x => { throw new FailedToQuerySearchException("main", new Exception("inner")); });

            ILogger logger = CreateLogger();

            SpecificationsSearchService service = CreateSearchService(searchRepository, logger);

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

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

            StatusCodeResult statusCodeResult = result as StatusCodeResult;

            statusCodeResult
            .StatusCode
            .Should()
            .Be(500);
        }
Beispiel #7
0
        async public Task SearchSpecificationDatasetRelationships_GivenSearchReturnsResults_ReturnsOKResult()
        {
            //Arrange
            SearchModel model = CreateSearchModel();
            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 <SpecificationIndex> searchResults = new SearchResults <SpecificationIndex>
            {
                TotalCount = 1
            };

            ISearchRepository <SpecificationIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Is("SearchTermTest"), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            ILogger logger = CreateLogger();

            SpecificationsSearchService service = CreateSearchService(searchRepository, logger);

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

            //Assert
            result
            .Should()
            .BeOfType <OkObjectResult>();
        }
Beispiel #8
0
        async public Task SearchSpecificationDatasetRelationships_GivenSearchReturnsResultsAndDataDefinitionsHasItems_ReturnsOKResult()
        {
            //Arrange
            SearchModel model = CreateSearchModel();
            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 <SpecificationIndex> searchResults = new SearchResults <SpecificationIndex>
            {
                TotalCount = 1,
                Results    = new List <Repositories.Common.Search.SearchResult <SpecificationIndex> >
                {
                    new Repositories.Common.Search.SearchResult <SpecificationIndex>
                    {
                        Result = new SpecificationIndex
                        {
                            DataDefinitionRelationshipIds = new[] { "def-1", "def-2" }
                        }
                    }
                }
            };

            ISearchRepository <SpecificationIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Is("SearchTermTest"), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            ILogger logger = CreateLogger();

            SpecificationsSearchService service = CreateSearchService(searchRepository, logger);

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

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

            OkObjectResult okObjectResult = result as OkObjectResult;

            SpecificationDatasetRelationshipsSearchResults specificationSearchResults = okObjectResult.Value as SpecificationDatasetRelationshipsSearchResults;

            specificationSearchResults
            .Results
            .Count()
            .Should()
            .Be(1);

            specificationSearchResults
            .TotalCount
            .Should()
            .Be(1);

            specificationSearchResults
            .Results
            .First()
            .DefinitionRelationshipCount
            .Should()
            .Be(2);
        }
Beispiel #9
0
        public async Task SearchSpecificationDatasetRelationships_GivenSearchReturnsFacets_ReturnsOKResult()
        {
            //Arrange
            SearchModel model = CreateSearchModel();

            SearchResults <SpecificationIndex> searchResults = new SearchResults <SpecificationIndex>
            {
                TotalCount = 1,
                Facets     = new List <Facet>
                {
                    new Facet
                    {
                        Name        = "stuff",
                        FacetValues = new[]
                        {
                            new FacetValue
                            {
                                Count = 200,
                                Name  = "stuff one"
                            },
                        }
                    },
                }
            };

            ISearchRepository <SpecificationIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Is("SearchTermTest"), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            ILogger logger = CreateLogger();

            SpecificationsSearchService service = CreateSearchService(searchRepository, logger);

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

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

            OkObjectResult okObjectResult = result as OkObjectResult;

            SpecificationDatasetRelationshipsSearchResults specificationSearchResults = okObjectResult.Value as SpecificationDatasetRelationshipsSearchResults;

            specificationSearchResults
            .Results
            .Should()
            .BeNullOrEmpty();

            specificationSearchResults
            .TotalCount
            .Should()
            .Be(0);

            searchResults
            .Facets
            .Should()
            .BeEquivalentTo(searchResults.Facets);
        }