public void Execute_UnknownInputType_ShouldReturnValidationIssue()
        {
            var stub = new SchedulerHostStub();

            var command = new AddTriggerCommand(() => stub.Value, new RegisteredInputType[0]);

            AddTriggerOutput result = (AddTriggerOutput)command.Execute(new AddTriggerInput
            {
                TriggerType = "Cron",
                JobDataMap  = new[]
                {
                    new JobDataItem
                    {
                        Key           = "CustomKey",
                        Value         = "CustomCode",
                        InputTypeCode = "custom"
                    },
                }
            });

            stub.AssertEmpty();

            result.AssertSuccessfull();

            Assert.That(result.ValidationErrors, Is.Not.Null);
            Assert.That(result.ValidationErrors["CustomKey"], Is.EqualTo("Unknown input type: custom"));
        }
        public void Execute_JobClassProvided_ShouldScheduleNewJob()
        {
            const string groupName = "Group";
            const string jobName   = "Job";

            var stub = new SchedulerHostStub(new[] { typeof(System.Object) });

            var command = new AddTriggerCommand(() => stub.Value, new RegisteredInputType[0]);

            AddTriggerOutput result = (AddTriggerOutput)command.Execute(new AddTriggerInput
            {
                Group       = groupName,
                Job         = jobName,
                JobClass    = typeof(System.Object).ToString(),
                Name        = "Trigger",
                TriggerType = "Simple"
            });

            result.AssertSuccessfull();

            GroupStub   group   = stub.GetSingleGroup();
            JobStub     job     = group.GetSingleJob();
            TriggerStub trigger = job.GetSingleTrigger();

            Assert.That(group.Name, Is.EqualTo(groupName));
            Assert.That(job.Name, Is.EqualTo(jobName));
            Assert.That(job.JobType, Is.EqualTo(typeof(System.Object)));
            Assert.That(trigger.Name, Is.EqualTo("Trigger"));
        }
        public void Execute_ValidJobDataConversionIssue_ShouldReturnValidationIssue()
        {
            var converter = Substitute.For <IInputTypeConverter>();

            converter.Convert("CustomCode").Throws(new Exception("Custom conversion issue"));

            var stub = new SchedulerHostStub(new Type[0]);

            var command = new AddTriggerCommand(() => stub.Value, new[] { new RegisteredInputType(new InputType("custom"), converter) });

            AddTriggerOutput result = (AddTriggerOutput)command.Execute(new AddTriggerInput
            {
                TriggerType = "Cron",
                JobDataMap  = new[]
                {
                    new JobDataItem
                    {
                        Key           = "CustomKey",
                        Value         = "CustomCode",
                        InputTypeCode = "custom"
                    },
                }
            });

            stub.AssertEmpty();

            result.AssertSuccessfull();

            Assert.That(result.ValidationErrors, Is.Not.Null);
            Assert.That(result.ValidationErrors["CustomKey"], Is.EqualTo("Custom conversion issue"));
        }
        public void Execute_NoJobClass_ShouldAddTriggerToExistingJob()
        {
            const string groupName = "Group";
            const string jobName   = "Job";

            var stub = new SchedulerHostStub();

            var command = new AddTriggerCommand(() => stub.Value, new RegisteredInputType[0]);

            AddTriggerOutput result = (AddTriggerOutput)command.Execute(new AddTriggerInput
            {
                Group       = groupName,
                Job         = jobName,
                Name        = "Trigger",
                TriggerType = "Simple"
            });

            result.AssertSuccessfull();

            GroupStub   group   = stub.GetSingleGroup();
            JobStub     job     = group.GetSingleJob();
            TriggerStub trigger = job.GetSingleTrigger();

            Assert.That(group.Name, Is.EqualTo(groupName));
            Assert.That(job.Name, Is.EqualTo(jobName));
            Assert.That(job.JobType, Is.Null);
            Assert.That(trigger.Name, Is.EqualTo("Trigger"));
        }
