FakeApplicationFactory.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System.Drawing;
  2. using TerminalGuiFluentTesting;
  3. namespace Terminal.Gui.Drivers;
  4. /// <summary>
  5. /// Provides methods to create and manage a fake application for testing purposes.
  6. /// </summary>
  7. public class FakeApplicationFactory
  8. {
  9. /// <summary>
  10. /// Creates an initialized fake application which will be cleaned up when result object
  11. /// is disposed.
  12. /// </summary>
  13. /// <returns></returns>
  14. public IDisposable SetupFakeApplication ()
  15. {
  16. CancellationTokenSource hardStopTokenSource = new CancellationTokenSource ();
  17. FakeInput fakeInput = new FakeInput ();
  18. fakeInput.ExternalCancellationTokenSource = hardStopTokenSource;
  19. FakeOutput output = new ();
  20. output.SetSize (80, 25);
  21. SizeMonitorImpl sizeMonitor = new (output);
  22. ApplicationImpl impl = new (new FakeComponentFactory (fakeInput, output, sizeMonitor));
  23. ApplicationImpl.SetInstance (impl);
  24. // Initialize with a fake driver
  25. impl.Init ("fake");
  26. return new FakeApplicationLifecycle (impl, hardStopTokenSource);
  27. }
  28. }