public async Task <IActionResult> CreateJobDefinition(int projectId, CreateJobDefinitionDto newJobDefinition)
        {
            _logger.LogInformation("Creating job definition in project {projectId}. Request body: {@newJobDefinition}", projectId, newJobDefinition);

            try
            {
                var newJobDefinitionResponse = _mapper.Map <JobDefinitionDto>(newJobDefinition);
                newJobDefinitionResponse.ProjectId = projectId;
                newJobDefinitionResponse.Id        = await _jobDefinitionService.AddJobDefinition(projectId,
                                                                                                  newJobDefinition.Name,
                                                                                                  newJobDefinition.IsDeletion);

                return(CreatedAtRoute("GetJobDefinitionById", new
                {
                    projectId,
                    jobId = newJobDefinitionResponse.Id
                }, newJobDefinitionResponse));
            }
            catch (DuplicateJobDefinitionException dupEx)
            {
                _logger.LogWarning(dupEx, "Duplicate job definition name");
                return(BadRequest(dupEx.Message));
            }
            catch (ProjectNotFoundException projEx)
            {
                _logger.LogWarning(projEx, "Project not found");
                return(BadRequest(projEx.Message));
            }
            catch (MultipleDeletionJobException jobEx)
            {
                _logger.LogWarning(jobEx, "A deletion job definition is already exist. A project should only contain one deletion job definition.");
                return(BadRequest(jobEx.Message));
            }
        }
Beispiel #2
0
        public async void CreateJobDefinition_ReturnsCreatedJobDefinition()
        {
            _jobDefinitionService
            .Setup(s => s.AddJobDefinition(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(1);

            var controller = new JobDefinitionController(_jobDefinitionService.Object, _mapper, _logger.Object);

            var dto = new CreateJobDefinitionDto
            {
                Name = "Default"
            };
            var result = await controller.CreateJobDefinition(1, dto);

            var okActionResult = Assert.IsType <CreatedAtRouteResult>(result);
            var returnValue    = Assert.IsType <JobDefinitionDto>(okActionResult.Value);

            Assert.Equal(1, returnValue.Id);
        }
        public async Task <JobDefinitionDto> CreateJobDefinition(int projectId, CreateJobDefinitionDto dto)
        {
            var path = $"project/{projectId}/job";

            return(await Api.Post <CreateJobDefinitionDto, JobDefinitionDto>(path, dto));
        }