示例#1
0
        public async Task <IActionResult> OnGetAsync(string testScenarioId)
        {
            Guard.IsNullOrWhiteSpace(testScenarioId, nameof(testScenarioId));

            TestScenario scenario = await GetCurrentScenario(testScenarioId);

            if (scenario == null)
            {
                _logger.Warning("Test scenario response is null");
                return(new NotFoundObjectResult("Test Scenario not found"));
            }

            DoesUserHavePermissionToSave = (await _authorizationHelper.DoesUserHavePermission(User, scenario, SpecificationActionTypes.CanEditQaTests)).ToString().ToLowerInvariant();

            SpecificationSummary specResponse = await GetSpecification(scenario.SpecificationId);

            if (specResponse == null)
            {
                return(new PreconditionFailedResult("Specification not found"));
            }

            EditScenarioViewModel = new ScenarioEditViewModel
            {
                Name = JavaScriptEncoder.Default.Encode(scenario.Name),

                Gherkin = JavaScriptEncoder.Default.Encode(scenario.Gherkin),

                Description = JavaScriptEncoder.Default.Encode(scenario.Description)
            };

            TestScenarioId    = testScenarioId;
            SpecificationId   = scenario.SpecificationId;
            SpecificationName = specResponse.Name;

            return(Page());
        }
        public async Task <IActionResult> SaveTestScenario(string specificationId, string testScenarioId, [FromBody] ScenarioEditViewModel vm)
        {
            Guard.ArgumentNotNull(specificationId, nameof(specificationId));
            Guard.ArgumentNotNull(vm, nameof(vm));

            if (!await _authorizationHelper.DoesUserHavePermission(User, specificationId, SpecificationActionTypes.CanEditQaTests))
            {
                return(new ForbidResult());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            TestScenarioUpdateModel editScenario = _mapper.Map <TestScenarioUpdateModel>(vm);

            editScenario.SpecificationId = specificationId;
            editScenario.Id = testScenarioId;

            ApiResponse <TestScenario> result = await _scenariosClient.UpdateTestScenario(editScenario);

            if (result.StatusCode == HttpStatusCode.OK)
            {
                return(Ok(result.Content));
            }
            else
            {
                HttpStatusCode statusCode = result.StatusCode;

                _logger.Error("An error occurred while updating scenario. Status code from backend={statusCode} for specification {specificationId}", statusCode, specificationId);

                throw new InvalidOperationException($"An error occurred while updating scenario. Status code={result.StatusCode}");
            }
        }