AddTest() public method

public AddTest ( [ schedule, [ expectedResults, ScheduledFunction function = null ) : ScheduledFunction
schedule [
expectedResults [
function ScheduledFunction
return ScheduledFunction
コード例 #1
0
        public void TestFunctionPause()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester = new SchedulerTester();

            PeriodicSchedule schedule        = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            List <TimeSpan>  expectedResults = new List <TimeSpan>
            {
                new TimeSpan(0, 0, 1),
                new TimeSpan(0, 0, 3),
                new TimeSpan(0, 0, 5),
                new TimeSpan(0, 0, 7),
                new TimeSpan(0, 0, 9)
            };

            schedulerTester.AddTest(schedule, expectedResults, delegate
            {
                DateTime resultTime = DateTime.UtcNow;
                Scheduler.DisableAll();
                Thread.Sleep(1500);
                Scheduler.EnableAll();
                return(resultTime);
            });

            schedulerTester.Run();
        }
コード例 #2
0
        public void TestStartEnabled()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester  schedulerTester = new SchedulerTester();
            PeriodicSchedule schedule        = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            List <TimeSpan>  expectedResults = new List <TimeSpan>
            {
                new TimeSpan(0, 0, 1),
                new TimeSpan(0, 0, 2),
                new TimeSpan(0, 0, 3),
                new TimeSpan(0, 0, 4),
                new TimeSpan(0, 0, 5),
                new TimeSpan(0, 0, 6),
                new TimeSpan(0, 0, 7),
                new TimeSpan(0, 0, 8),
                new TimeSpan(0, 0, 9)
            };

            schedulerTester.SetStartTime();

            schedulerTester.AddTest(Scheduler.Add <DateTime>(schedule, SchedulerTester.TestFunction, enabled: true),
                                    expectedResults);

            while (!schedulerTester.Completed())
            {
                Thread.Sleep(10);
            }
            schedulerTester.Stop();

            schedulerTester.CheckResults();
        }
コード例 #3
0
        public void TestTwoSeconds()
        {
            SchedulerTester.WaitForStartOfSecond(true);

            SchedulerTester schedulerTester = new SchedulerTester();

            PeriodicSchedule schedule = new PeriodicSchedule(
                hour: Hour.Every,
                minute: Minute.Every,
                second: Second.EveryTwoSeconds);
            List <TimeSpan> expectedResults = new List <TimeSpan>
            {
                new TimeSpan(0, 0, 2),
                new TimeSpan(0, 0, 4),
                new TimeSpan(0, 0, 6),
                new TimeSpan(0, 0, 8),
                new TimeSpan(0, 0, 10),
                new TimeSpan(0, 0, 12),
                new TimeSpan(0, 0, 14),
                new TimeSpan(0, 0, 16),
                new TimeSpan(0, 0, 18)
            };

            schedulerTester.AddTest(schedule, expectedResults);

            schedulerTester.Run();
        }
コード例 #4
0
        public void TestDisable()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester = new SchedulerTester();

            PeriodicSchedule schedule        = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            List <TimeSpan>  expectedResults = new List <TimeSpan>
            {
                new TimeSpan(0, 0, 1),
                new TimeSpan(0, 0, 2),
                new TimeSpan(0, 0, 3),
                new TimeSpan(0, 0, 4),
                new TimeSpan(0, 0, 5),
                new TimeSpan(0, 0, 6),
                new TimeSpan(0, 0, 7),
                new TimeSpan(0, 0, 8),
                new TimeSpan(0, 0, 9)
            };

            schedulerTester.AddTest(schedule, expectedResults);

            schedule        = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            expectedResults = new List <TimeSpan>
            {
                new TimeSpan(0, 0, 6),
                new TimeSpan(0, 0, 7),
                new TimeSpan(0, 0, 8),
                new TimeSpan(0, 0, 9)
            };
            IScheduledFunction <DateTime> scheduledFunction = schedulerTester.AddTest(schedule, expectedResults);

            schedulerTester.Start();

            Thread.Sleep(200);
            Scheduler.Disable(scheduledFunction);
            Thread.Sleep(6000);
            Scheduler.Enable(scheduledFunction);

            while (!schedulerTester.Completed())
            {
                Thread.Sleep(10);
            }
            schedulerTester.Stop();

            schedulerTester.CheckResults();
        }
コード例 #5
0
        public void TestTwoSchedulers()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester = new SchedulerTester();

            PeriodicSchedule schedule        = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            List <TimeSpan>  expectedResults = new List <TimeSpan>
            {
                new TimeSpan(0, 0, 1),
                new TimeSpan(0, 0, 2),
                new TimeSpan(0, 0, 3),
                new TimeSpan(0, 0, 4),
                new TimeSpan(0, 0, 5),
                new TimeSpan(0, 0, 6),
                new TimeSpan(0, 0, 7),
                new TimeSpan(0, 0, 8),
                new TimeSpan(0, 0, 9)
            };

            schedulerTester.AddTest(schedule, expectedResults);

            schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            IScheduledFunction <int> scheduledFunction = Scheduler.Add <int>(schedule,
                                                                             function =>
                                                                             function.History.Count() > 0
                                                                              ? function.History.Last().Result + 1
                                                                              : 1, enabled: false);

            Scheduler.Enable(scheduledFunction);
            schedulerTester.Run();
            Scheduler.Disable(scheduledFunction);

            Queue <ScheduledFunctionResult <int> > results =
                new Queue <ScheduledFunctionResult <int> >(scheduledFunction.History);
            int resultCount = 0;

            while (results.Count > 0)
            {
                resultCount++;

                if (resultCount > 9)
                {
                    Assert.Fail("ScheduledFunction<int>: Too many results returned");
                    break;
                }

                Assert.AreEqual(resultCount, results.Dequeue().Result);
            }

            if (resultCount < 9)
            {
                Assert.Fail("ScheduledFunction<int>: Not enough results returned");
            }
        }
