public void IntervalShouldBeSetTo1WhenStartWithNoParameterIsCalled() { var sut = new ScheduledTimer(); sut.Begin(); Assert.That(sut.TimerObject.Interval, Is.EqualTo(1)); }
public void ScheduleTimerShouldOnlyCallDoOnceEvenWithMultipleBeginRequests() { int count = 0; var sut = new ScheduledTimer() .Do(() => Interlocked.Increment(ref count)) .StartingAt(DateTime.Now) .Every(TimeSpan.FromMilliseconds(1000)); Task.Run(() => sut.Begin()); Task.Run(() => sut.Begin()); Task.Run(() => sut.Begin()); Thread.Sleep(200); Assert.That(count, Is.EqualTo(1)); }
public void StartWithNoParameterShouldUpdateTheStatusToRunning() { const ScheduledTimerStatus expected = ScheduledTimerStatus.Running; var sut = new ScheduledTimer(); sut.Begin(); Assert.That(sut.Status, Is.EqualTo(expected)); }
public void StartThenStopShouldUpdateStatusToStopped() { const ScheduledTimerStatus expectedRunning = ScheduledTimerStatus.Running; const ScheduledTimerStatus expectedStopped = ScheduledTimerStatus.Stopped; var sut = new ScheduledTimer(); sut.Begin(); Assert.That(sut.Status, Is.EqualTo(expectedRunning)); sut.End(); Assert.That(sut.Status, Is.EqualTo(expectedStopped)); }
public void DisposeWithTimerRunningShouldStopTimerAndDisposeInternalTimer() { const ScheduledTimerStatus expected = ScheduledTimerStatus.Stopped; var sut = new ScheduledTimer(); var disposed = false; sut.TimerObject.Disposed += ((sender, args) => disposed = true); sut.Begin(); sut.Dispose(); Assert.That(sut.Status, Is.EqualTo(expected)); Assert.That(disposed, Is.True); }
public void IntervalUpdatedAfterStartShouldNotChangeTheIntervalUntilStartHasBeenCalled() { var sut = new ScheduledTimer(); sut.StartingAt(DateTime.Now.AddMilliseconds(100)); // Becuase of the nature of time, give the interval a second of leeway Assert.That(sut.TimerObject.Interval, Is.InRange(100d, 200d)); sut.Every(TimeSpan.FromMilliseconds(200)); // Becuase of the nature of time, give the interval a second of leeway Assert.That(sut.TimerObject.Interval, Is.InRange(100d, 200d)); sut.Begin(); Thread.Sleep(300); Assert.That(sut.TimerObject.Interval, Is.EqualTo(200)); }
public void SetReplicationIntervalShouldUpdateTheTimerIntervalAndAutoResetAccordingly() { var sut = new ScheduledTimer(); var counter = 0; sut.Do(() => Interlocked.Increment(ref counter)).Every(TimeSpan.FromMilliseconds(100)); Assert.That(sut.TimerObject.Interval, Is.EqualTo(100)); sut.Begin(); Thread.Sleep(550); Assert.That(counter, Is.EqualTo(5)); }