Beispiel #1
0
        public async void UpdateJobTaskOrder_ReturnsSuccess()
        {
            _jobDefinitionService.Setup(s => s.GetJobTaskDefinitions(It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <JobTaskDefinition>
            {
                new JobTaskDefinition
                {
                    Id   = 1,
                    Name = "Generate"
                },
                new JobTaskDefinition
                {
                    Id   = 2,
                    Name = "Push"
                }
            });

            _jobDefinitionService.Setup(s => s.UpdateJobTaskDefinition(It.IsAny <JobTaskDefinition>(), It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);

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

            var result = await controller.UpdateJobTaskOrder(1, 1, new UpdateTaskOrderDto()
            {
                TaskOrders = new Dictionary <int, int>
                {
                    { 2, 1 },
                    { 1, 2 }
                }
            });

            Assert.IsType <OkResult>(result);
        }
Beispiel #2
0
        public async void CreateJobTaskDefinitions_ReturnsCreatedJobTaskDefinitions()
        {
            _jobDefinitionService
            .Setup(s => s.AddJobTaskDefinitions(It.IsAny <int>(), It.IsAny <List <JobTaskDefinition> >(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <int> {
                1
            });

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

            var dto = new List <CreateJobTaskDefinitionDto>
            {
                new CreateJobTaskDefinitionDto
                {
                    Name = "Generate"
                }
            };

            var result = await controller.CreateJobTaskDefinitions(1, 1, dto);

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

            Assert.NotEmpty(returnValue);
        }
Beispiel #3
0
        public async void SetJobDefinitionAsDefault_ReturnsSuccess()
        {
            _jobDefinitionService.Setup(s => s.SetJobDefinitionAsDefault(It.IsAny <int>(), It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);

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

            var result = await controller.SetJobDefinitionAsDefault(1, 1);

            Assert.IsType <OkResult>(result);
        }
Beispiel #4
0
        public async void UpdateJobTaskConfig_ReturnsBadRequest()
        {
            var controller = new JobDefinitionController(_jobDefinitionService.Object, _mapper, _logger.Object);

            var result = await controller.UpdateJobTaskConfig(1, 1, 1, new UpdateJobTaskConfigDto());

            var badRequestResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.Equal("Task Id doesn't match.", badRequestResult.Value);
        }
Beispiel #5
0
        public async void DeleteJobTaskDefinition_ReturnsNoContent()
        {
            _jobDefinitionService.Setup(s => s.DeleteJobTaskDefinition(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);

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

            var result = await controller.DeleteJobTaskDefinition(1, 1, 1);

            Assert.IsType <NoContentResult>(result);
        }
Beispiel #6
0
        public async void UpdateJobTaskConfig_ReturnsSuccess()
        {
            _jobDefinitionService.Setup(s => s.UpdateJobTaskConfig(It.IsAny <int>(), It.IsAny <Dictionary <string, string> >(), It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);

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

            var result = await controller.UpdateJobTaskConfig(1, 1, 1, new UpdateJobTaskConfigDto()
            {
                Id = 1
            });

            Assert.IsType <OkResult>(result);
        }
Beispiel #7
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);
        }
Beispiel #8
0
        public async void GetJobDefinitionById_ReturnsJobDefinition()
        {
            _jobDefinitionService.Setup(s => s.GetJobDefinitionById(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((int id, CancellationToken cancellationToken) =>
                          new JobDefinition
            {
                Id   = id,
                Name = "Default"
            });

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

            var result = await controller.GetJobDefinition(1, 1);

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

            Assert.Equal(1, returnValue.Id);
        }
Beispiel #9
0
        public async void GetJobDefinitions_ReturnsJobDefinitionList()
        {
            _jobDefinitionService.Setup(s => s.GetJobDefinitions(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <JobDefinition>
            {
                new JobDefinition
                {
                    Id   = 1,
                    Name = "Default"
                }
            });

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

            var result = await controller.GetJobDefinitions(1);

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

            Assert.NotEmpty(returnValue);
        }
Beispiel #10
0
        public async void GetJobTaskDefinitionByName_ReturnsJobTaskDefinition()
        {
            _jobDefinitionService.Setup(s => s.GetJobTaskDefinitionByName(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((int jobDefinitionId, string name, CancellationToken cancellationToken) =>
                          new JobTaskDefinition
            {
                Id              = 1,
                Name            = name,
                JobDefinitionId = jobDefinitionId
            });

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

            var result = await controller.GetJobTaskDefinition(1, 1, "Generate");

            var okActionResult = Assert.IsType <OkObjectResult>(result);
            var returnValue    = Assert.IsType <JobTaskDefinitionDto>(okActionResult.Value);

            Assert.Equal("Generate", returnValue.Name);
            Assert.Equal(1, returnValue.JobDefinitionId);
        }