コード例 #6
0
        public void TestFunctionAdd()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester1 = new SchedulerTester();
            SchedulerTester schedulerTester2 = null;

            PeriodicSchedule schedule        = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            List <TimeSpan>  expectedResults = new List <TimeSpan>
            {
                new TimeSpan(0, 0, 1),
                new TimeSpan(0, 0, 2)
            };

            schedulerTester1.AddTest(schedule, expectedResults, delegate
            {
                DateTime resultTime = DateTime.UtcNow;
                if (schedulerTester2 == null)
                {
                    schedulerTester2 = new SchedulerTester();

                    schedule = new PeriodicSchedule(hour: Hour.Every,
                                                    minute: Minute.Every,
                                                    second: Second.Every);
                    expectedResults = new List <TimeSpan>
                    {
                        new TimeSpan(0, 0,
                                     1),
                        new TimeSpan(0, 0,
                                     2),
                        new TimeSpan(0, 0,
                                     3),
                        new TimeSpan(0, 0,
                                     4)
                    };
                    schedulerTester2.AddTest(schedule,
                                             expectedResults);

                    schedulerTester2.Start();
                }
                return(resultTime);
            });

            schedulerTester1.Run();

            while (schedulerTester2 == null || !schedulerTester2.Completed())
            {
                Thread.Sleep(10);
            }
            schedulerTester2.Stop();

            schedulerTester2.CheckResults();
        }
コード例 #7
0
        public void TestMinimumGap1()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester  schedulerTester = new SchedulerTester();
            PeriodicSchedule schedule        = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every,
                                                                    minimumGap: TimeSpan.FromSeconds(2));
            List <TimeSpan> expectedResults = new List <TimeSpan>
            {
                new TimeSpan(0, 0, 3),
                new TimeSpan(0, 0, 6),
                new TimeSpan(0, 0, 9),
                new TimeSpan(0, 0, 12),
                new TimeSpan(0, 0, 15)
            };

            schedulerTester.AddTest(schedule, expectedResults);

            schedulerTester.Run();
        }
コード例 #8
0
        public void TestExecuteImmediately1()
        {
            SchedulerTester.WaitForStartOfSecond(true);

            SchedulerTester  schedulerTester = new SchedulerTester();
            PeriodicSchedule schedule        = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.EveryOtherSecond);
            List <TimeSpan>  expectedResults = new List <TimeSpan>
            {
                new TimeSpan(0, 0, 1),
                new TimeSpan(0, 0, 3),
                new TimeSpan(0, 0, 5),
                new TimeSpan(0, 0, 7),
                new TimeSpan(0, 0, 9)
            };

            schedulerTester.AddTest(
                Scheduler.Add <DateTime>(schedule, SchedulerTester.TestFunction, enabled: false,
                                         executeImmediately: false), expectedResults);

            schedulerTester.Run();
        }
