示例#1
0
        public void RecurringTimer_Parse()
        {
            RecurringTimer timer;

            timer = new RecurringTimer("Disabled");
            Assert.AreEqual(RecurringTimerType.Disabled, timer.Type);

            timer = new RecurringTimer("Hourly,10");
            Assert.AreEqual(RecurringTimerType.Hourly, timer.Type);
            Assert.AreEqual("00:10:00", timer.TimeOffset.ToString());

            timer = new RecurringTimer("Hourly,10:11");
            Assert.AreEqual(RecurringTimerType.Hourly, timer.Type);
            Assert.AreEqual("00:10:11", timer.TimeOffset.ToString());

            timer = new RecurringTimer("Daily,10:11");
            Assert.AreEqual(RecurringTimerType.Daily, timer.Type);
            Assert.AreEqual("10:11:00", timer.TimeOffset.ToString());

            timer = new RecurringTimer("Daily,10:11:12");
            Assert.AreEqual(RecurringTimerType.Daily, timer.Type);
            Assert.AreEqual("10:11:12", timer.TimeOffset.ToString());

            timer = new RecurringTimer("Interval,10s");
            Assert.AreEqual(RecurringTimerType.Interval, timer.Type);
            Assert.AreEqual("00:00:10", timer.TimeOffset.ToString());

            timer = new RecurringTimer("Interval,01:02:03");
            Assert.AreEqual(RecurringTimerType.Interval, timer.Type);
            Assert.AreEqual("01:02:03", timer.TimeOffset.ToString());
        }
示例#2
0
        public void RecurringTimer_Parse()
        {
            RecurringTimer timer;

            timer = new RecurringTimer("Disabled");
            Assert.Equal(RecurringTimerType.Disabled, timer.Type);

            timer = new RecurringTimer("Minute");
            Assert.Equal(RecurringTimerType.Minute, timer.Type);
            Assert.Equal(TimeSpan.Zero, timer.TimeOffset);

            timer = new RecurringTimer("QuarterHour");
            Assert.Equal(RecurringTimerType.QuarterHour, timer.Type);
            Assert.Equal(TimeSpan.Zero, timer.TimeOffset);

            timer = new RecurringTimer("QuarterHour:10");
            Assert.Equal(RecurringTimerType.QuarterHour, timer.Type);
            Assert.Equal(TimeSpan.FromMinutes(10), timer.TimeOffset);

            timer = new RecurringTimer("QuarterHour:10:11");
            Assert.Equal(RecurringTimerType.QuarterHour, timer.Type);
            Assert.Equal(TimeSpan.FromMinutes(10) + TimeSpan.FromSeconds(11), timer.TimeOffset);

            timer = new RecurringTimer("Hourly");
            Assert.Equal(RecurringTimerType.Hourly, timer.Type);
            Assert.Equal(TimeSpan.Zero, timer.TimeOffset);

            timer = new RecurringTimer("Hourly:10");
            Assert.Equal(RecurringTimerType.Hourly, timer.Type);
            Assert.Equal(TimeSpan.FromMinutes(10), timer.TimeOffset);

            timer = new RecurringTimer("Hourly:10:11");
            Assert.Equal(RecurringTimerType.Hourly, timer.Type);
            Assert.Equal(TimeSpan.FromMinutes(10) + TimeSpan.FromSeconds(11), timer.TimeOffset);

            timer = new RecurringTimer("Daily");
            Assert.Equal(RecurringTimerType.Daily, timer.Type);
            Assert.Equal("00:00:00", timer.TimeOffset.ToString());

            timer = new RecurringTimer("Daily:10:11");
            Assert.Equal(RecurringTimerType.Daily, timer.Type);
            Assert.Equal(TimeSpan.FromHours(10) + TimeSpan.FromMinutes(11), timer.TimeOffset);

            timer = new RecurringTimer("Daily:10:11:12");
            Assert.Equal(RecurringTimerType.Daily, timer.Type);
            Assert.Equal(TimeSpan.FromHours(10) + TimeSpan.FromMinutes(11) + TimeSpan.FromSeconds(12), timer.TimeOffset);

            timer = new RecurringTimer("Interval:10:11:12");
            Assert.Equal(RecurringTimerType.Interval, timer.Type);
            Assert.Equal(TimeSpan.FromHours(10) + TimeSpan.FromMinutes(11) + TimeSpan.FromSeconds(12), timer.TimeOffset);

            timer = new RecurringTimer("Interval:48:11:12");
            Assert.Equal(RecurringTimerType.Interval, timer.Type);
            Assert.Equal(TimeSpan.FromHours(48) + TimeSpan.FromMinutes(11) + TimeSpan.FromSeconds(12), timer.TimeOffset);
        }
示例#3
0
        public async Task RecurringTimer_Async()
        {
            var timer  = new RecurringTimer(RecurringTimerType.Interval, TimeSpan.FromSeconds(1));
            var sysNow = SysTime.Now;

            timer.Reset();
            Assert.False(timer.HasFired());
            await timer.WaitAsync(TimeSpan.FromMilliseconds(500));

            Assert.True(SysTime.Now + TimeSpan.FromMilliseconds(50) - sysNow > TimeSpan.FromSeconds(1));
        }
