Ejemplo n.º 1
0
        public void TestJobsControllerDeleteByIdWithWildcard()
        {
            // Arrange
            IPersistenceStore persistenceStore = new InMemoryStore();

            Scheduler.Shutdown();

            Scheduler.Initialize((config =>
            {
                config.EnableWebApiSelfHost = false;
                config.EnableAuditHistory = false;
                config.PersistenceStoreType = PersistenceStoreType.InMemory;
                config.AutoStart = false;
            }));

            var schedulerCore = new SchedulerCore(Scheduler.Instance(), persistenceStore);

            const string jobName  = "Job1";
            const string jobGroup = "Group1";
            var          jobId    = new Guid("30575FAE-86D3-4EC1-8E10-1E7F5EA6BBB4");

            schedulerCore.CreateJob(jobName, jobGroup, typeof(NoOpJob), new Dictionary <string, object>(), string.Empty, jobId);


            _mockPermissionsHelper.Setup(i => i.GetAuthorizedJobGroups()).Returns(new List <string> {
                "*"
            });
            var controller = new JobsController(_mockPermissionsHelper.Object, schedulerCore);

            // Act
            var jobBeforeDelete = controller.Get(jobId);

            controller.Delete(jobId);
            try
            {
                controller.Get(jobId);
            }
            catch (HttpResponseException ex)
            {
                Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
            }

            // Assert
            Assert.Equal(jobGroup, jobBeforeDelete.JobGroup);
            Assert.Equal(jobName, jobBeforeDelete.JobName);
        }
Ejemplo n.º 2
0
        public void JobsService_GetJobsSync_With_BothDates_BeforeRange()
        {
            //Arrange
            var start = new DateTime(2019, 1, 1);
            var end   = new DateTime(2019, 2, 5);
            var mock  = new Mock <ILogger <JobsController> >();

            //Act
            var service = new JobsController(mock.Object);
            var result  = service.Get(start, end);

            //Assert
            Assert.Empty(result);
        }
Ejemplo n.º 3
0
        public void JobsService_GetJobsSync_With_Dates_InWrongOrder()
        {
            //Arrange
            var start = new DateTime(2021, 2, 5);
            var end   = new DateTime(2021, 2, 4);
            var mock  = new Mock <ILogger <JobsController> >();

            //Act
            var service = new JobsController(mock.Object);
            var result  = service.Get(start, end);

            //Assert
            Assert.Empty(result);
        }
Ejemplo n.º 4
0
        public void JobsService_GetJobsSync_With_StartDate_BeforeRange()
        {
            //Arrange
            var start = new DateTime(1995, 12, 28);
            var end   = new DateTime(2020, 1, 1);
            var mock  = new Mock <ILogger <JobsController> >();

            //Act
            var service = new JobsController(mock.Object);
            var result  = service.Get(start, end);

            //Assert
            var arrResult = result as Jobs[];

            Assert.Single(arrResult);
            Assert.Equal(15, arrResult[0].ActiveJobs);
        }
Ejemplo n.º 5
0
        public void JobsService_GetJobsSync_With_BothDates_AreTheSame()
        {
            //Arrange
            var start = new DateTime(2020, 1, 17);
            var end   = new DateTime(2020, 1, 17);
            var mock  = new Mock <ILogger <JobsController> >();

            //Act
            var service = new JobsController(mock.Object);
            var result  = service.Get(start, end);

            //Assert
            var arrResult = result as Jobs[];

            Assert.Single(arrResult);
            Assert.Equal(200, arrResult[0].PredictedJobViews);
        }
Ejemplo n.º 6
0
        public void JobsService_GetJobsSync_With_EndDate_AfterRange()
        {
            //Arrange
            var start = new DateTime(2021, 2, 10);
            var end   = new DateTime(2030, 1, 1);
            var mock  = new Mock <ILogger <JobsController> >();

            //Act
            var service = new JobsController(mock.Object);
            var result  = service.Get(start, end);

            //Assert
            var arrResult = result as Jobs[];

            Assert.Single(arrResult);
            Assert.Equal(403, arrResult[0].JobViews);
        }
