public async void CreateJobTaskDefinition_ReturnsCreatedJobTaskDefinition() { _jobDefinitionService .Setup(s => s.AddJobTaskDefinition(It.IsAny <JobTaskDefinition>(), It.IsAny <CancellationToken>())) .ReturnsAsync(1); var controller = new JobDefinitionController(_jobDefinitionService.Object, _mapper, _logger.Object); var dto = new CreateJobTaskDefinitionDto { Name = "Generate" }; var result = await controller.CreateJobTaskDefinition(1, 1, dto); var okActionResult = Assert.IsType <CreatedAtRouteResult>(result); var returnValue = Assert.IsType <JobTaskDefinitionDto>(okActionResult.Value); Assert.Equal(1, returnValue.Id); }
public async Task <IActionResult> CreateJobTaskDefinition(int projectId, int jobId, CreateJobTaskDefinitionDto newTask) { // exclude additional configs since it may contain secret values var requestBodyToLog = new CreateJobTaskDefinitionDto { Name = newTask.Name, Configs = newTask.Configs, Provider = newTask.Provider, Sequence = newTask.Sequence, Type = newTask.Type }; _logger.LogRequest("Creating job task definition in job {jobId} in project {projectId}. Request body: {@requestBodyToLog}", jobId, projectId, requestBodyToLog); try { var entity = _mapper.Map <JobTaskDefinition>(newTask); entity.JobDefinitionId = jobId; entity.Id = await _jobDefinitionService.AddJobTaskDefinition(entity); var newJobTaskDefinitionResponse = _mapper.Map <JobTaskDefinitionDto>(entity); _logger.LogResponse("Job task definition in job {jobId} in project {projectId} created. Response body: {@newJobTaskDefinitionResponse}", jobId, projectId, newJobTaskDefinitionResponse); return(CreatedAtRoute("GetJobTaskDefinitionById", new { projectId, jobId, taskId = newJobTaskDefinitionResponse.Id }, newJobTaskDefinitionResponse)); } catch (DuplicateJobTaskDefinitionException dupTaskEx) { _logger.LogWarning(dupTaskEx, "Duplicate task name"); return(BadRequest(dupTaskEx.Message)); } catch (InvalidTaskProviderTypeException providerTypeEx) { _logger.LogWarning(providerTypeEx, "Invalid provider type"); return(BadRequest(providerTypeEx.Message)); } catch (JobDefinitionNotFoundException modEx) { _logger.LogWarning(modEx, "Job definition not found"); return(BadRequest(modEx.Message)); } catch (TaskProviderNotInstalledException provEx) { _logger.LogWarning(provEx, "Provider not installed"); return(BadRequest(provEx.Message)); } catch (ExternalServiceRequiredException esrEx) { _logger.LogWarning(esrEx, "External service required"); return(BadRequest(esrEx.Message)); } catch (ExternalServiceNotFoundException esnfEx) { _logger.LogWarning(esnfEx, "External service not found"); return(BadRequest(esnfEx.Message)); } catch (IncorrectExternalServiceTypeException iestEx) { _logger.LogWarning(iestEx, "Incorrect external service type"); return(BadRequest(iestEx.Message)); } catch (JobTaskDefinitionTypeException taskEx) { _logger.LogWarning(taskEx, "Incorrect task definition type"); return(BadRequest(taskEx.Message)); } catch (TaskConfigRequiredException tcEx) { _logger.LogWarning(tcEx, "Incorrect task config"); return(BadRequest(tcEx.Message)); } catch (TaskProviderAdditionalConfigRequiredException acReqEx) { _logger.LogWarning(acReqEx, "Incorrect task additional config"); return(BadRequest(acReqEx.Message)); } catch (TaskProviderAdditionalConfigAllowedValuesException avEx) { _logger.LogWarning(avEx, "Incorrect task additional config"); return(BadRequest(avEx.Message)); } }
public async Task <JobTaskDefinitionDto> CreateJobTaskDefinition(int projectId, int jobId, CreateJobTaskDefinitionDto dto) { var path = $"project/{projectId}/job/{jobId}/task"; return(await Api.Post <CreateJobTaskDefinitionDto, JobTaskDefinitionDto>(path, dto)); }