public void WhenSyncProcessIsCreated_UpdateJobs_CreatedNewJob() { // Arrange. const string processName = "TestProcess"; var syncGuid = Guid.Parse("DF1F8724-297C-45AE-8E70-B924FD375620"); var jobName = syncGuid.ToString(); var synchronizer = Mock.Create<IProcessSynchronizer>(Behavior.Loose); Mock.Arrange(() => synchronizer.Guid).Returns(syncGuid); Mock.Arrange(() => synchronizer.ProcessName).Returns(processName); Mock.Arrange(() => synchronizer.Schedules).Returns(new ISchedule[] { }); var scheduler = Mock.Create<IScheduler>(Behavior.Loose); Mock.Arrange(() => scheduler.GetJobNames(QuartzScheduler.QuartzGroupName)).Returns(new string[] { }); JobDetail jobDetail = null; Mock.Arrange(() => scheduler.AddJob(Arg.IsAny<JobDetail>(), true)).DoInstead<JobDetail, bool>((jd, replace) => jobDetail = jd); var logger = Mock.Create<ILogger>(Behavior.Loose); var target = new DummyQuartzScheduler { Logger = logger }; target.SetScheduler(scheduler); // Act. target.UpdateJobs(new List<IProcessSynchronizer> { synchronizer }); // Assert. Assert.IsNotNull(jobDetail); Assert.AreEqual(jobName, jobDetail.Name); Mock.Assert(() => logger.Log(LogSeverity.Error, Arg.IsAny<string>(), Arg.IsAny<Exception>()), Occurs.Never()); }
public void WhenSyncProcessWasRemoved_UpdateJobs_DeletesJob() { // Arrange. var existingJobs = new[] { "Job1", "Job2" }; var scheduler = Mock.Create<IScheduler>(Behavior.Loose); Mock.Arrange(() => scheduler.GetJobNames(QuartzScheduler.QuartzGroupName)).Returns(existingJobs); var logger = Mock.Create<ILogger>(Behavior.CallOriginal); var target = new DummyQuartzScheduler { Logger = logger }; target.SetScheduler(scheduler); // Act. target.UpdateJobs(new List<IProcessSynchronizer>()); // Assert. Mock.Assert(() => scheduler.DeleteJob("Job1", QuartzScheduler.QuartzGroupName), Occurs.Once()); Mock.Assert(() => scheduler.DeleteJob("Job2", QuartzScheduler.QuartzGroupName), Occurs.Once()); Mock.Assert(() => logger.Log(LogSeverity.Error, Arg.IsAny<string>(), Arg.IsAny<Exception>()), Occurs.Never()); }