public void DeleteJobForAuthorizedUserWithDeletePermissionDeletesJob()
        {
            Mock.Arrange(() => CurrentUserDataProvider.GetIdentity(TENANT_ID))
            .Returns(new Identity
            {
                Permissions = new List <String> {
                    JOB_DELETE_PERMISSION
                },
                Username = CURRENT_USER_ID,
                Tid      = TENANT_ID
            })
            .MustBeCalled();
            Mock.Arrange(() => CurrentUserDataProvider.IsEntityOfUser(CURRENT_USER_ID, TENANT_ID, Arg.IsAny <Job>()))
            .Returns(true)
            .MustBeCalled();
            Mock.Arrange(() => _lifeCycleContext.Jobs.Find(1))
            .IgnoreInstance()
            .Returns(CreateSampleJobDbSet()[0])
            .MustBeCalled();
            Mock.Arrange(() => _lifeCycleContext.Jobs.Remove(Arg.IsAny <Job>()))
            .IgnoreInstance()
            .MustBeCalled();
            var actionResult = _jobsController.Delete(1).Result;

            AssertStatusCodeResult(actionResult, HttpStatusCode.NoContent);

            Mock.Assert(() => CurrentUserDataProvider.GetIdentity(TENANT_ID));
            Mock.Assert(() => CurrentUserDataProvider.IsEntityOfUser(CURRENT_USER_ID, TENANT_ID, Arg.IsAny <Job>()));
            Mock.Assert(_lifeCycleContext);
        }
Ejemplo n.º 2
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.º 3
0
        public void Delete_WhenCalled_ReturnNotFoundResult()
        {
            //Arrange
            var service = new Mock <IJobService>();
            var logger  = new Mock <ILogger <JobsController> >();

            var jobToDelete = buildJobRequest();
            var controller  = new JobsController(logger.Object, service.Object);
            var jobId       = jobToDelete.Id;
            Job job         = null;

            service.Setup(x => x.Find(jobId)).Returns(job);
            //Act
            var results = controller.Delete(jobId);

            //Assert
            var response   = Assert.IsType <Task <IActionResult> >(results);
            var statusCode = response.Result as NotFoundResult;

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

            var jobToDelete = buildJobRequest();
            var controller  = new JobsController(logger.Object, service.Object);
            var jobId       = jobToDelete.Id;
            Job job         = new Job {
            };

            service.Setup(x => x.Find(jobId)).Returns(job);
            service.Setup(x => x.RemoveAsync(It.Ref <Job> .IsAny)).Returns(Task.CompletedTask);
            //Act
            var results = controller.Delete(jobId);

            //Assert
            var response   = Assert.IsType <Task <IActionResult> >(results);
            var statusCode = response.Result as NoContentResult;

            Assert.Equal(StatusCodes.Status204NoContent, statusCode.StatusCode);
        }