public void CanBeSetToInfiniteToPreventTimerFromFiring() { var timer = new TaskTimer(); timer.Delay = new TimeSpan(0, 0, 0, 0, -1); Assert.Equal(new TimeSpan(0, 0, 0, 0, -1), timer.Delay); }
public void CanBeChangedByConfigurableChannelComponents() { var timer = new TaskTimer(); timer.Delay = TimeSpan.FromSeconds(42); Assert.Equal(42, timer.Delay.TotalSeconds); }
public void ReturnsTrueWhileUntilActionIsInvoked() { var timer = new TaskTimer { Delay = TimeSpan.FromMilliseconds(1) }; var actionStarted = new ManualResetEventSlim(); var actionCanFinish = new ManualResetEventSlim(); timer.Start( () => Task.Factory.StartNew( () => { actionStarted.Set(); actionCanFinish.Wait(); })); Assert.True(timer.IsStarted); actionStarted.Wait(50); Assert.False(timer.IsStarted); actionCanFinish.Set(); }
public void InvokesActionAfterDelay() { var timer = new TaskTimer { Delay = TimeSpan.FromMilliseconds(1) }; var actionInvoked = new ManualResetEventSlim(); timer.Start(() => Task.Factory.StartNew(actionInvoked.Set)); Assert.False(actionInvoked.IsSet); Assert.True(actionInvoked.Wait(50)); }
public void AbortsPreviousAction() { AsyncTest.Run(async() => { var timer = new TaskTimer { Delay = TimeSpan.FromMilliseconds(1) }; bool actionInvoked = false; timer.Start(() => Task.Factory.StartNew(() => actionInvoked = true)); timer.Cancel(); await TaskEx.Delay(20); Assert.False(actionInvoked); }); }
public void ThrowsArgumentOutOfRangeExceptionWhenNewValueIsMoreThanMaxIntMilliseconds() { var timer = new TaskTimer(); Assert.Throws<ArgumentOutOfRangeException>(() => timer.Delay = TimeSpan.FromMilliseconds((double)int.MaxValue + 1)); }
public void ReturnsFalseIfTimerWasNeverStarted() { var timer = new TaskTimer(); Assert.False(timer.IsStarted); }
public void ThrowsArgumentOutOfRangeExceptionWhenNewValueIsZeroOrLess() { var timer = new TaskTimer(); Assert.Throws<ArgumentOutOfRangeException>(() => timer.Delay = TimeSpan.Zero); }
public void DefaultValueIsOneMinuteBecauseItHasToBeSomethingValid() { var timer = new TaskTimer(); Assert.Equal(TimeSpan.FromMinutes(1), timer.Delay); }
public void AbortsPreviousAction() { AsyncTest.Run(async () => { var timer = new TaskTimer { Delay = TimeSpan.FromMilliseconds(1) }; bool actionInvoked = false; timer.Start(() => Task.Factory.StartNew(() => actionInvoked = true)); timer.Cancel(); await TaskEx.Delay(20); Assert.False(actionInvoked); }); }
public void ThrowsArgumentOutOfRangeExceptionWhenNewValueIsZeroOrLess() { var timer = new TaskTimer(); Assert.Throws <ArgumentOutOfRangeException>(() => timer.Delay = TimeSpan.Zero); }
public void ThrowsArgumentOutOfRangeExceptionWhenNewValueIsMoreThanMaxIntMilliseconds() { var timer = new TaskTimer(); Assert.Throws <ArgumentOutOfRangeException>(() => timer.Delay = TimeSpan.FromMilliseconds((double)int.MaxValue + 1)); }