Exemple #1
0
        public void TestScenarioResultsService_PerformSearch_WhenRowCountsApiCallContentIsNull_ThenExceptionThrown()
        {
            // Arrange
            IScenarioSearchService   searchService       = CreateScenarioSearchService();
            ISpecificationsApiClient specsApiClient      = CreateSpecsApiClient();
            ITestEngineApiClient     testEngineApiClient = CreateTestEngineApiClient();
            ILogger logger = CreateLogger();

            TestScenarioResultRequestViewModel resultRequestViewModel = new TestScenarioResultRequestViewModel()
            {
                SearchTerm      = "",
                PageNumber      = 1,
                FundingPeriodId = null,
                SpecificationId = null,
            };

            TestScenarioResultsService testScenarioResultsService = CreateService(searchService, specsApiClient, testEngineApiClient, logger: logger);

            searchService.PerformSearch(Arg.Any <SearchRequestViewModel>())
            .Returns(new ScenarioSearchResultViewModel()
            {
                Scenarios = new List <ScenarioSearchResultItemViewModel>()
                {
                    new ScenarioSearchResultItemViewModel()
                    {
                        Id   = "s1",
                        Name = "S1",
                    },
                    new ScenarioSearchResultItemViewModel()
                    {
                        Id   = "s2",
                        Name = "S2",
                    },
                }
            });

            List <SpecificationSummary> specifications = CreateSpecifications();

            specsApiClient
            .GetSpecificationSummaries()
            .Returns(new ApiResponse <IEnumerable <SpecificationSummary> >(HttpStatusCode.OK, specifications));

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

            // Act
            Func <Task> action = async() => await testScenarioResultsService.PerformSearch(resultRequestViewModel);

            // Assert
            action.
            Should()
            .ThrowExactly <InvalidOperationException>()
            .WithMessage("Row counts api request failed with null content");

            logger
            .Received(1)
            .Warning(Arg.Is("Row counts api request failed with null content"));
        }
        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);
        }
        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>());
        }
