Beispiel #1
0
        public void LongRunner_1xPeriod()
        {
            TimerSchedulingProvider provider = new TimerSchedulingProvider(new TimerSchedulingProvider.DateTimeNowProvider(), TimeSpan.FromMinutes(1));

            Envelope envelope = Envelope.Create("Hello, World!")
                                .AddExecuteAt(DateTime.Now.AddMinutes(1));

            SchedulingContext context = new SchedulingContext(envelope);

            provider.Add(context);

            Thread.Sleep(TimeSpan.FromSeconds(1 * 60 + 10));

            Assert.AreEqual(true, context.IsExecuted);
        }
Beispiel #2
0
 public SchedulingContext(TimerSchedulingProvider collection, ISchedulingContext inner)
 {
     this.collection = collection;
     this.inner      = inner;
 }
Beispiel #3
0
        public void Collection()
        {
            TimerSchedulingProvider provider = new TimerSchedulingProvider(new TimerSchedulingProvider.DateTimeNowProvider());

            Envelope envelope1 = Envelope.Create("Hello, World!")
                                 .AddExecuteAt(DateTime.Now.AddDays(10));

            Envelope envelope2 = Envelope.Create("Hi, there!")
                                 .AddExecuteAt(DateTime.Now.AddMinutes(1));

            SchedulingContext context1 = new SchedulingContext(envelope1);
            SchedulingContext context2 = new SchedulingContext(envelope2);

            provider.Add(context1);
            provider.Add(context2);

            Assert.AreEqual(true, provider.IsContained(context1));
            Assert.AreEqual(false, context1.IsExecuted);
            Assert.AreEqual(true, provider.IsContained(context2));
            Assert.AreEqual(false, context2.IsExecuted);

            provider.Remove(context1);

            Assert.AreEqual(false, provider.IsContained(context1));
            Assert.AreEqual(false, context1.IsExecuted);
            Assert.AreEqual(true, provider.IsContained(context2));
            Assert.AreEqual(false, context2.IsExecuted);

            provider.Remove(context2);

            Assert.AreEqual(false, provider.IsContained(context1));
            Assert.AreEqual(false, context1.IsExecuted);
            Assert.AreEqual(false, provider.IsContained(context2));
            Assert.AreEqual(false, context2.IsExecuted);

            provider.Add(context1);

            Assert.AreEqual(true, provider.IsContained(context1));
            Assert.AreEqual(false, context1.IsExecuted);
            Assert.AreEqual(false, provider.IsContained(context2));
            Assert.AreEqual(false, context2.IsExecuted);

            provider.Add(context2);

            Assert.AreEqual(true, provider.IsContained(context1));
            Assert.AreEqual(false, context1.IsExecuted);
            Assert.AreEqual(true, provider.IsContained(context2));
            Assert.AreEqual(false, context2.IsExecuted);

            foreach (ISchedulingContext item in provider.Enumerate())
            {
                if (item.Equals(context1))
                {
                    item.Execute();

                    Assert.AreEqual(false, provider.IsContained(context1));
                    Assert.AreEqual(true, context1.IsExecuted);
                }
                else if (item.Equals(context2))
                {
                    item.Execute();

                    Assert.AreEqual(false, provider.IsContained(context2));
                    Assert.AreEqual(true, context2.IsExecuted);
                }
                else
                {
                    Assert.Fail("Collection contains other items.");
                }
            }

            Assert.AreEqual(false, provider.IsContained(context1));
            Assert.AreEqual(true, context1.IsExecuted);
            Assert.AreEqual(false, provider.IsContained(context2));
            Assert.AreEqual(true, context2.IsExecuted);
        }