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}");
            }
        }
        public async Task SaveTestScenario_WhenUserDoesHaveEditQaTestPermission_ThenActionAllowed()
        {
            // Arrange
            string specificationId = "abc123";

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

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

            IScenariosApiClient scenariosClient = CreateScenariosClient();

            scenariosClient.UpdateTestScenario(Arg.Any <TestScenarioUpdateModel>())
            .Returns(new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario()));

            ScenarioController controller = CreateScenarioController(authorizationHelper: authorizationHelper, scenariosClient: scenariosClient);

            // Act
            IActionResult result = await controller.SaveTestScenario(specificationId, "test123", new ScenarioEditViewModel());

            // Assert
            result.Should().BeOfType <OkObjectResult>();
        }