Пример #1
0
        public void DoesNothingAfterEventsEnd()
        {
            var triggered = false;
            var first     = new DateTime(2015, 08, 07);
            var se        = new ScheduledEvent("test", first, (name, triggerTime) =>
            {
                triggered = true;
            });

            se.Scan(first);
            Assert.IsTrue(triggered);

            triggered = false;
            se.Scan(first.AddYears(100));
            Assert.IsFalse(triggered);
        }
Пример #2
0
        public void SchedulesNextEvent()
        {
            var first = new DateTime(2015, 08, 07);
            var second = new DateTime(2015, 08, 08);
            var dates = new[] { first, second }.ToHashSet();
            var se = new ScheduledEvent("test", dates.ToList(), (name, triggerTime) =>
            {
                dates.Remove(triggerTime);
            });

            se.Scan(first);
            Assert.IsFalse(dates.Contains(first));

            se.Scan(second);
            Assert.IsFalse(dates.Contains(second));
        }
        public void FiresEventWhenTimePasses()
        {
            var triggered = false;
            var se        = new ScheduledEvent("test", new DateTime(2015, 08, 07), (name, triggerTime) =>
            {
                triggered = true;
            });

            se.IsLoggingEnabled = true;

            se.Scan(new DateTime(2015, 08, 06));
            Assert.IsFalse(triggered);

            se.Scan(new DateTime(2015, 08, 08));
            Assert.IsTrue(triggered);
        }
Пример #4
0
        public void NextEventTimeIsMaxValueWhenNoMoreEvents()
        {
            var time   = new DateTime(2015, 08, 11, 10, 30, 0);
            var sevent = new ScheduledEvent("test", time, (n, t) => { });

            sevent.Scan(time);
            Assert.AreEqual(DateTime.MaxValue, sevent.NextEventUtcTime);
        }
Пример #5
0
        public void FiresSkippedEventsInSameCallToScan()
        {
            int count  = 0;
            var time   = new DateTime(2015, 08, 11, 10, 30, 0);
            var sevent = new ScheduledEvent("test", new[] { time.AddSeconds(-2), time.AddSeconds(-1), time }, (n, t) => count++);

            sevent.Scan(time);
            Assert.AreEqual(3, count);
        }
Пример #6
0
        public void FiresEventOnTime()
        {
            var fired  = false;
            var time   = new DateTime(2015, 08, 11, 10, 30, 0);
            var sevent = new ScheduledEvent("test", time, (n, t) => fired = true);

            sevent.Scan(time);
            Assert.IsTrue(fired);
        }
Пример #7
0
        /// <summary>
        /// Convenience method for invoking a scheduled event's Scan method inside the <see cref="IsolatorLimitResultProvider"/>
        /// </summary>
        public static void Consume(
            this IIsolatorLimitResultProvider isolatorLimitProvider,
            ScheduledEvent scheduledEvent,
            DateTime scanTimeUtc
            )
        {
            // perform initial filtering to prevent starting a task when not necessary
            if (scheduledEvent.NextEventUtcTime > scanTimeUtc)
            {
                return;
            }

            var timeProvider = RealTimeProvider.Instance;

            isolatorLimitProvider.Consume(timeProvider, () => scheduledEvent.Scan(scanTimeUtc));
        }