示例#4
0
        public void RecurringTimer_Disabled()
        {
            RecurringTimer timer;

            timer = new RecurringTimer(RecurringTimerType.Disabled, TimeSpan.FromSeconds(1));
            Assert.IsFalse(timer.HasFired(new DateTime(2010, 10, 23, 10, 10, 0)));   // Should never fire when disabled
            Assert.IsFalse(timer.HasFired(new DateTime(2010, 10, 24, 9, 0, 0)));
            Assert.IsFalse(timer.HasFired(new DateTime(2010, 10, 24, 10, 1, 0)));
            Assert.IsFalse(timer.HasFired(new DateTime(2010, 10, 24, 10, 1, 0)));
            Assert.IsFalse(timer.HasFired(new DateTime(2010, 10, 25, 10, 1, 0)));
        }
示例#5
0
        public void RecurringTimer_Interval()
        {
            RecurringTimer timer;

            timer = new RecurringTimer(RecurringTimerType.Interval, TimeSpan.FromSeconds(10));
            timer.Start(new DateTime(2011, 8, 26, 0, 0, 0));
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 8, 26, 0, 0, 0)));
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 8, 26, 0, 0, 9)));
            Assert.IsTrue(timer.HasFired(new DateTime(2011, 8, 26, 0, 0, 10)));
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 8, 26, 0, 0, 19)));
            Assert.IsTrue(timer.HasFired(new DateTime(2011, 8, 26, 0, 0, 21)));
        }
示例#6
0
        public async Task RecurringTimer_Set()
        {
            var timer = new RecurringTimer("Interval:00:00:05");

            Assert.False(timer.HasFired());

            timer.Set();
            Assert.True(timer.HasFired());
            Assert.False(timer.HasFired());

            var startUtc = DateTime.UtcNow;

            await timer.WaitAsync(TimeSpan.FromMilliseconds(50));

            Assert.True(DateTime.UtcNow - startUtc >= TimeSpan.FromSeconds(5));
        }
示例#7
0
        public void RecurringTimer_Interval()
        {
            RecurringTimer timer;

            timer = new RecurringTimer(RecurringTimerType.Interval, TimeSpan.FromSeconds(10));
            timer.Start(new DateTime(2011, 8, 26, 0, 0, 0));
            Assert.False(timer.HasFired(new DateTime(2011, 8, 26, 0, 0, 0)));
            Assert.False(timer.HasFired(new DateTime(2011, 8, 26, 0, 0, 9)));
            Assert.True(timer.HasFired(new DateTime(2011, 8, 26, 0, 0, 10)));
            Assert.False(timer.HasFired(new DateTime(2011, 8, 26, 0, 0, 19)));
            Assert.True(timer.HasFired(new DateTime(2011, 8, 26, 0, 0, 21)));

            Assert.Equal("Interval:00:00:10", timer.ToString());

            timer = new RecurringTimer("Interval:48:11:12");
            Assert.Equal("Interval:48:11:12", timer.ToString());
        }
示例#8
0
        public void RecurringTimer_Daily()
        {
            RecurringTimer timer;

            timer = new RecurringTimer(new TimeOfDay("10:00:00"));
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 10, 23, 10, 10, 0)));   // Verify that we don't fire until we see the transition
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 10, 24, 9, 0, 0)));     // Still before the scheduled time
            Assert.IsTrue(timer.HasFired(new DateTime(2011, 10, 24, 10, 1, 0)));     // Should have seen the transition
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 10, 24, 10, 1, 0)));    // Should be false now because we already handled this time
            Assert.IsTrue(timer.HasFired(new DateTime(2011, 10, 25, 10, 1, 0)));     // Should fire for the next day

            timer = new RecurringTimer(RecurringTimerType.Daily, new TimeSpan(10, 0, 0));
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 10, 23, 10, 10, 0)));   // Verify that we don't fire until we see the transition
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 10, 24, 9, 0, 0)));     // Still before the scheduled time
            Assert.IsTrue(timer.HasFired(new DateTime(2011, 10, 24, 10, 1, 0)));     // Should have seen the transition
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 10, 24, 10, 1, 0)));    // Should be false now because we already handled this time
            Assert.IsTrue(timer.HasFired(new DateTime(2011, 10, 25, 10, 1, 0)));     // Should fire for the next day
        }
示例#9
0
        public void RecurringTimer_Hourly()
        {
            RecurringTimer timer;

            timer = new RecurringTimer(RecurringTimerType.Hourly, TimeSpan.FromMinutes(4));

            Assert.IsFalse(timer.HasFired(new DateTime(2011, 08, 20, 10, 0, 0)));    // Never fires on the first poll
            Assert.IsTrue(timer.HasFired(new DateTime(2011, 08, 20, 10, 5, 0)));
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 08, 20, 11, 1, 0)));    // Still before offset
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 08, 20, 11, 3, 0)));    // Still before offset
            Assert.IsTrue(timer.HasFired(new DateTime(2011, 08, 20, 11, 4, 0)));     // Right at offset
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 08, 20, 11, 4, 0)));    // Doesn't fire until the next hour
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 08, 20, 11, 15, 0)));
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 08, 20, 11, 30, 0)));
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 08, 20, 11, 55, 0)));
            Assert.IsFalse(timer.HasFired(new DateTime(2011, 08, 20, 12, 0, 0)));
            Assert.IsTrue(timer.HasFired(new DateTime(2011, 08, 20, 12, 5, 0)));     // Just past the next firing time
        }