public void WhenManualTriggersAreNotFound_StartJob_TriggersJob() { // Arrange. const string processName = "TestProcess"; var syncGuid = Guid.Parse("DF1F8724-297C-45AE-8E70-B924FD375620"); var jobName = syncGuid.ToString(); var jobDetail = new JobDetail(jobName, QuartzScheduler.QuartzGroupName, typeof(SyncProcessWorker)); var trigger = Mock.Create<Trigger>(Behavior.Loose); Mock.Arrange(() => trigger.Group).Returns(QuartzScheduler.QuartzGroupName); var scheduler = Mock.Create<IScheduler>(Behavior.Loose); Mock.Arrange(() => scheduler.GetJobDetail(jobName, QuartzScheduler.QuartzGroupName)).Returns(jobDetail); Mock.Arrange(() => scheduler.GetTriggersOfJob(jobName, QuartzScheduler.QuartzGroupName)).Returns(new[] { trigger }); var logger = Mock.Create<ILogger>(Behavior.Loose); var target = new DummyQuartzScheduler { Logger = logger }; target.SetScheduler(scheduler); // Act. target.StartJob(processName, syncGuid); // Assert. Mock.Assert(() => scheduler.TriggerJob(jobName, QuartzScheduler.QuartzGroupName), Occurs.Once()); Mock.Assert(() => logger.Log(LogSeverity.Error, Arg.IsAny<string>(), Arg.IsAny<Exception>()), Occurs.Never()); }
public void WhenJobIsNotFound_StartJob_ThrowsException() { // Arrange. const string processName = "TestProcess"; var syncGuid = Guid.Parse("DF1F8724-297C-45AE-8E70-B924FD375620"); var jobName = syncGuid.ToString(); var scheduler = Mock.Create<IScheduler>(Behavior.Loose); Mock.Arrange(() => scheduler.GetJobDetail(jobName, QuartzScheduler.QuartzGroupName)).Returns(null as JobDetail); var logger = Mock.Create<ILogger>(Behavior.Loose); var target = new DummyQuartzScheduler { Logger = logger }; target.SetScheduler(scheduler); // Act. target.StartJob(processName, syncGuid); // Assert. Mock.Assert(() => logger.Log(LogSeverity.Error, Arg.IsAny<string>(), Arg.IsAny<Exception>()), Occurs.Never()); }