mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user