Exemple #5
0
        public async Task TestScenarioResultsService_PerformSearch_WhenTestScenariosExist_ThenResultsAreReturned()
        {
            // Arrange
            IScenarioSearchService   searchService       = CreateScenarioSearchService();
            ISpecificationsApiClient specsApiClient      = CreateSpecsApiClient();
            ITestEngineApiClient     testEngineApiClient = CreateTestEngineApiClient();

            TestScenarioResultsService testScenarioResultsService = CreateService(searchService, specsApiClient, testEngineApiClient);

            TestScenarioResultRequestViewModel resultRequestViewModel = new TestScenarioResultRequestViewModel()
            {
                SearchTerm      = "",
                PageNumber      = 1,
                FundingPeriodId = null,
                SpecificationId = null,
            };

            ScenarioSearchResultViewModel scenarioSearchResultViewModel = new ScenarioSearchResultViewModel()
            {
                CurrentPage     = 1,
                TotalResults    = 1,
                StartItemNumber = 1,
                EndItemNumber   = 1,
                Scenarios       = new List <ScenarioSearchResultItemViewModel>()
                {
                    new ScenarioSearchResultItemViewModel()
                    {
                        Id   = "ts1",
                        Name = "Test Scenario 1",
                        FundingPeriodName = "2018/2019",
                        Status            = "Passed",
                        SpecificationName = "Specifcation 1",
                        LastUpdatedDate   = new DateTime(2018, 1, 5, 7, 8, 9),
                    }
                }
            };

            searchService.PerformSearch(Arg.Is <SearchRequestViewModel>(s => s.SearchTerm == resultRequestViewModel.SearchTerm))
            .Returns(scenarioSearchResultViewModel);

            List <SpecificationSummary> specifications = CreateSpecifications();

            specsApiClient
            .GetSpecificationSummaries()
            .Returns(new ApiResponse <IEnumerable <SpecificationSummary> >(HttpStatusCode.OK, specifications.AsEnumerable()));

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

            testScenarioResultCounts.Add(new TestScenarioResultCounts()
            {
                Passed           = 5,
                Failed           = 10,
                Ignored          = 50,
                LastUpdatedDate  = new DateTime(2018, 10, 5, 7, 8, 9),
                TestScenarioId   = "ts1",
                TestScenarioName = "Test Scenario 1",
            });

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

            // Act
            TestScenarioResultViewModel resultViewModel = await testScenarioResultsService.PerformSearch(resultRequestViewModel);

            // Assert
            resultViewModel.Should().NotBeNull();

            TestScenarioResultViewModel expectedResult = new TestScenarioResultViewModel()
            {
                CurrentPage     = 1,
                EndItemNumber   = 1,
                Facets          = new List <SearchFacetViewModel>(),
                FundingPeriodId = null,
                Specifications  = new List <ReferenceViewModel>()
                {
                    new ReferenceViewModel("spec1", "Specification 1"),
                    new ReferenceViewModel("spec2", "Specification 2"),
                    new ReferenceViewModel("spec3", "Specification for 2018/2019"),
                },
                StartItemNumber = 1,
                TotalResults    = 1,
                TestResults     = new List <TestScenarioResultItemViewModel>()
                {
                    new TestScenarioResultItemViewModel()
                    {
                        Id              = "ts1",
                        Name            = "Test Scenario 1",
                        Passes          = 5,
                        Failures        = 10,
                        Ignored         = 50,
                        LastUpdatedDate = new DateTime(2018, 1, 5, 7, 8, 9),
                    }
                }
            };

            resultViewModel.Should().BeEquivalentTo(expectedResult);

            await specsApiClient
            .Received(1)
            .GetSpecificationSummaries();
        }
        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());
        }
        public async Task <TestScenarioResultViewModel> PerformSearch(TestScenarioResultRequestViewModel request)
        {
            Guard.ArgumentNotNull(request, nameof(request));

            SearchRequestViewModel searchRequest = new SearchRequestViewModel()
            {
                IncludeFacets = false,
                SearchTerm    = request.SearchTerm,
                Filters       = request.Filters,
                PageNumber    = request.PageNumber,
                PageSize      = 20,
                SearchMode    = SearchMode.All
            };

            if (searchRequest.Filters == null)
            {
                searchRequest.Filters = new Dictionary <string, string[]>();
            }

            SetFilterValue(searchRequest, "specificationId", request.SpecificationId);
            SetFilterValue(searchRequest, "fundingPeriodId", request.FundingPeriodId);

            Task <ScenarioSearchResultViewModel> scenarioSearchResultsTask = _scenariosSearchService.PerformSearch(searchRequest);
            Task <ApiResponse <IEnumerable <SpecificationSummary> > > specificationsLookupTask;

            if (string.IsNullOrWhiteSpace(request.FundingPeriodId))
            {
                specificationsLookupTask = _specsClient.GetSpecificationSummaries();
            }
            else
            {
                specificationsLookupTask = _specsClient.GetSpecifications(request.FundingPeriodId);
            }

            await TaskHelper.WhenAllAndThrow(scenarioSearchResultsTask, specificationsLookupTask);

            ScenarioSearchResultViewModel scenarioSearchResults = scenarioSearchResultsTask.Result;

            if (scenarioSearchResults == null)
            {
                _logger.Warning("Scenario Search Results response was null");
                throw new InvalidOperationException("Scenario Search Results response was null");
            }

            ApiResponse <IEnumerable <SpecificationSummary> > specificationsApiResponse = specificationsLookupTask.Result;

            if (specificationsApiResponse == null)
            {
                _logger.Warning("Specifications API Response was null");
                throw new InvalidOperationException("Specifications API Response was null");
            }

            if (specificationsApiResponse.StatusCode != HttpStatusCode.OK)
            {
                _logger.Warning("Specifications API Response content did not return OK, but instead {specificationsApiResponse.StatusCode}", specificationsApiResponse.StatusCode);
                throw new InvalidOperationException($"Specifications API Response content did not return OK, but instead '{specificationsApiResponse.StatusCode}'");
            }

            if (specificationsApiResponse.Content == null)
            {
                _logger.Warning("Specifications API Response content was null");
                throw new InvalidOperationException("Specifications API Response content was null");
            }

            IEnumerable <string>        testScenarioIds = scenarioSearchResults.Scenarios.Select(s => s.Id);
            TestScenarioResultViewModel result          = _mapper.Map <TestScenarioResultViewModel>(scenarioSearchResults);

            List <ReferenceViewModel> specifications = new List <ReferenceViewModel>();

            foreach (SpecificationSummary specification in specificationsApiResponse.Content.OrderBy(s => s.Name))
            {
                specifications.Add(new ReferenceViewModel(specification.Id, specification.Name));
            }

            result.Specifications = specifications;

            if (testScenarioIds.Any())
            {
                ApiResponse <IEnumerable <TestScenarioResultCounts> > rowCounts = await _testEngineClient.GetTestResultCounts(new TestScenarioResultCountsRequestModel()
                {
                    TestScenarioIds = testScenarioIds,
                });

                if (rowCounts == null)
                {
                    _logger.Warning("Row counts api request failed with null response");
                    throw new InvalidOperationException($"Row counts api request failed with null response");
                }

                if (rowCounts.StatusCode != HttpStatusCode.OK)
                {
                    _logger.Warning("Row counts api request failed with status code: {rowCounts.StatusCode}", rowCounts.StatusCode);
                    throw new InvalidOperationException($"Row counts api request failed with status code: {rowCounts.StatusCode}");
                }

                if (rowCounts.Content == null)
                {
                    _logger.Warning("Row counts api request failed with null content");
                    throw new InvalidOperationException($"Row counts api request failed with null content");
                }

                foreach (TestScenarioResultItemViewModel vm in result.TestResults)
                {
                    TestScenarioResultCounts counts = rowCounts.Content.Where(r => r.TestScenarioId == vm.Id).FirstOrDefault();
                    if (counts != null)
                    {
                        vm.Failures = counts.Failed;
                        vm.Passes   = counts.Passed;
                        vm.Ignored  = counts.Ignored;
                    }
                }
            }

            return(result);
        }