FakeApplicationLifecycle.cs 590 B

12345678910111213141516171819
  1. #nullable enable
  2. namespace Terminal.Gui.Drivers;
  3. /// <summary>
  4. /// Implements a fake application lifecycle for testing purposes. Cleans up the application on dispose by cancelling
  5. /// the provided <see cref="CancellationTokenSource"/> and shutting down the application.
  6. /// </summary>
  7. /// <param name="hardStop"></param>
  8. internal class FakeApplicationLifecycle (CancellationTokenSource hardStop) : IDisposable
  9. {
  10. /// <inheritdoc/>
  11. public void Dispose ()
  12. {
  13. hardStop.Cancel ();
  14. Application.Running?.Dispose ();
  15. Application.Shutdown ();
  16. }
  17. }