Пример #1
0
        public async Task EditTestScenarioPageModel_OnGetAsync_GivenSpecificationNotFoundFromRepository_ReturnsPreconditionFailed()
        {
            // Arrange
            ApiResponse <TestScenario> testScenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario()
            {
                SpecificationId = SpecificationId
            });

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            specsClient
            .GetSpecificationSummary(Arg.Is(SpecificationId))
            .Returns(new ApiResponse <SpecificationSummary>(HttpStatusCode.NotFound, null));

            IScenariosApiClient scenarioClient = CreateScenarioApiClient();

            scenarioClient
            .GetCurrentTestScenarioById(Arg.Is(TestScenarioid))
            .Returns(testScenario);

            EditTestScenarioPageModel pageModel = CreatePageModel(specsClient, scenarioClient);

            // Act
            IActionResult result = await pageModel.OnGetAsync(TestScenarioid);

            // Assert
            result
            .Should()
            .BeOfType <PreconditionFailedResult>()
            .Which
            .Value
            .Should()
            .Be("Specification not found");
        }
Пример #2
0
        public async Task EditTestScenarioPageModel_OnGetAsync_GivenTestScenarioNotFoundFromRepository_ReturnsNotFoundResult()
        {
            //Arrange
            ApiResponse <TestScenario> testScenario = new ApiResponse <TestScenario>(HttpStatusCode.NotFound);

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            IScenariosApiClient scenarioClient = CreateScenarioApiClient();

            scenarioClient
            .GetCurrentTestScenarioById(Arg.Is(TestScenarioid))
            .Returns(testScenario);

            EditTestScenarioPageModel pageModel = CreatePageModel(specsClient, scenarioClient);

            //Act
            IActionResult result = await pageModel.OnGetAsync(TestScenarioid);

            //Assert
            result
            .Should()
            .BeOfType <NotFoundObjectResult>()
            .Which
            .Value
            .Should()
            .Be("Test Scenario not found");
        }
        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);
        }
        private async Task <TestScenarioViewModel> GetTestScenario(string scenarioId)
        {
            ApiResponse <TestScenario> scenario = await _scenariosApiClient.GetCurrentTestScenarioById(scenarioId);

            if (scenario.Content == null)
            {
                return(null);
            }

            return(_mapper.Map <TestScenarioViewModel>(scenario.Content));
        }
Пример #6
0
        private async Task <TestScenario> GetCurrentScenario(string testScenarioId)
        {
            Guard.IsNullOrWhiteSpace(testScenarioId, nameof(testScenarioId));

            ApiResponse <TestScenario> testScenarioResponse = await _scenariosClient.GetCurrentTestScenarioById(testScenarioId);

            if (testScenarioResponse != null && testScenarioResponse.StatusCode == HttpStatusCode.OK)
            {
                return(testScenarioResponse.Content);
            }

            return(null);
        }
        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>());
        }
        public async Task OnGetAsync_GivenScenarioNotReturned_ReturnsNotFoundResult()
        {
            //Arrange
            ApiResponse <TestScenario> scenario = new ApiResponse <TestScenario>(HttpStatusCode.NotFound);

            IScenariosApiClient apiClient = CreateScenariosClient();

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

            ViewProviderTestResultsPageModel pageModel = CreatePageModel(scenariosApiClient: apiClient);

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

            //Assert
            result
            .Should()
            .BeAssignableTo <NotFoundResult>();
        }
Пример #10
0
        public async Task EditTestScenarioPageModel_OnGetAsync_WhenUserDoesNotHaveEditQaTestPermission_ThenDoesUserHavePermissionToSaveisFalse()
        {
            // Arrange
            ApiResponse <TestScenario> testScenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario()
            {
                Description     = "Test Scenario for testing",
                Gherkin         = "Given test scenario Then validate test scenario",
                Id              = "100",
                Name            = "Test scenario for Spec - Test Spec",
                SpecificationId = SpecificationId,
                Author          = new Reference()
                {
                    Id = "", Name = ""
                },
                Version = 1
            });

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            IScenariosApiClient scenarioClient = CreateScenarioApiClient();

            scenarioClient
            .GetCurrentTestScenarioById(Arg.Is(TestScenarioid))
            .Returns(testScenario);

            IEnumerable <Reference> FundingStreamList = new[]
            {
                new Reference
                {
                    Id   = "fs1",
                    Name = "Funding Stream Name"
                }
            };

            SpecificationSummary specification = new SpecificationSummary()
            {
                Id             = SpecificationId,
                Name           = "Test Specification",
                FundingPeriod  = new Reference("1617", "2016/2017"),
                Description    = "Test Description",
                FundingStreams = FundingStreamList,
            };

            specsClient
            .GetSpecificationSummary(Arg.Is(SpecificationId))
            .Returns(new ApiResponse <SpecificationSummary>(HttpStatusCode.OK, specification));

            IAuthorizationHelper authorizationHelper = Substitute.For <IAuthorizationHelper>();

            authorizationHelper
            .DoesUserHavePermission(Arg.Any <ClaimsPrincipal>(), Arg.Any <ISpecificationAuthorizationEntity>(), Arg.Is(SpecificationActionTypes.CanEditQaTests))
            .Returns(false);

            EditTestScenarioPageModel pageModel = CreatePageModel(specsClient, scenarioClient, authorizationHelper: authorizationHelper);

            // Act
            await pageModel.OnGetAsync(TestScenarioid);

            // Assert
            pageModel.DoesUserHavePermissionToSave.Should().Be("false");
        }
Пример #11
0
        public async Task EditTestScenarioPageModel_OnGetAsync_GivenValidCurrentTestScenario_ThenPageIsReturned()
        {
            // Arrange
            ApiResponse <TestScenario> testScenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario()
            {
                Description     = "Test Scenario for testing",
                Gherkin         = "Given test scenario Then validate test scenario",
                Id              = "100",
                Name            = "Test scenario for Spec - Test Spec",
                SpecificationId = SpecificationId,
                Author          = new Reference()
                {
                    Id = "", Name = ""
                },
                Version = 1
            });

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            IScenariosApiClient scenarioClient = CreateScenarioApiClient();

            scenarioClient
            .GetCurrentTestScenarioById(Arg.Is(TestScenarioid))
            .Returns(testScenario);

            IEnumerable <Reference> FundingStreamList = new[]
            {
                new Reference
                {
                    Id   = "fs1",
                    Name = "Funding Stream Name"
                }
            };

            SpecificationSummary specification = new SpecificationSummary()
            {
                Id             = SpecificationId,
                Name           = "Test Specification",
                FundingPeriod  = new Reference("1617", "2016/2017"),
                Description    = "Test Description",
                FundingStreams = FundingStreamList,
            };

            specsClient
            .GetSpecificationSummary(Arg.Is(SpecificationId))
            .Returns(new ApiResponse <SpecificationSummary>(HttpStatusCode.OK, specification));

            EditTestScenarioPageModel pageModel = CreatePageModel(specsClient, scenarioClient);

            // Act
            IActionResult result = await pageModel.OnGetAsync(TestScenarioid);

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

            pageModel.TestScenarioId.Should().Be("scenario-id");
            pageModel.SpecificationId.Should().Be(SpecificationId);
            pageModel.SpecificationName.Should().Be("Test Specification");
            pageModel.EditScenarioViewModel.Description.Should().Be("Test Scenario for testing");
            pageModel.EditScenarioViewModel.Name.Should().Be("Test scenario for Spec - Test Spec");
            pageModel.EditScenarioViewModel.Gherkin.Should().Be("Given test scenario Then validate test scenario");
        }