public async void CheckJob_ReturnsSuccess()
        {
            _jobQueueService.Setup(s => s.GetFirstUnassignedQueuedJob(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((string engineName, CancellationToken cancellationToken) =>
                          new JobQueue
            {
                CatapultEngineId = engineName
            });

            var httpContext = new DefaultHttpContext()
            {
                User = new ClaimsPrincipal(new[]
                {
                    new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Name, "Engine01"),
                        new Claim(ClaimTypes.Role, UserRole.Engine)
                    })
                }),
            };

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper, _logger.Object)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = httpContext
                }
            };

            var result = await controller.CheckJob();

            Assert.IsType <OkObjectResult>(result);

            _catapultEngineService.Verify(s => s.UpdateLastSeen("Engine01", null, It.IsAny <CancellationToken>()), Times.Once);
        }
예제 #2
0
        public async void UpdateJobQueue_ReturnsBadRequest()
        {
            _jobQueueService.Setup(s => s.UpdateJobQueue(It.IsAny <JobQueue>(), It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);

            _catapultEngineService.Setup(s => s.GetCatapultEngine(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((string name, CancellationToken cancellationToken) => new CatapultEngine
            {
                Name     = name,
                IsActive = true
            });

            var httpContext = new DefaultHttpContext()
            {
                User = new ClaimsPrincipal(new[]
                {
                    new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Name, "Engine01"),
                        new Claim(ClaimTypes.Role, UserRole.Engine)
                    })
                }),
            };

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper, _logger.Object)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = httpContext
                }
            };

            var result = await controller.UpdateJobQueue(1, new UpdateJobDto());

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

            Assert.Equal("Queue Id doesn't match.", badRequestResult.Value);
        }
예제 #3
0
        public async void CheckJob_UnregisteredEngine_ReturnsUnauthorized()
        {
            _catapultEngineService.Setup(s => s.GetCatapultEngine(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((CatapultEngine)null);

            var httpContext = new DefaultHttpContext()
            {
                User = new ClaimsPrincipal(new[]
                {
                    new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Name, "Engine01"),
                        new Claim(ClaimTypes.Role, UserRole.Engine)
                    })
                }),
            };

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper, _logger.Object)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = httpContext
                }
            };

            var result = await controller.CheckJob();

            Assert.IsType <UnauthorizedResult>(result);
        }
