public void PausedTimerShouldBeSaveAndLoadable() { int waitTimeMs = 100; bool elapsed = false; PausableTimer timer = new PausableTimer(waitTimeMs); timer.Elapsed += (a, b) => { elapsed = true; }; int margin = Mathf.RoundToInt(waitTimeMs * 0.1f); timer.Start(); // Wait half the time, then save System.Threading.Thread.Sleep((waitTimeMs + margin) / 2); timer.Pause(); IGenericSaveData save = timer.GetSave(); Assert.IsFalse(elapsed); timer = new PausableTimer(save); timer.Elapsed += (a, b) => { elapsed = true; }; System.Threading.Thread.Sleep((waitTimeMs + margin) / 2); Assert.IsFalse(elapsed); timer.Resume(); System.Threading.Thread.Sleep((waitTimeMs + margin) / 2); Assert.IsTrue(elapsed); }
public void Resume() { if (IsPaused) { _timer.Resume(); } }
public void TimerShouldBePausable() { int waitTimeMs = 100; bool elapsed = false; PausableTimer timer = new PausableTimer(waitTimeMs); timer.Elapsed += (a, b) => { elapsed = true; }; int margin = waitTimeMs / 10; timer.Start(); timer.Pause(); System.Threading.Thread.Sleep(waitTimeMs + margin); Assert.IsFalse(elapsed); timer.Resume(); System.Threading.Thread.Sleep(waitTimeMs - margin); Assert.IsFalse(elapsed); System.Threading.Thread.Sleep(2 * margin); // is now time+margin Assert.IsTrue(elapsed); }