Esempio n. 1
0
 public static void TestEventAfterDispose()
 {
     bool wasHere = false;
     using (DelayedAction delayedAction = new DelayedAction(() => { wasHere = true; }, new TimeSpan(0, 0, 0, 0, 1), null))
     {
         delayedAction.RestartIdleTimer();
         Assert.That(wasHere, Is.False, "The event should not be triggered immediately.");
     }
     Thread.Sleep(50);
     Assert.That(wasHere, Is.False, "The event should be note be triggered once disposed.");
 }
Esempio n. 2
0
 public static void TestShortDelayAndImmediateStart()
 {
     bool wasHere = false;
     using (DelayedAction delayedAction = new DelayedAction(() => { wasHere = true; }, new TimeSpan(0, 0, 0, 0, 1), null))
     {
         delayedAction.RestartIdleTimer();
         Thread.Sleep(50);
         Assert.That(wasHere, Is.True, "The event should be triggered once started.");
         wasHere = false;
         Thread.Sleep(50);
         Assert.That(wasHere, Is.False, "The event should not be triggered more than once.");
     }
 }
Esempio n. 3
0
 public static void TestManyRestartsButOnlyOneEvent()
 {
     int eventCount = 0;
     using (DelayedAction delayedAction = new DelayedAction(() => { ++eventCount; }, new TimeSpan(0, 0, 0, 0, 5), null))
     {
         for (int i = 0; i < 10; ++i)
         {
             delayedAction.RestartIdleTimer();
         }
         Thread.Sleep(50);
         Assert.That(eventCount, Is.EqualTo(1), "The event should be triggered exactly once.");
         Thread.Sleep(50);
         Assert.That(eventCount, Is.EqualTo(1), "The event should still be triggered exactly once.");
     }
 }
Esempio n. 4
0
 public static void TestObjectDisposedException()
 {
     DelayedAction delayedAction = new DelayedAction(() => { }, new TimeSpan(0, 0, 0, 0, 1), null);
     delayedAction.Dispose();
     Assert.Throws<ObjectDisposedException>(() => { delayedAction.RestartIdleTimer(); });
 }