コード例 #9
0
        public void TestMinimumGap2()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester  schedulerTester = new SchedulerTester();
            PeriodicSchedule schedule        = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every,
                                                                    minimumGap: TimeSpan.FromSeconds(2));
            List <TimeSpan> expectedResults = new List <TimeSpan>
            {
                TimeSpan.MinValue,
                // Immediate execution
                new TimeSpan(0, 0, 3),
                new TimeSpan(0, 0, 6),
                new TimeSpan(0, 0, 9),
                new TimeSpan(0, 0, 12),
                new TimeSpan(0, 0, 15)
            };

            schedulerTester.AddTest(
                Scheduler.Add <DateTime>(schedule, SchedulerTester.TestFunction, enabled: false, executeImmediately: true),
                expectedResults);

            schedulerTester.Run();
        }
コード例 #10
0
        public void TestStartAfter()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester = new SchedulerTester();

            DateTime startAfterTime = DateTime.UtcNow.AddSeconds(4);

            PeriodicSchedule schedule        = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            List <TimeSpan>  expectedResults = new List <TimeSpan>
            {
                new TimeSpan(0, 0, 5),
                new TimeSpan(0, 0, 6),
                new TimeSpan(0, 0, 7),
                new TimeSpan(0, 0, 8),
                new TimeSpan(0, 0, 9)
            };

            schedulerTester.AddTest(
                Scheduler.Add <DateTime>(schedule, SchedulerTester.TestFunction, enabled: false,
                                         startAfter: startAfterTime), expectedResults);

            schedulerTester.Run();
        }
コード例 #11
0
        public void TestSharedSchedule()
        {
            SchedulerTester.WaitForStartOfSecond(true);

            SchedulerTester schedulerTester = new SchedulerTester();

            PeriodicSchedule schedule = new PeriodicSchedule(
                hour: Hour.Every,
                minute: Minute.Every,
                second: Second.Every);
            List<TimeSpan> expectedResults = new List<TimeSpan>
            {
                new TimeSpan(0, 0, 1),
                new TimeSpan(0, 0, 2),
                new TimeSpan(0, 0, 3),
                new TimeSpan(0, 0, 4),
                new TimeSpan(0, 0, 5),
                new TimeSpan(0, 0, 6),
                new TimeSpan(0, 0, 7),
                new TimeSpan(0, 0, 8),
                new TimeSpan(0, 0, 9)
            };
            schedulerTester.AddTest(schedule, expectedResults);

            expectedResults = new List<TimeSpan>
            {
                new TimeSpan(0, 0, 1),
                new TimeSpan(0, 0, 2),
                new TimeSpan(0, 0, 3),
                new TimeSpan(0, 0, 4),
                new TimeSpan(0, 0, 5),
                new TimeSpan(0, 0, 6),
                new TimeSpan(0, 0, 7),
                new TimeSpan(0, 0, 8),
                new TimeSpan(0, 0, 9)
            };
            schedulerTester.AddTest(schedule, expectedResults);

            schedulerTester.Run();
        }
コード例 #12
0
        public void TestFunctionPause()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester = new SchedulerTester();

            PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            List<TimeSpan> expectedResults = new List<TimeSpan>
                                                 {
                                                     new TimeSpan(0, 0, 1),
                                                     new TimeSpan(0, 0, 3),
                                                     new TimeSpan(0, 0, 5),
                                                     new TimeSpan(0, 0, 7),
                                                     new TimeSpan(0, 0, 9)
                                                 };
            schedulerTester.AddTest(schedule, expectedResults, delegate
                                                                   {
                                                                       DateTime resultTime = DateTime.UtcNow;
                                                                       Scheduler.DisableAll();
                                                                       Thread.Sleep(1500);
                                                                       Scheduler.EnableAll();
                                                                       return resultTime;
                                                                   });

            schedulerTester.Run();
        }
