GuiTestContextTests.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System.Drawing;
  2. using TerminalGuiFluentTesting;
  3. using TerminalGuiFluentTestingXunit;
  4. using Xunit.Abstractions;
  5. namespace IntegrationTests.FluentTests;
  6. /// <summary>
  7. /// Basic tests for GuiTestContext functionality including constructor, lifecycle, and resize operations.
  8. /// </summary>
  9. public class GuiTestContextTests (ITestOutputHelper outputHelper)
  10. {
  11. private readonly TextWriter _out = new TestOutputWriter (outputHelper);
  12. [Theory]
  13. [ClassData (typeof (TestDrivers))]
  14. public void Constructor_Sets_Application_Screen (TestDriver d)
  15. {
  16. using var context = new GuiTestContext (d, _out, TimeSpan.FromSeconds (10));
  17. Assert.NotEqual (Rectangle.Empty, context.App?.Screen);
  18. }
  19. [Theory]
  20. [ClassData (typeof (TestDrivers))]
  21. public void ResizeConsole_Resizes (TestDriver d)
  22. {
  23. var lbl = new Label
  24. {
  25. Width = Dim.Fill ()
  26. };
  27. using GuiTestContext c = With.A<Window> (40, 10, d)
  28. .Add (lbl)
  29. .AssertEqual (38, lbl.Frame.Width) // Window has 2 border
  30. .ResizeConsole (20, 20)
  31. .WaitIteration ()
  32. .AssertEqual (18, lbl.Frame.Width);
  33. }
  34. [Theory]
  35. [ClassData (typeof (TestDrivers))]
  36. public void With_New_A_Runs (TestDriver d)
  37. {
  38. using GuiTestContext context = With.A<Window> (40, 10, d, _out);
  39. Assert.True (context.App!.TopRunnable!.Running);
  40. Assert.NotEqual (Rectangle.Empty, context.App!.Screen);
  41. }
  42. [Theory]
  43. [ClassData (typeof (TestDrivers))]
  44. public void AnsiScreenShot_Renders_Ansi_Stream (TestDriver d)
  45. {
  46. using GuiTestContext context = With.A<Window> (10, 3, d, _out)
  47. .Then ((app) =>
  48. {
  49. app.TopRunnable!.BorderStyle = LineStyle.None;
  50. app.TopRunnable!.Border!.Thickness = Thickness.Empty;
  51. app.TopRunnable.Text = "hello";
  52. })
  53. .ScreenShot ("ScreenShot", _out)
  54. .AnsiScreenShot ("AnsiScreenShot", _out)
  55. ;
  56. }
  57. [Theory]
  58. [ClassData (typeof (TestDrivers))]
  59. public void With_Starts_Stops_Without_Error (TestDriver d)
  60. {
  61. using GuiTestContext context = With.A<Window> (40, 10, d, _out);
  62. // No actual assertions are needed — if no exceptions are thrown, it's working
  63. }
  64. [Theory]
  65. [ClassData (typeof (TestDrivers))]
  66. public void With_Without_Stop_Still_Cleans_Up (TestDriver d)
  67. {
  68. GuiTestContext? context;
  69. using (context = With.A<Window> (40, 10, d, _out))
  70. {
  71. Assert.False (context.Finished);
  72. }
  73. Assert.True (context.Finished);
  74. }
  75. }