Ejemplo n.º 7
0
        public async Task ShouldReturnStatusCodeOk_WhenControllerCalled()
        {
            var mockDirectoryService = TestUtils.SetupMockDirectoryService();
            var mockFileService      = Substitute.For <IFileService>();

            var mockXmlSerializer = SetupMockRequestXmlSerializer();

            var controller = new JobsController(mockXmlSerializer, mockDirectoryService);

            controller.Request = new HttpRequestMessage();
            controller.Request.SetConfiguration(new HttpConfiguration());

            var result = await controller.Get();

            var actionResult = await result.ExecuteAsync(CancellationToken.None);

            Assert.Equal(HttpStatusCode.OK, actionResult.StatusCode);
        }
Ejemplo n.º 8
0
        public void JobsService_GetJobsSync_With_BothDates_InRange()
        {
            //Arrange
            var start = new DateTime(2021, 2, 4);
            var end   = new DateTime(2021, 2, 5);
            var mock  = new Mock <ILogger <JobsController> >();

            //Act
            var service = new JobsController(mock.Object);
            var result  = service.Get(start, end);

            //Assert
            var arrResult = result as Jobs[];

            Assert.NotNull(arrResult);
            Assert.Equal(2, arrResult.Length);
            Assert.Equal(738, arrResult[0].JobViews);
            Assert.Equal(365, arrResult[1].PredictedJobViews);
        }
Ejemplo n.º 9
0
        public async Task ShouldReturnStatusCodeInternalServerError_WhenExceptionOccured()
        {
            var mockDirectoryService = TestUtils.SetupMockDirectoryService();
            var mockFileService      = Substitute.For <IFileService>();

            var mockXmlSerializer = SetupMockRequestXmlSerializer();

            mockXmlSerializer.SerializeDataAsync(TestUtils.TempPath).Returns(x => { throw new Exception("Exception"); });

            var controller = new JobsController(mockXmlSerializer, mockDirectoryService);

            controller.Request = new HttpRequestMessage();
            controller.Request.SetConfiguration(new HttpConfiguration());

            var result = await controller.Get();

            var actionResult = await result.ExecuteAsync(CancellationToken.None);

            Assert.Equal(HttpStatusCode.InternalServerError, actionResult.StatusCode);
        }
Ejemplo n.º 10
0
        public void Get_WhenCalled_ReturnNoContentResult()
        {
            //Arrange
            var service = new Mock <IJobService>();
            var logger  = new Mock <ILogger <JobsController> >();

            var jobs = GetFakeData();

            service.Setup(x => x.All()).Returns(jobs);
            var controller = new JobsController(logger.Object, service.Object);

            int page = 3;
            //Act
            var results = controller.Get(page);

            //Assert
            var response     = Assert.IsType <ActionResult <JobResponse> >(results);
            var actionResult = response.Result as NoContentResult;
            var statusCode   = actionResult.StatusCode;

            Assert.Equal(StatusCodes.Status204NoContent, statusCode);
        }
Ejemplo n.º 11
0
        public void Get_WhenCalled_ReturnOkResult_WithResources()
        {
            //Arrange
            var service = new Mock <IJobService>();
            var logger  = new Mock <ILogger <JobsController> >();

            var jobs = GetFakeData();

            service.Setup(x => x.All()).Returns(jobs);
            var controller = new JobsController(logger.Object, service.Object);

            int page = 1;
            //Act
            var results = controller.Get(page);

            //Assert
            var response       = Assert.IsType <ActionResult <JobResponse> >(results);
            var actionResult   = response.Result as OkObjectResult;
            var statusCode     = actionResult.StatusCode;
            var responseValues = actionResult.Value as IEnumerable <JobResponse>;

            Assert.Equal(StatusCodes.Status200OK, statusCode);
            Assert.Equal(JobsController.NUM_OF_RESULT_PER_PAGE, responseValues.Count());
        }