コード例 #13
0
        public void TestFunctionAdd()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester1 = new SchedulerTester();
            SchedulerTester schedulerTester2 = null;

            PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            List<TimeSpan> expectedResults = new List<TimeSpan>
                                                 {
                                                     new TimeSpan(0, 0, 1),
                                                     new TimeSpan(0, 0, 2)
                                                 };
            schedulerTester1.AddTest(schedule, expectedResults, delegate
                                                                    {
                                                                        DateTime resultTime = DateTime.UtcNow;
                                                                        if (schedulerTester2 == null)
                                                                        {
                                                                            schedulerTester2 = new SchedulerTester();

                                                                            schedule = new PeriodicSchedule(hour: Hour.Every,
                                                                                                    minute: Minute.Every,
                                                                                                    second: Second.Every);
                                                                            expectedResults = new List<TimeSpan>
                                                                                                  {
                                                                                                      new TimeSpan(0, 0,
                                                                                                                   1),
                                                                                                      new TimeSpan(0, 0,
                                                                                                                   2),
                                                                                                      new TimeSpan(0, 0,
                                                                                                                   3),
                                                                                                      new TimeSpan(0, 0,
                                                                                                                   4)
                                                                                                  };
                                                                            schedulerTester2.AddTest(schedule,
                                                                                                     expectedResults);

                                                                            schedulerTester2.Start();
                                                                        }
                                                                        return resultTime;
                                                                    });

            schedulerTester1.Run();

            while (schedulerTester2 == null || !schedulerTester2.Completed())
            {
                Thread.Sleep(10);
            }
            schedulerTester2.Stop();

            schedulerTester2.CheckResults();
        }
コード例 #14
0
        public void TestRemove()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester = new SchedulerTester();

            PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            List<TimeSpan> expectedResults = new List<TimeSpan>
                                                 {
                                                     new TimeSpan(0, 0, 1),
                                                     new TimeSpan(0, 0, 2),
                                                     new TimeSpan(0, 0, 3),
                                                     new TimeSpan(0, 0, 4),
                                                     new TimeSpan(0, 0, 5),
                                                     new TimeSpan(0, 0, 6),
                                                     new TimeSpan(0, 0, 7),
                                                     new TimeSpan(0, 0, 8),
                                                     new TimeSpan(0, 0, 9)
                                                 };
            schedulerTester.AddTest(schedule, expectedResults);

            schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            expectedResults = new List<TimeSpan>
                                  {
                                      new TimeSpan(0, 0, 1)
                                  };
            IScheduledFunction<DateTime> scheduledFunction = schedulerTester.AddTest(schedule, expectedResults);

            schedulerTester.Start();

            Thread.Sleep(1500);
            Scheduler.Remove(scheduledFunction);

            while (!schedulerTester.Completed())
            {
                Thread.Sleep(10);
            }
            schedulerTester.Stop();

            schedulerTester.CheckResults();
        }
コード例 #15
0
        public void TestStartAfter()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester = new SchedulerTester();

            DateTime startAfterTime = DateTime.UtcNow.AddSeconds(4);

            PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            List<TimeSpan> expectedResults = new List<TimeSpan>
                                                 {
                                                     new TimeSpan(0, 0, 5),
                                                     new TimeSpan(0, 0, 6),
                                                     new TimeSpan(0, 0, 7),
                                                     new TimeSpan(0, 0, 8),
                                                     new TimeSpan(0, 0, 9)
                                                 };
            schedulerTester.AddTest(
                Scheduler.Add<DateTime>(schedule, SchedulerTester.TestFunction, enabled: false,
                                        startAfter: startAfterTime), expectedResults);

            schedulerTester.Run();
        }
コード例 #16
0
        public void TestStartEnabled()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester = new SchedulerTester();
            PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            List<TimeSpan> expectedResults = new List<TimeSpan>
                                                 {
                                                     new TimeSpan(0, 0, 1),
                                                     new TimeSpan(0, 0, 2),
                                                     new TimeSpan(0, 0, 3),
                                                     new TimeSpan(0, 0, 4),
                                                     new TimeSpan(0, 0, 5),
                                                     new TimeSpan(0, 0, 6),
                                                     new TimeSpan(0, 0, 7),
                                                     new TimeSpan(0, 0, 8),
                                                     new TimeSpan(0, 0, 9)
                                                 };

            schedulerTester.SetStartTime();

            schedulerTester.AddTest(Scheduler.Add<DateTime>(schedule, SchedulerTester.TestFunction, enabled: true),
                                    expectedResults);

            while (!schedulerTester.Completed())
            {
                Thread.Sleep(10);
            }
            schedulerTester.Stop();

            schedulerTester.CheckResults();
        }
