Ejemplo n.º 1
0
        public void CompileTestScenario_GivenResultFailedThrowsInvalidOperationException()
        {
            //Arrange
            const string specificationId = "test-spec";

            ScenarioCompileViewModel viewModel = new ScenarioCompileViewModel();

            ScenarioCompileModel compileModel = new ScenarioCompileModel();

            IMapper mapper = CreateMapper();

            mapper
            .Map <ScenarioCompileModel>(Arg.Is(viewModel))
            .Returns(compileModel);

            ApiResponse <IEnumerable <ScenarioCompileError> > result = new ApiResponse <IEnumerable <ScenarioCompileError> >(HttpStatusCode.BadRequest);
            ITestEngineApiClient apiClient = CreateApiClient();

            apiClient
            .CompileScenario(Arg.Is(compileModel))
            .Returns(result);

            TestEngineController controller = CreateController(mapper: mapper, testEngineApiClient: apiClient);

            //Act
            Func <Task> test = async() => await controller.CompileTestScenario(specificationId, viewModel);

            //Assert
            test
            .Should()
            .ThrowExactly <InvalidOperationException>();
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CompileTestScenario(string specificationId, [FromBody] ScenarioCompileViewModel vm)
        {
            Guard.ArgumentNotNull(specificationId, nameof(specificationId));
            Guard.ArgumentNotNull(vm, nameof(vm));

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

            ScenarioCompileModel compileModel = _mapper.Map <ScenarioCompileModel>(vm);

            compileModel.SpecificationId = specificationId;

            ApiResponse <IEnumerable <ScenarioCompileError> > result = await _testEngineApiClient.CompileScenario(compileModel);

            if (result.StatusCode == HttpStatusCode.OK)
            {
                return(Ok(result.Content));
            }
            else
            {
                throw new InvalidOperationException($"An error occurred while compiling scenario test. Status code={result.StatusCode}");
            }
        }
Ejemplo n.º 3
0
        public async Task CompileTestScenario_GivenResultFromApiIsOK_ReturnsOKObjectResult()
        {
            //Arrange
            const string specificationId = "test-spec";

            ScenarioCompileViewModel viewModel = new ScenarioCompileViewModel();

            ScenarioCompileModel compileModel = new ScenarioCompileModel();

            IMapper mapper = CreateMapper();

            mapper
            .Map <ScenarioCompileModel>(Arg.Is(viewModel))
            .Returns(compileModel);

            ApiResponse <IEnumerable <ScenarioCompileError> > result = new ApiResponse <IEnumerable <ScenarioCompileError> >(HttpStatusCode.OK);
            ITestEngineApiClient apiClient = CreateApiClient();

            apiClient
            .CompileScenario(Arg.Is(compileModel))
            .Returns(result);

            TestEngineController controller = CreateController(mapper: mapper, testEngineApiClient: apiClient);

            //Act
            IActionResult actionResult = await controller.CompileTestScenario(specificationId, viewModel);

            //Assert
            actionResult
            .Should()
            .BeAssignableTo <OkObjectResult>();
        }