Fixes #4374 - Nukes all (?) legacy Driver and Application stuff; revamps tests (#4376)

This commit is contained in:
Tig
2025-11-11 16:29:33 -07:00
committed by GitHub
parent 559dea9239
commit d53fcd7485
310 changed files with 14827 additions and 16911 deletions

View File

@@ -3,7 +3,9 @@ using TerminalGuiFluentTesting;
namespace Terminal.Gui.Drivers;
#pragma warning disable CS1591
/// <summary>
/// Provides methods to create and manage a fake application for testing purposes.
/// </summary>
public class FakeApplicationFactory
{
/// <summary>
@@ -13,35 +15,23 @@ public class FakeApplicationFactory
/// <returns></returns>
public IDisposable SetupFakeApplication ()
{
var cts = new CancellationTokenSource ();
var fakeInput = new FakeNetInput (cts.Token);
CancellationTokenSource hardStopTokenSource = new CancellationTokenSource ();
FakeInput fakeInput = new FakeInput ();
fakeInput.ExternalCancellationTokenSource = hardStopTokenSource;
FakeOutput output = new ();
output.Size = new (80, 25);
output.SetSize (80, 25);
IApplication origApp = ApplicationImpl.Instance;
var sizeMonitor = new FakeSizeMonitor (output, output.LastBuffer!);
SizeMonitorImpl sizeMonitor = new (output);
var impl = new ApplicationImpl (new FakeNetComponentFactory (fakeInput, output, sizeMonitor));
ApplicationImpl impl = new (new FakeComponentFactory (fakeInput, output, sizeMonitor));
ApplicationImpl.ChangeInstance (impl);
// Initialize with a fake driver
impl.Init (null, "fake");
// Handle different facade types - cast to common interface instead
var d = (IConsoleDriverFacade)Application.Driver!;
sizeMonitor.SizeChanged += (_, e) =>
{
if (e.Size != null)
{
Size s = e.Size.Value;
output.Size = s;
d.OutputBuffer.SetSize (s.Width, s.Height);
}
};
return new FakeApplicationLifecycle (origApp, cts);
return new FakeApplicationLifecycle (origApp, hardStopTokenSource);
}
}