Exemple #1
0
        public async Task QueueGenerateProcessTestsJob_ProjectNameEmpty_ThrowsBadRequest()
        {
            var jobsRepositoryMock       = new Mock <IJobsRepository>();
            var serviceLogRepositoryMock = new Mock <IServiceLogRepository>();
            var controller = new JobsController(jobsRepositoryMock.Object, serviceLogRepositoryMock.Object)
            {
                Request = new HttpRequestMessage()
            };

            var param = new GenerateProcessTestsJobParameters();

            param.ProjectId   = 1;
            param.ProjectName = "";
            param.Processes.Add(new GenerateProcessTestInfo()
            {
                ProcessId = 1
            });

            // Act
            try
            {
                await controller.QueueGenerateProcessTestsJob(param);
            }
            catch (BadRequestException ex)
            {
                Assert.AreEqual(ex.ErrorCode, ErrorCodes.QueueJobProjectNameEmpty);
                throw;
            }
        }
Exemple #2
0
        public async Task <IHttpActionResult> QueueGenerateProcessTestsJob([FromBody] GenerateProcessTestsJobParameters request)
        {
            ValidateRequest(request);

            var session    = ServerHelper.GetSession(Request);
            var parameters = SerializationHelper.ToXml(request.Processes);
            var hostUri    = ServerUriHelper.BaseHostUri;
            var jobId      = await _jobsRepository.AddJobMessage(JobType.GenerateProcessTests,
                                                                 false,
                                                                 parameters,
                                                                 null,
                                                                 request.ProjectId,
                                                                 request.ProjectName,
                                                                 session.UserId,
                                                                 session.UserName,
                                                                 hostUri.ToString());


            return(ConstructHttpResponse(jobId));
        }
Exemple #3
0
        public async Task QueueGenerateProcessTestsJob_ValidParameters_ReturnsCreatedResponse()
        {
            var session = new Session {
                UserName = "******", UserId = 1
            };
            var token = Guid.NewGuid().ToString();
            var jobsRepositoryMock       = new Mock <IJobsRepository>();
            var serviceLogRepositoryMock = new Mock <IServiceLogRepository>();

            jobsRepositoryMock
            .Setup(j => j.AddJobMessage(It.IsAny <JobType>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(),
                                        It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult <int?>(2));

            var controller = new JobsController(jobsRepositoryMock.Object, serviceLogRepositoryMock.Object)
            {
                Request = new HttpRequestMessage()
            };

            controller.Request.Headers.Add("Session-Token", token);
            controller.Request.Properties[ServiceConstants.SessionProperty] = session;
            HttpContext.Current = new HttpContext(
                new HttpRequest("", "http://localhost:9801/svc/adminstore/jobs/test/process", ""),
                new HttpResponse(new StringWriter()));

            var param = new GenerateProcessTestsJobParameters();

            param.ProjectId   = 1;
            param.ProjectName = "test";
            param.Processes.Add(new GenerateProcessTestInfo()
            {
                ProcessId = 1
            });

            // Act
            var actionResult = (await controller.QueueGenerateProcessTestsJob(param)) as CreatedNegotiatedContentResult <AddJobResult>;


            Assert.IsNotNull(actionResult);
            Assert.AreEqual(actionResult.Content.JobId, 2);
        }
Exemple #4
0
        void ValidateRequest(GenerateProcessTestsJobParameters request)
        {
            if (request == null)
            {
                throw new BadRequestException("Please provide a request body", ErrorCodes.QueueJobEmptyRequest);
            }

            if (request.ProjectId <= 0)
            {
                throw new BadRequestException("Please provide a valid project id", ErrorCodes.QueueJobProjectIdInvalid);
            }

            if (string.IsNullOrEmpty(request.ProjectName))
            {
                throw new BadRequestException("Please provide the project name", ErrorCodes.QueueJobProjectNameEmpty);
            }

            if (request?.Processes == null || !request.Processes.Any() || request.Processes.Any(a => a.ProcessId <= 0))
            {
                throw new BadRequestException("Please provide valid processes to generate job", ErrorCodes.QueueJobProcessesInvalid);
            }
        }