Beispiel #1
0
 public void Execute()
 {
     collection.Remove(inner);
     inner.Execute();
 }
Beispiel #2
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);
        }