public void Resume() { var cts = new CancellationTokenSource(); var count = 0; using (var src = new WakeableTimer()) { src.Interval = TimeSpan.FromSeconds(1); src.Start(TimeSpan.FromMilliseconds(100)); _ = src.Subscribe(Synchronous.AsTask(() => { ++count; src.Stop(); cts.Cancel(); })); src.Start(); src.Suspend(); Assert.That(count, Is.EqualTo(0)); Task.Delay(300).Wait(); Assert.That(count, Is.EqualTo(0)); Assert.That(Execute(src, 0, cts), "Timeout"); Assert.That(count, Is.EqualTo(1)); } }
public void Transition_State() { using (var src = new WakeableTimer()) { Assert.That(src.State, Is.EqualTo(TimerState.Stop)); src.Start(); Assert.That(src.State, Is.EqualTo(TimerState.Run)); src.Start(); // ignore Assert.That(src.State, Is.EqualTo(TimerState.Run)); src.Suspend(); Assert.That(src.State, Is.EqualTo(TimerState.Suspend)); src.Suspend(); Assert.That(src.State, Is.EqualTo(TimerState.Suspend)); src.Start(); Assert.That(src.State, Is.EqualTo(TimerState.Run)); src.Stop(); Assert.That(src.State, Is.EqualTo(TimerState.Stop)); src.Stop(); // ignore Assert.That(src.State, Is.EqualTo(TimerState.Stop)); } }
public void State_Scenario() { using (var timer = new WakeableTimer()) { Assert.That(timer.State, Is.EqualTo(TimerState.Stop)); timer.Start(); Assert.That(timer.State, Is.EqualTo(TimerState.Run)); timer.Start(); Assert.That(timer.State, Is.EqualTo(TimerState.Run)); timer.Suspend(); Assert.That(timer.State, Is.EqualTo(TimerState.Suspend)); timer.Suspend(); Assert.That(timer.State, Is.EqualTo(TimerState.Suspend)); timer.Start(); Assert.That(timer.State, Is.EqualTo(TimerState.Run)); timer.Stop(); Assert.That(timer.State, Is.EqualTo(TimerState.Stop)); timer.Stop(); Assert.That(timer.State, Is.EqualTo(TimerState.Stop)); } }