コード例 #17
0
        public void TestExecuteImmediately1()
        {
            SchedulerTester.WaitForStartOfSecond(true);

            SchedulerTester schedulerTester = new SchedulerTester();
            PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.EveryOtherSecond);
            List<TimeSpan> expectedResults = new List<TimeSpan>
                                                 {
                                                     new TimeSpan(0, 0, 1),
                                                     new TimeSpan(0, 0, 3),
                                                     new TimeSpan(0, 0, 5),
                                                     new TimeSpan(0, 0, 7),
                                                     new TimeSpan(0, 0, 9)
                                                 };
            schedulerTester.AddTest(
                Scheduler.Add<DateTime>(schedule, SchedulerTester.TestFunction, enabled: false,
                                        executeImmediately: false), expectedResults);

            schedulerTester.Run();
        }
コード例 #18
0
        public void TestMinimumGap1()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester = new SchedulerTester();
            PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every,
                                             minimumGap: TimeSpan.FromSeconds(2));
            List<TimeSpan> expectedResults = new List<TimeSpan>
                                                 {
                                                     new TimeSpan(0, 0, 3),
                                                     new TimeSpan(0, 0, 6),
                                                     new TimeSpan(0, 0, 9),
                                                     new TimeSpan(0, 0, 12),
                                                     new TimeSpan(0, 0, 15)
                                                 };
            schedulerTester.AddTest(schedule, expectedResults);

            schedulerTester.Run();
        }
コード例 #19
0
        public void TestTwoSchedulers()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester = new SchedulerTester();

            PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            List<TimeSpan> expectedResults = new List<TimeSpan>
                                                 {
                                                     new TimeSpan(0, 0, 1),
                                                     new TimeSpan(0, 0, 2),
                                                     new TimeSpan(0, 0, 3),
                                                     new TimeSpan(0, 0, 4),
                                                     new TimeSpan(0, 0, 5),
                                                     new TimeSpan(0, 0, 6),
                                                     new TimeSpan(0, 0, 7),
                                                     new TimeSpan(0, 0, 8),
                                                     new TimeSpan(0, 0, 9)
                                                 };
            schedulerTester.AddTest(schedule, expectedResults);

            schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every);
            IScheduledFunction<int> scheduledFunction = Scheduler.Add<int>(schedule,
                                                                          function =>
                                                                          function.History.Count() > 0
                                                                              ? function.History.Last().Result + 1
                                                                              : 1, enabled: false);

            Scheduler.Enable(scheduledFunction);
            schedulerTester.Run();
            Scheduler.Disable(scheduledFunction);

            Queue<ScheduledFunctionResult<int>> results =
                new Queue<ScheduledFunctionResult<int>>(scheduledFunction.History);
            int resultCount = 0;
            while (results.Count > 0)
            {
                resultCount++;

                if (resultCount > 9)
                {
                    Assert.Fail("ScheduledFunction<int>: Too many results returned");
                    break;
                }

                Assert.AreEqual(resultCount, results.Dequeue().Result);
            }

            if (resultCount < 9)
            {
                Assert.Fail("ScheduledFunction<int>: Not enough results returned");
            }
        }
コード例 #20
0
        public void TestMinimumGap2()
        {
            SchedulerTester.WaitForStartOfSecond();

            SchedulerTester schedulerTester = new SchedulerTester();
            PeriodicSchedule schedule = new PeriodicSchedule(hour: Hour.Every, minute: Minute.Every, second: Second.Every,
                                             minimumGap: TimeSpan.FromSeconds(2));
            List<TimeSpan> expectedResults = new List<TimeSpan>
                                                 {
                                                     TimeSpan.MinValue,
                                                     // Immediate execution
                                                     new TimeSpan(0, 0, 3),
                                                     new TimeSpan(0, 0, 6),
                                                     new TimeSpan(0, 0, 9),
                                                     new TimeSpan(0, 0, 12),
                                                     new TimeSpan(0, 0, 15)
                                                 };
            schedulerTester.AddTest(
                Scheduler.Add<DateTime>(schedule, SchedulerTester.TestFunction, enabled: false, executeImmediately: true),
                expectedResults);

            schedulerTester.Run();
        }