TimerTestExtension.cs 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Wayne.Lib.StateEngine.TestExtensions
  4. {
  5. /// <summary>
  6. /// Extension that can be used in unit tests to fire timers.
  7. /// </summary>
  8. public static class TimerTestExtension
  9. {
  10. /// <summary>
  11. /// Fires all actuve timers in the supplied state machine.
  12. /// </summary>
  13. /// <param name="stateMachine"></param>
  14. public static void FireTimers(StateMachine stateMachine)
  15. {
  16. State currentState = stateMachine.CurrentStateRecursive;
  17. do
  18. {
  19. Console.WriteLine("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
  20. Console.WriteLine("FireTimers: Fireing {0} timers in {1}", currentState.ParentStateMachine.timerWrapperList.Count, currentState.ParentStateMachine.Name);
  21. Console.WriteLine("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
  22. List<TimerWrapper> tempTimerWrapperList = new List<TimerWrapper>(currentState.ParentStateMachine.timerWrapperList);
  23. foreach (var timerwrapper in tempTimerWrapperList)
  24. timerwrapper.Fire();
  25. currentState = currentState.ParentState;
  26. } while (currentState != null);
  27. }
  28. }
  29. }