Simple scheduler class
상속: IDisposable
 public void Scheduler_ThrowsExceptionOnNullTimeToRun()
 {
     Assert.Throws<ArgumentException>(() =>
     {
         using (SimpleScheduler scheduler = new SimpleScheduler(() => { }, null)) { }
     });
 }
 public void Scheduler_ThrowsExceptionOnEmptyTimeToRun()
 {
     Assert.Throws<ArgumentException>(() =>
     {
         using (SimpleScheduler scheduler = new SimpleScheduler(() => { }, string.Empty)) { }
     });
 }
        public void Scheduler_CanBeDisabled()
        {
            foreach (string time in SimpleScheduler.DisablingValues)
            {
                bool wasCalled = false;

                using (SimpleScheduler scheduler = new SimpleScheduler(() => wasCalled = true, time))
                {
                    scheduler.Start();

                    scheduler.IsRunning.Should().BeFalse();
                    wasCalled.Should().BeFalse();
                }
            }
        }
        public void Scheduler_ExecutesAction()
        {
            bool wasCalled = false;

            // time to call the action
            TimeSpan time = DateTime.Now.TimeOfDay.Add(TimeSpan.FromSeconds(1));
            string nextSecond = time.ToString(@"hh\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture);

            using (SimpleScheduler scheduler = new SimpleScheduler(() => wasCalled = true, nextSecond))
            {
                scheduler.Start();

                System.Threading.Thread.Sleep(2000);

                // due to strange timings this test might fail. incrementing the wait time might help
                wasCalled.Should().BeTrue();
            }
        }
예제 #5
0
        public TaskWService()
        {
            ServiceName = "TaskService";

            this.schedule = new SimpleScheduler(() => CheckForReservations(), DateTime.Now.AddSeconds(5).ToString("hh:mm:ss"), new TimeSpan(0,5,0));
        }