public async Task <IActionResult> SearchTestScenarios([FromBody] SearchRequestViewModel request)
        {
            Guard.ArgumentNotNull(request, nameof(request));

            TestScenarioSearchResultViewModel result = await _testScenarioSearchService.PerformSearch(request);

            if (result != null)
            {
                return(Ok(result));
            }
            else
            {
                return(new StatusCodeResult(500));
            }
        }
예제 #2
0
        public async Task SearchTestScenarios_GivenResultsReturnedFromSearch_ReturnsOK()
        {
            // Arrange
            SearchRequestViewModel requestModel = new SearchRequestViewModel();

            TestScenarioSearchResultViewModel results = new TestScenarioSearchResultViewModel();

            ITestScenarioSearchService searchService = CreateTestScenarioSearchService();

            searchService
            .PerformSearch(Arg.Any <SearchRequestViewModel>())
            .Returns(results);

            TestScenarioSearchController controller = CreateController(searchService);

            // Act
            IActionResult actionResult = await controller.SearchTestScenarios(requestModel);

            // Asserts
            actionResult
            .Should()
            .BeOfType <OkObjectResult>();
        }
        public async Task <TestScenarioSearchResultViewModel> PerformSearch(SearchRequestViewModel request)
        {
            SearchFilterRequest requestOptions = new SearchFilterRequest()
            {
                Page          = request.PageNumber.HasValue ? request.PageNumber.Value : 1,
                PageSize      = request.PageSize.HasValue ? request.PageSize.Value : 50,
                SearchTerm    = request.SearchTerm,
                IncludeFacets = false,
                Filters       = request.Filters,
                SearchFields  = new string[] { "TestScenarioName" }
            };

            if (request.PageNumber.HasValue && request.PageNumber.Value > 0)
            {
                requestOptions.Page = request.PageNumber.Value;
            }

            PagedResult <TestScenarioSearchResultItem> TestScenarioResult = await _testEngineApiClient.FindTestScenariosForProvider(requestOptions);

            if (TestScenarioResult == null)
            {
                _logger.Error("Find Test Scenarios HTTP request failed");
                return(null);
            }

            TestScenarioSearchResultViewModel results = new TestScenarioSearchResultViewModel
            {
                TotalResults = TestScenarioResult.TotalItems,
                CurrentPage  = TestScenarioResult.PageNumber
            };

            IList <SearchFacetViewModel> searchFacets = new List <SearchFacetViewModel>();

            if (TestScenarioResult.Facets != null)
            {
                foreach (SearchFacet facet in TestScenarioResult.Facets)
                {
                    searchFacets.Add(_mapper.Map <SearchFacetViewModel>(facet));
                }
            }

            results.Facets = searchFacets.AsEnumerable();

            List <TestScenarioSearchResultItemViewModel> itemResults = new List <TestScenarioSearchResultItemViewModel>();

            foreach (TestScenarioSearchResultItem searchResult in TestScenarioResult.Items)
            {
                itemResults.Add(_mapper.Map <TestScenarioSearchResultItemViewModel>(searchResult));
            }

            itemResults.OrderBy(f => f.LastUpdatedDate);

            results.TestScenarios = itemResults.AsEnumerable();

            if (results.TotalResults == 0)
            {
                results.StartItemNumber = 0;
                results.EndItemNumber   = 0;
            }
            else
            {
                results.StartItemNumber = ((requestOptions.Page - 1) * requestOptions.PageSize) + 1;
                results.EndItemNumber   = results.StartItemNumber + requestOptions.PageSize - 1;
            }

            if (results.EndItemNumber > TestScenarioResult.TotalItems)
            {
                results.EndItemNumber = TestScenarioResult.TotalItems;
            }

            results.PagerState = new PagerState(requestOptions.Page, TestScenarioResult.TotalPages, 4);

            return(results);
        }
        public async Task OnGetAsync_WhenTestScenariosSearchResultsFoundThenTestCoverageIsCalculated_ThenSuccessfullyShown()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            ITestScenarioSearchService searchService = CreateTestScenarioSearchService();

            Provider provider = CreateProvider();

            IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") };

            IEnumerable <string> specSummary = GetSpecificationsWithResults();

            specsClient.GetFundingPeriods()
            .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods));

            resultsApiClient.GetSpecificationIdsForProvider(Arg.Any <string>())
            .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary));

            resultsApiClient.GetProviderByProviderId(Arg.Any <string>())
            .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider));

            IList <TestScenarioSearchResultItemViewModel> testScenarioSearchResultItems = GetTestScenarioSearchResults();
            TestScenarioSearchResultItemViewModel         ignoredItem = new TestScenarioSearchResultItemViewModel()
            {
                Id = "3",
                LastUpdatedDate        = new DateTime(12, 01, 23),
                ProviderId             = "1",
                ProviderName           = "Provider 1",
                SpecificationId        = "2",
                SpecificationName      = "Spec 02",
                TestResult             = "Ignored",
                TestScenarioId         = "2",
                TestScenarioName       = "Test Scenario 02",
                LastUpdatedDateDisplay = "1",
            };

            testScenarioSearchResultItems.Add(ignoredItem);

            TestScenarioSearchResultItemViewModel failedItem = new TestScenarioSearchResultItemViewModel()
            {
                Id = "4",
                LastUpdatedDate        = new DateTime(12, 01, 23),
                ProviderId             = "1",
                ProviderName           = "Provider 1",
                SpecificationId        = "2",
                SpecificationName      = "Spec 02",
                TestResult             = "Failed",
                TestScenarioId         = "2",
                TestScenarioName       = "Test Scenario 02",
                LastUpdatedDateDisplay = "1",
            };

            testScenarioSearchResultItems.Add(failedItem);

            string specificationId = "2";

            TestScenarioSearchResultViewModel results = new TestScenarioSearchResultViewModel()
            {
                TestScenarios = testScenarioSearchResultItems,
                TotalResults  = 4,
                CurrentPage   = 1,
            };

            SearchRequestViewModel searchRequest = CreateSearchRequest();

            searchRequest.Filters["specificationId"][0] = specificationId;

            searchService.PerformSearch(Arg.Any <SearchRequestViewModel>())
            .Returns(results);

            specsClient
            .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >())
            .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>()));

            ProviderScenarioResultsPageModel providerScenarioResultsPageModel = CreatePageModel(searchService, resultsApiClient, specsApiClient: specsClient);

            //Act
            IActionResult actionResult = await providerScenarioResultsPageModel.OnGetAsync("1", 1, "", "1819", specificationId);

            // Assert
            actionResult
            .Should()
            .BeOfType <PageResult>();

            providerScenarioResultsPageModel.Passed.Should().Be(2);
            providerScenarioResultsPageModel.Failed.Should().Be(1);
            providerScenarioResultsPageModel.Ignored.Should().Be(1);
            providerScenarioResultsPageModel.TestCoverage.Should().Be(75);
        }
        public async Task OnGetAsync_WhenTestScenariosSearchResultsFound_ThenSuccessfullyShown()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            ITestScenarioSearchService searchService = CreateTestScenarioSearchService();

            Provider provider = CreateProvider();

            IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") };

            IEnumerable <string> specSummary = GetSpecificationsWithResults();

            specsClient.GetFundingPeriods()
            .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods));

            resultsApiClient.GetSpecificationIdsForProvider(Arg.Any <string>())
            .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary));

            resultsApiClient.GetProviderByProviderId(Arg.Any <string>())
            .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider));

            specsClient
            .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >())
            .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>()));

            IList <TestScenarioSearchResultItemViewModel> testScenarioSearchResultItems = GetTestScenarioSearchResults();

            string specificationId = "2";

            TestScenarioSearchResultViewModel results = new TestScenarioSearchResultViewModel()
            {
                TestScenarios = testScenarioSearchResultItems,
                TotalResults  = 2,
                CurrentPage   = 1,
            };

            SearchRequestViewModel searchRequest = CreateSearchRequest();

            searchRequest.Filters["specificationId"][0] = specificationId;

            searchService.PerformSearch(Arg.Any <SearchRequestViewModel>())
            .Returns(results);

            ProviderScenarioResultsPageModel providerScenarioResultsPageModel = CreatePageModel(searchService, resultsApiClient, specsApiClient: specsClient);

            //Act
            IActionResult actionResult = await providerScenarioResultsPageModel.OnGetAsync("1", 1, "", "1819", specificationId);

            // Assert
            actionResult
            .Should()
            .BeOfType <PageResult>();

            providerScenarioResultsPageModel.TestScenarioSearchResults.Should().NotBeNull();
            providerScenarioResultsPageModel.FundingPeriods.Count().Should().Be(3);

            await searchService.Received(1).PerformSearch(Arg.Is <SearchRequestViewModel>(r =>
                                                                                          r.PageNumber == searchRequest.PageNumber &&
                                                                                          r.IncludeFacets == searchRequest.IncludeFacets &&
                                                                                          r.SearchTerm == searchRequest.SearchTerm &&
                                                                                          r.Filters["providerId"][0] == searchRequest.Filters["providerId"][0] &&
                                                                                          r.Filters["specificationId"][0] == searchRequest.Filters["specificationId"][0]
                                                                                          ));
        }
        public async Task <IActionResult> OnGetAsync(string providerId, int?pageNumber, string searchTerm = null, string fundingPeriodId = null, string specificationId = null)
        {
            Guard.IsNullOrWhiteSpace(providerId, nameof(providerId));

            ProviderId = providerId;

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

            Task populatePeriodsTask = PopulateFundingPeriods(fundingPeriodId);

            Task <ApiResponse <Provider> > apiResponseTask = _resultsApiClient.GetProviderByProviderId(providerId);


            await TaskHelper.WhenAllAndThrow(populatePeriodsTask, apiResponseTask);

            if (string.IsNullOrWhiteSpace(fundingPeriodId))
            {
                fundingPeriodId = FundingPeriods?.First().Value;
            }

            FundingPeriodId = fundingPeriodId;

            await PopulateSpecifications(providerId, specificationId);

            SpecificationId = specificationId;

            ApiResponse <Provider> apiResponse = apiResponseTask.Result;

            if (apiResponse != null && apiResponse.StatusCode == HttpStatusCode.OK && apiResponse.Content != null)
            {
                Provider response = apiResponse.Content;

                ProviderViewModel providerViewModel = _mapper.Map <ProviderViewModel>(apiResponse.Content);

                ProviderInfoModel = providerViewModel;
            }
            else
            {
                _logger.Error("Provider response content is null");
                return(new StatusCodeResult(500));
            }

            if (!string.IsNullOrWhiteSpace(specificationId))
            {
                TestScenarioSearchResults = await _testScenarioSearchService.PerformSearch(searchRequest);

                if (TestScenarioSearchResults != null)
                {
                    Passed  = TestScenarioSearchResults.TestScenarios.Where(c => c.TestResult == "Passed").Count();
                    Failed  = TestScenarioSearchResults.TestScenarios.Where(c => c.TestResult == "Failed").Count();
                    Ignored = TestScenarioSearchResults.TestScenarios.Where(c => c.TestResult == "Ignored").Count();

                    int totalRecords = Passed + Failed + Ignored;
                    if (totalRecords > 0)
                    {
                        TestCoverage = Math.Round((decimal)(Passed + Failed) / totalRecords * 100, 1);
                    }
                }
            }

            return(Page());
        }