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.
87 lines
3.0 KiB
C#
87 lines
3.0 KiB
C#
using System.Drawing;
|
|
using TerminalGuiFluentTesting;
|
|
using TerminalGuiFluentTestingXunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace IntegrationTests.FluentTests;
|
|
|
|
/// <summary>
|
|
/// Basic tests for GuiTestContext functionality including constructor, lifecycle, and resize operations.
|
|
/// </summary>
|
|
public class GuiTestContextTests (ITestOutputHelper outputHelper)
|
|
{
|
|
private readonly TextWriter _out = new TestOutputWriter (outputHelper);
|
|
|
|
[Theory]
|
|
[ClassData (typeof (TestDrivers))]
|
|
public void Constructor_Sets_Application_Screen (TestDriver d)
|
|
{
|
|
using var context = new GuiTestContext (d, _out, TimeSpan.FromSeconds (10));
|
|
|
|
Assert.NotEqual (Rectangle.Empty, context.App?.Screen);
|
|
}
|
|
|
|
[Theory]
|
|
[ClassData (typeof (TestDrivers))]
|
|
public void ResizeConsole_Resizes (TestDriver d)
|
|
{
|
|
var lbl = new Label
|
|
{
|
|
Width = Dim.Fill ()
|
|
};
|
|
|
|
using GuiTestContext c = With.A<Window> (40, 10, d)
|
|
.Add (lbl)
|
|
.AssertEqual (38, lbl.Frame.Width) // Window has 2 border
|
|
.ResizeConsole (20, 20)
|
|
.WaitIteration ()
|
|
.AssertEqual (18, lbl.Frame.Width);
|
|
}
|
|
|
|
[Theory]
|
|
[ClassData (typeof (TestDrivers))]
|
|
public void With_New_A_Runs (TestDriver d)
|
|
{
|
|
using GuiTestContext context = With.A<Window> (40, 10, d, _out);
|
|
Assert.True (context.App!.TopRunnable!.Running);
|
|
Assert.NotEqual (Rectangle.Empty, context.App!.Screen);
|
|
}
|
|
|
|
[Theory]
|
|
[ClassData (typeof (TestDrivers))]
|
|
public void AnsiScreenShot_Renders_Ansi_Stream (TestDriver d)
|
|
{
|
|
using GuiTestContext context = With.A<Window> (10, 3, d, _out)
|
|
.Then ((app) =>
|
|
{
|
|
app.TopRunnable!.BorderStyle = LineStyle.None;
|
|
app.TopRunnable!.Border!.Thickness = Thickness.Empty;
|
|
app.TopRunnable.Text = "hello";
|
|
})
|
|
.ScreenShot ("ScreenShot", _out)
|
|
.AnsiScreenShot ("AnsiScreenShot", _out)
|
|
;
|
|
}
|
|
|
|
[Theory]
|
|
[ClassData (typeof (TestDrivers))]
|
|
public void With_Starts_Stops_Without_Error (TestDriver d)
|
|
{
|
|
using GuiTestContext context = With.A<Window> (40, 10, d, _out);
|
|
// No actual assertions are needed — if no exceptions are thrown, it's working
|
|
}
|
|
|
|
[Theory]
|
|
[ClassData (typeof (TestDrivers))]
|
|
public void With_Without_Stop_Still_Cleans_Up (TestDriver d)
|
|
{
|
|
GuiTestContext? context;
|
|
|
|
using (context = With.A<Window> (40, 10, d, _out))
|
|
{
|
|
Assert.False (context.Finished);
|
|
}
|
|
|
|
Assert.True (context.Finished);
|
|
}
|
|
} |