Esempio n. 1
0
        public async Task SearchProvider_GivenNullResultFromSearch_ReturnsStatusCode500()
        {
            //Arrange
            SearchRequestViewModel requestModel = new SearchRequestViewModel();

            ITestResultsSearchService resultsSearchService = CreateResultsSearchService();

            resultsSearchService
            .PerformProviderTestResultsSearch(Arg.Is(requestModel))
            .Returns((ProviderTestsSearchResultViewModel)null);

            TestEngineController testEngineController = CreateController(testResultsSearchService: resultsSearchService);

            //Act
            IActionResult result = await testEngineController.SearchProviders(requestModel);

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

            StatusCodeResult statusCodeResult = result as StatusCodeResult;

            statusCodeResult
            .StatusCode
            .Should()
            .Be(500);
        }
        public async Task OnGetAsync_GivenResultsIsNull_ReturnsStatusCodeResult500()
        {
            //Arrange
            ApiResponse <TestScenario> scenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario());

            IScenariosApiClient apiClient = CreateScenariosClient();

            apiClient
            .GetCurrentTestScenarioById(Arg.Is(Scenarioid))
            .Returns(scenario);

            TestScenarioViewModel scenarioViewModel = new TestScenarioViewModel();

            ITestResultsSearchService resultsService = CreateResultsService();

            resultsService
            .PerformProviderTestResultsSearch(Arg.Any <SearchRequestViewModel>())
            .Returns((ProviderTestsSearchResultViewModel)null);

            ViewProviderTestResultsPageModel pageModel = CreatePageModel(scenariosApiClient: apiClient);

            //Act
            IActionResult result = await pageModel.OnGetAsync(Scenarioid, null, "");

            //Assert
            result
            .Should()
            .BeOfType <InternalServerErrorResult>()
            .Which
            .Value
            .Should()
            .Be("Provider Results returned null");
        }
        public async Task OnGetAsync_GivenCountTaskReturnsNoItems_ThenCoverageIsSetCorrectly()
        {
            //Arrange
            ApiResponse <TestScenario> scenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario());

            IScenariosApiClient apiClient = CreateScenariosClient();

            apiClient
            .GetCurrentTestScenarioById(Arg.Is(Scenarioid))
            .Returns(scenario);

            ProviderTestsSearchResultViewModel viewModel = new ProviderTestsSearchResultViewModel();

            ITestResultsSearchService resultsService = CreateResultsService();

            resultsService
            .PerformProviderTestResultsSearch(Arg.Any <SearchRequestViewModel>())
            .Returns(viewModel);

            ITestEngineApiClient testEngineApiClient = CreateTestEngineClient();

            testEngineApiClient
            .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>())
            .Returns(new ApiResponse <IEnumerable <TestScenarioResultCounts> >(HttpStatusCode.OK, Enumerable.Empty <TestScenarioResultCounts>()));

            ISpecsApiClient specsApiClient = CreateSpecsClient();

            specsApiClient
            .GetSpecificationSummary(Arg.Any <string>())
            .Returns(new ApiResponse <Clients.SpecsClient.Models.SpecificationSummary>(HttpStatusCode.OK, new Clients.SpecsClient.Models.SpecificationSummary()));

            ViewProviderTestResultsPageModel pageModel = CreatePageModel(
                resultsService, testEngineApiClient,
                scenariosApiClient: apiClient,
                specsApiClient: specsApiClient);

            //Act
            IActionResult result = await pageModel.OnGetAsync(Scenarioid, null, "");

            //Assert
            result
            .Should()
            .BeOfType <PageResult>()
            .Which
            .Should()
            .NotBeNull();

            await testEngineApiClient
            .Received(1)
            .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>());

            pageModel
            .TestCoverage
            .Should()
            .Be(0);
        }
