public void OnGetAsync_ReturnsErrorWhenFundingPeriodResponseIsNull()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            ITestScenarioSearchService searchService = CreateTestScenarioSearchService();

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

            Provider provider = CreateProvider();

            IEnumerable <Reference> fundingPeriods = null;

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

            SearchRequestViewModel searchRequest = CreateSearchRequest();

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

            // Act
            Func <Task> test = async() => await providerScenarioResultsPageModel.OnGetAsync("2", 1, "", "1819", "1");

            // Assert
            test
            .Should()
            .ThrowExactly <System.InvalidOperationException>().WithMessage("Unable to retreive Periods: Status Code = NotFound");
        }
        public void OnGetAsync_GivenNullProviderId_Returns_ArgumentNullExceptionThrown()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            ITestScenarioSearchService searchService = CreateTestScenarioSearchService();

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

            // Act - Assert
            Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await providerScenarioResultsPageModel.OnGetAsync(null, 1, "", "1819", "1"));
        }
        public async Task OnGetAsync_WithValidProviderResultsReturned_PopulatesProviderDetails()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            ITestScenarioSearchService searchService = CreateTestScenarioSearchService();

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

            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("2")
            .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>()));

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

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

            providerScenarioResultsPageModel.ProviderInfoModel.Should().NotBeNull();
            providerScenarioResultsPageModel.ProviderInfoModel.Upin.Should().Be(234234);
            providerScenarioResultsPageModel.ProviderInfoModel.Ukprn.Should().Be(345345);
            providerScenarioResultsPageModel.ProviderInfoModel.Urn.Should().Be(2234);
            providerScenarioResultsPageModel.ProviderInfoModel.ProviderType.Should().Be("Academy");
        }
        public async Task OnGetAsync_WithNullProviderResultsReturned_ReturnsStatusCode500()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            ITestScenarioSearchService searchService = CreateTestScenarioSearchService();

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

            Provider provider = null;

            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("2")
            .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary));

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

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

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

            // Assert
            actionResult
            .Should()
            .BeOfType <StatusCodeResult>().Which.StatusCode.Should().Be(500);
        }
        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]
                                                                                          ));
        }