mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 07:47:54 +01:00
Replaced static `Application` references with instance-based `App` context across the codebase. Updated calls to `Application.RequestStop()` and `Application.Screen` to use `App?.RequestStop()` and `App?.Screen` for better encapsulation and flexibility. Refactored test infrastructure to align with the new context, including reintroducing `FakeApplicationFactory` and `FakeApplicationLifecycle` for testing purposes. Improved logging, error handling, and test clarity by adding `logWriter` support and simplifying test setup. Removed redundant or obsolete code, such as `NetSequences` and the old `FakeApplicationFactory` implementation. Updated documentation to reflect the new `IApplication.RequestStop()` usage.
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using System.Drawing;
|
|
using TerminalGuiFluentTesting;
|
|
|
|
namespace Terminal.Gui.Drivers;
|
|
|
|
/// <summary>
|
|
/// Provides methods to create and manage a fake application for testing purposes.
|
|
/// </summary>
|
|
public class FakeApplicationFactory
|
|
{
|
|
/// <summary>
|
|
/// Creates an initialized fake application which will be cleaned up when result object
|
|
/// is disposed.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public IDisposable SetupFakeApplication ()
|
|
{
|
|
CancellationTokenSource hardStopTokenSource = new CancellationTokenSource ();
|
|
FakeInput fakeInput = new FakeInput ();
|
|
fakeInput.ExternalCancellationTokenSource = hardStopTokenSource;
|
|
FakeOutput output = new ();
|
|
output.SetSize (80, 25);
|
|
|
|
SizeMonitorImpl sizeMonitor = new (output);
|
|
|
|
ApplicationImpl impl = new (new FakeComponentFactory (fakeInput, output, sizeMonitor));
|
|
ApplicationImpl.SetInstance (impl);
|
|
|
|
// Initialize with a fake driver
|
|
impl.Init ("fake");
|
|
|
|
return new FakeApplicationLifecycle (hardStopTokenSource);
|
|
}
|
|
}
|