예제 #4
0
        public async void CreateJobQueue_ReturnsCreatedJobQueue()
        {
            _jobQueueService
            .Setup(s => s.AddJobQueue(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(1);
            _jobQueueService.Setup(s => s.GetJobQueueById(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((int projectId, int id, CancellationToken cancellationToken) =>
                          new JobQueue
            {
                Id        = id,
                ProjectId = projectId
            });

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper, _logger.Object);

            var result = await controller.CreateJobQueue(1, new NewJobDto
            {
                ProjectId = 1
            });

            var createAtRouteActionResult = Assert.IsType <CreatedAtRouteResult>(result);
            var returnValue = Assert.IsType <JobDto>(createAtRouteActionResult.Value);

            Assert.Equal(1, returnValue.Id);
        }
        public async void CreateJobQueue_ReturnsBadRequest()
        {
            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper, _configuration.Object, _logger.Object);

            var result = await controller.CreateJobQueue(1, new NewJobDto());

            var badRequestResult = Assert.IsType<BadRequestObjectResult>(result);
            Assert.Equal("Project Id doesn't match.", badRequestResult.Value);
        }
        public async void CancelJobQueue_ReturnsSuccess()
        {
            _jobQueueService.Setup(s => s.CancelJobQueue(It.IsAny <int>(), It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper, _logger.Object);

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

            Assert.IsType <OkResult>(result);
        }
예제 #7
0
 public IEnumerator Execute()
 {
     yield return(JobQueueController.Run(
                      _client,
                      _session,
                      _jobQueueNamespaceName,
                      _onRunJob,
                      _onError
                      ));
 }
        public async void UpdateJobQueue_ReturnsBadRequest()
        {
            _jobQueueService.Setup(s => s.UpdateJobQueue(It.IsAny <JobQueue>(), It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper, _logger.Object);

            var result = await controller.UpdateJobQueue(1, new UpdateJobDto());

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

            Assert.Equal("Queue Id doesn't match.", badRequestResult.Value);
        }
예제 #9
0
        public async void UpdateJobQueueWithProject_ReturnsSuccess()
        {
            _jobQueueService.Setup(s => s.UpdateJobQueue(It.IsAny <JobQueue>(), It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper, _logger.Object);

            var result = await controller.UpdateJobQueue(1, 1, new UpdateJobDto
            {
                Id = 1
            });

            Assert.IsType <OkResult>(result);
        }
        public async void SendNotification_ReturnsJobQueue()
        {
            _configuration.SetupGet(s => s[ConfigurationKey.WebUrl]).Returns("http://web");
            _jobQueueService.Setup(s => s.SendNotification(1, "http://web", It.IsAny<CancellationToken>()))
                .Returns(Task.CompletedTask);

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper,
                _configuration.Object, _logger.Object);

            var result = await controller.SendNotification(1);

            var okActionResult = Assert.IsType<OkResult>(result);
        }
        public async void GetJobLogs_ReturnsJobQueue()
        {
            _jobQueueService.Setup(s => s.GetJobLogs(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
                .ReturnsAsync("logs");

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper,
                _configuration.Object, _logger.Object);

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

            var okActionResult = Assert.IsType<OkObjectResult>(result);
            var returnValue = Assert.IsType<string>(okActionResult.Value);
            Assert.Equal("logs", returnValue);
        }
예제 #12
0
        public async void GetJobQueue_ReturnsJobQueue()
        {
            _jobQueueService.Setup(s => s.GetJobQueueById(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((int id, CancellationToken cancellationToken) =>
                          new JobQueue
            {
                Id = id
            });

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper,
                                                    _logger.Object);

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

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

            Assert.Equal(1, returnValue.Id);
        }
예제 #13
0
        public async void GetJobQueueByCode_ReturnsJobQueue()
        {
            _jobQueueService.Setup(s => s.GetJobQueueByCode(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((string code, CancellationToken cancellationToken) =>
                          new JobQueue
            {
                Id   = 1,
                Code = code
            });

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper,
                                                    _logger.Object);

            var result = await controller.GetJobQueueByCode(1, "20181101.1");

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

            Assert.Equal("20181101.1", returnValue.Code);
        }
        public async void GetJobQueues_ReturnsJobQueueList()
        {
            _jobQueueService.Setup(s => s.GetJobQueues(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
                .ReturnsAsync(new List<JobQueue>
                {
                    new JobQueue
                    {
                        Id = 1
                    }
                });

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper,
                _configuration.Object, _logger.Object);

            var result = await controller.GetJobQueues(1);

            var okActionResult = Assert.IsType<OkObjectResult>(result);
            var returnValue = Assert.IsType<List<JobDto>>(okActionResult.Value);
            Assert.NotEmpty(returnValue);
        }
예제 #15
0
        public async void GetJobQueueStatus_ReturnsobQueueStatusist()
        {
            _jobQueueService.Setup(s => s.GetJobTaskStatus(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <JobTaskStatus>
            {
                new JobTaskStatus
                {
                    TaskName = "Generate"
                }
            });

            var controller = new JobQueueController(_jobQueueService.Object, _catapultEngineService.Object, _mapper,
                                                    _logger.Object);

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

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

            Assert.NotEmpty(returnValue);
        }
예제 #16
0
 private void Start()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     if (BuildersJobQueue == null)
     {
         BuildersJobQueue = new JobQueue();
     }
     if (GuardsJobQueue == null)
     {
         GuardsJobQueue = new JobQueue();
     }
     if (PassengersJobQueue == null)
     {
         PassengersJobQueue = new JobQueue();
     }
     if (OrcsJobQueue == null)
     {
         OrcsJobQueue = new JobQueue();
     }
 }