Esempio n. 4
0
        public async Task <IActionResult> SearchProviders([FromBody] SearchRequestViewModel request)
        {
            Guard.ArgumentNotNull(request, nameof(request));

            ProviderTestsSearchResultViewModel result = await _testResultsSearchService.PerformProviderTestResultsSearch(request);

            if (result != null)
            {
                return(Ok(result));
            }
            else
            {
                return(new StatusCodeResult(500));
            }
        }
        public async Task OnGetAsync_GivenResultsReturned_ReturnsPage()
        {
            //Arrange
            ApiResponse <TestScenario> scenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario());

            IScenariosApiClient scenariosClient = CreateScenariosClient();

            scenariosClient
            .GetCurrentTestScenarioById(Arg.Is(Scenarioid))
            .Returns(scenario);

            TestScenarioViewModel scenarioViewModel = new TestScenarioViewModel();

            ProviderTestsSearchResultViewModel viewModel = new ProviderTestsSearchResultViewModel();

            ITestResultsSearchService resultsService = CreateResultsService();

            resultsService
            .PerformProviderTestResultsSearch(Arg.Any <SearchRequestViewModel>())
            .Returns(viewModel);

            ITestEngineApiClient testEngineClient = CreateTestEngineClient();

            List <TestScenarioResultCounts> countResults = new List <TestScenarioResultCounts>();

            testEngineClient
            .GetTestResultCounts(Arg.Is <TestScenarioResultCountsRequestModel>(c => c.TestScenarioIds.Count() == 1 && c.TestScenarioIds.First() == Scenarioid))
            .Returns(new ApiResponse <IEnumerable <TestScenarioResultCounts> >(HttpStatusCode.OK, countResults));

            ISpecsApiClient specsApiClient = CreateSpecsClient();

            specsApiClient
            .GetSpecificationSummary(Arg.Any <string>())
            .Returns(new ApiResponse <Clients.SpecsClient.Models.SpecificationSummary>(HttpStatusCode.OK, new Clients.SpecsClient.Models.SpecificationSummary()));

            ViewProviderTestResultsPageModel pageModel = CreatePageModel(resultsService, testEngineClient, scenariosClient, specsApiClient: specsApiClient);

            //Act
            IActionResult result = await pageModel.OnGetAsync(Scenarioid, null, "");

            //Assert
            result
            .Should()
            .BeAssignableTo <PageResult>();
        }
        public async Task OnGetAsync_GivenCountTaskReturnsNullContent_ThenErrorIsReturned()
        {
            //Arrange
            ApiResponse <TestScenario> scenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario());

            IScenariosApiClient apiClient = CreateScenariosClient();

            apiClient
            .GetCurrentTestScenarioById(Arg.Is(Scenarioid))
            .Returns(scenario);

            ProviderTestsSearchResultViewModel viewModel = new ProviderTestsSearchResultViewModel();

            ITestResultsSearchService resultsService = CreateResultsService();

            resultsService
            .PerformProviderTestResultsSearch(Arg.Any <SearchRequestViewModel>())
            .Returns(viewModel);

            ITestEngineApiClient testEngineApiClient = CreateTestEngineClient();

            testEngineApiClient
            .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>())
            .Returns(new ApiResponse <IEnumerable <TestScenarioResultCounts> >(HttpStatusCode.OK, null));

            ViewProviderTestResultsPageModel pageModel = CreatePageModel(resultsService, testEngineApiClient, scenariosApiClient: apiClient);

            //Act
            IActionResult result = await pageModel.OnGetAsync(Scenarioid, null, "");

            //Assert
            result
            .Should()
            .BeOfType <InternalServerErrorResult>()
            .Which
            .Value
            .Should()
            .Be("Count Task result content was null");

            await testEngineApiClient
            .Received(1)
            .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>());
        }
Esempio n. 7
0
        public async Task SearchProvider_GivenNResultReturnedFromSearch_ReturnsOKResult()
        {
            //Arrange
            SearchRequestViewModel requestModel = new SearchRequestViewModel();

            ProviderTestsSearchResultViewModel viewModel = new ProviderTestsSearchResultViewModel();

            ITestResultsSearchService resultsSearchService = CreateResultsSearchService();

            resultsSearchService
            .PerformProviderTestResultsSearch(Arg.Is(requestModel))
            .Returns(viewModel);

            TestEngineController testEngineController = CreateController(testResultsSearchService: resultsSearchService);

            //Act
            IActionResult result = await testEngineController.SearchProviders(requestModel);

            //Assert
            result
            .Should()
            .BeAssignableTo <OkObjectResult>();
        }
        public async Task <IActionResult> OnGetAsync(string scenarioId, int?pageNumber, string searchTerm)
        {
            TestScenario = await GetTestScenario(scenarioId);

            if (TestScenario == null)
            {
                return(new NotFoundResult());
            }

            SearchRequestViewModel searchRequest = new SearchRequestViewModel()
            {
                PageNumber    = pageNumber,
                IncludeFacets = false,
                SearchTerm    = searchTerm,
                Filters       = new Dictionary <string, string[]> {
                    { "testScenarioId", new[] { scenarioId } }
                }
            };

            SearchTerm = searchTerm;

            Task <ProviderTestsSearchResultViewModel> providerResultsTask           = _testResultsSearchService.PerformProviderTestResultsSearch(searchRequest);
            Task <ApiResponse <IEnumerable <TestScenarioResultCounts> > > countTask = _testEngineClient.GetTestResultCounts(new TestScenarioResultCountsRequestModel()
            {
                TestScenarioIds = new string[] { scenarioId }
            });


            await TaskHelper.WhenAllAndThrow(providerResultsTask, countTask);

            ProviderResults = providerResultsTask.Result;

            if (ProviderResults == null)
            {
                return(new InternalServerErrorResult("Provider Results returned null"));
            }

            if (countTask.Result == null)
            {
                return(new InternalServerErrorResult("Count Task result was null"));
            }

            if (countTask.Result.StatusCode != System.Net.HttpStatusCode.OK)
            {
                return(new InternalServerErrorResult($"Count Task didn't return OK, but instead '{countTask.Result.StatusCode}'"));
            }

            if (countTask.Result.Content == null)
            {
                return(new InternalServerErrorResult("Count Task result content was null"));
            }

            TestScenarioResultCounts scenarioResultCounts = countTask.Result.Content.FirstOrDefault();

            if (scenarioResultCounts != null)
            {
                TestCoverage = scenarioResultCounts.TestCoverage;
            }
            else
            {
                TestCoverage = 0;
            }

            ApiResponse <SpecificationSummary> specResponse = await _specsClient.GetSpecificationSummary(TestScenario.SpecificationId);

            if (specResponse == null)
            {
                return(new InternalServerErrorResult("Specification summary API call result was null"));
            }

            if (specResponse.StatusCode != System.Net.HttpStatusCode.OK)
            {
                return(new InternalServerErrorResult($"Specification summary API call didn't return OK, but instead '{countTask.Result.StatusCode}'"));
            }

            if (specResponse.Content == null)
            {
                return(new InternalServerErrorResult("Specification summary API call content was null"));
            }

            Specification = _mapper.Map <SpecificationSummaryViewModel>(specResponse.Content);

            return(Page());
        }