public async Task SearchScenarios_GivenInvalidTop_ReturnsBadRequest()
        {
            //Arrange
            SearchModel model = new SearchModel
            {
                PageNumber = 1,
                Top        = 0
            };
            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();

            ScenariosSearchService service = CreateSearchService(logger: logger);

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

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

            result
            .Should()
            .BeOfType <BadRequestObjectResult>();
        }
Exemplo n.º 2
0
        async public Task SearchScenarios_GivenSearchThrowsException_ReturnsStatusCode500()
        {
            //Arrange
            SearchModel model = CreateSearchModel();

            ISearchRepository <ScenarioIndex> 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();

            ScenariosSearchService service = CreateSearchService(searchRepository, logger: logger);

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

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

            statusCodeResult
            .StatusCode
            .Should()
            .Be(500);
        }
Exemplo n.º 3
0
        async public Task SearchScenarios_GivenSearchReturnsResults_ReturnsOKResult()
        {
            //Arrange
            SearchModel model = CreateSearchModel();

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

            ISearchRepository <ScenarioIndex> searchRepository = CreateSearchRepository();

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

            ILogger logger = CreateLogger();

            ScenariosSearchService service = CreateSearchService(searchRepository, logger: logger);

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

            //Assert
            result
            .Should()
            .BeOfType <OkObjectResult>();
        }
        async public Task SearchScenarios_GivenSearchReturnsResultsAndDataLastUpdateIsNull_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 <ScenarioIndex> searchResults = new SearchResults <ScenarioIndex>
            {
                TotalCount = 1,
                Results    = new List <Repositories.Common.Search.SearchResult <ScenarioIndex> >
                {
                    new Repositories.Common.Search.SearchResult <ScenarioIndex>
                    {
                        Result = new ScenarioIndex
                        {
                            LastUpdatedDate = null
                        }
                    }
                }
            };

            ISearchRepository <ScenarioIndex> searchRepository = CreateSearchRepository();

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

            ILogger logger = CreateLogger();

            ScenariosSearchService service = CreateSearchService(searchRepository, logger: logger);

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

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

            OkObjectResult okObjectResult = result as OkObjectResult;
        }
Exemplo n.º 5
0
        public async Task SearchSpecifications_GivenNullSearchModel_ReturnsBadRequest()
        {
            //Arrange
            ILogger logger = CreateLogger();

            ScenariosSearchService service = CreateSearchService(logger: logger);

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

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

            result
            .Should()
            .BeOfType <BadRequestObjectResult>();
        }
Exemplo n.º 6
0
        async public Task SearchScenarios_GivenSearchReturnsResultsAndDataLastUpdateIsNull_ReturnsOKResult()
        {
            //Arrange
            SearchModel model = CreateSearchModel();

            SearchResults <ScenarioIndex> searchResults = new SearchResults <ScenarioIndex>
            {
                TotalCount = 1,
                Results    = new List <Repositories.Common.Search.SearchResult <ScenarioIndex> >
                {
                    new Repositories.Common.Search.SearchResult <ScenarioIndex>
                    {
                        Result = new ScenarioIndex
                        {
                            LastUpdatedDate = null
                        }
                    }
                }
            };

            ISearchRepository <ScenarioIndex> searchRepository = CreateSearchRepository();

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

            ILogger logger = CreateLogger();

            ScenariosSearchService service = CreateSearchService(searchRepository, logger: logger);

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

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

            OkObjectResult okObjectResult = result as OkObjectResult;
        }
        async public Task SearchScenarios_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 <ScenarioIndex> 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();

            ScenariosSearchService service = CreateSearchService(searchRepository, logger: logger);

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

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

            statusCodeResult
            .StatusCode
            .Should()
            .Be(500);
        }
Exemplo n.º 8
0
        public async Task SearchScenarios_GivenInvalidTop_ReturnsBadRequest()
        {
            //Arrange
            SearchModel model = new SearchModel
            {
                PageNumber = 1,
                Top        = 0
            };
            ILogger logger = CreateLogger();

            ScenariosSearchService service = CreateSearchService(logger: logger);

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

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

            result
            .Should()
            .BeOfType <BadRequestObjectResult>();
        }