Exemple #5
0
        public void Execute_HasAllowedJobTypes_ShouldReturnAllowedJobTypes()
        {
            var stub = new SchedulerHostStub();

            var result = (JobTypesOutput) new GetAllowedJobTypesCommand(() => stub.Value, new[] { typeof(string) }).Execute(new NoInput());

            result.AssertSuccessfull();

            Assert.That(result.AllowedTypes, Is.Not.Null);
            Assert.That(result.AllowedTypes.Length, Is.EqualTo(1));
            Assert.That(result.AllowedTypes[0], Is.EqualTo(typeof(string)));
        }
        public void Execute_NoJobClassOrNameProvided_ShouldFail()
        {
            var stub = new SchedulerHostStub(new[] { typeof(System.Object) });

            var command = new AddTriggerCommand(() => stub.Value, new RegisteredInputType[0]);

            AddTriggerOutput result = (AddTriggerOutput)command.Execute(new AddTriggerInput
            {
                Group       = "Group",
                TriggerType = "Simple"
            });

            Assert.That(result.Success, Is.False);
            Assert.That(stub.SchedulerCommander.Groups.Count, Is.EqualTo(0));
        }
        public void Execute_JobClassIsNotAllowed_ShouldFail()
        {
            var stub = new SchedulerHostStub();

            var command = new AddTriggerCommand(() => stub.Value, new RegisteredInputType[0]);

            AddTriggerOutput result = (AddTriggerOutput)command.Execute(new AddTriggerInput
            {
                JobClass    = typeof(System.Object).ToString(),
                Name        = "Trigger",
                TriggerType = "Simple"
            });

            Assert.That(result.Success, Is.False, "Success");
        }
        private AddTriggerOutput AssertTriggerJobDataMap(
            AddTriggerInput input,
            Action <IDictionary <string, object> > assertAction,
            params RegisteredInputType[] inputTypes)
        {
            var stub = new SchedulerHostStub();

            var command = new AddTriggerCommand(() => stub.Value, inputTypes);

            AddTriggerOutput result = (AddTriggerOutput)command.Execute(input);

            result.AssertSuccessfull();
            assertAction(stub.GetSingleGroup().GetSingleJob().GetSingleTrigger().TriggerJobData);

            return(result);
        }
        private AddTriggerOutput AssertTriggerType(AddTriggerInput input, Action <TriggerType> assertAction)
        {
            var stub = new SchedulerHostStub();

            var command = new AddTriggerCommand(() => stub.Value, new RegisteredInputType[0]);

            AddTriggerOutput result = (AddTriggerOutput)command.Execute(input);

            result.AssertSuccessfull();

            TriggerStub trigger = stub.GetSingleGroup().GetSingleJob().GetSingleTrigger();

            assertAction(trigger.Trigger);

            return(result);
        }
        public void Execute_UnknownTriggerType_ShouldReturnError()
        {
            var stub = new SchedulerHostStub();

            var command = new AddTriggerCommand(() => stub.Value, new RegisteredInputType[0]);

            AddTriggerOutput result = (AddTriggerOutput)command.Execute(new AddTriggerInput
            {
                TriggerType = "Unsupported"
            });

            Assert.That(result.Success, Is.False, "Success");
            Assert.That(result.ErrorMessage, Is.Not.Null);

            stub.AssertEmpty();
        }
Exemple #11
0
        public void Execute_HasAllowedJobTypesAndScheduledJobTypes_ShouldMergeJobTypes()
        {
            var stub = new SchedulerHostStub(
                new GroupStub("Default",
                              new JobStub("Job1", typeof(int)),
                              new JobStub("Job2", typeof(long))));

            var result = (JobTypesOutput) new GetAllowedJobTypesCommand(() => stub.Value, new[] { typeof(string) }).Execute(new NoInput());

            result.AssertSuccessfull();

            Assert.That(result.AllowedTypes, Is.Not.Null);
            Assert.That(result.AllowedTypes.Length, Is.EqualTo(3));
            Assert.That(result.AllowedTypes, Contains.Item(typeof(int)));
            Assert.That(result.AllowedTypes, Contains.Item(typeof(long)));
            Assert.That(result.AllowedTypes, Contains.Item(typeof(string)));
        }