GuiTestContextTests.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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, Application.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 (Application.Top!.Running);
  40. Assert.NotEqual (Rectangle.Empty, Application.Screen);
  41. }
  42. [Theory]
  43. [ClassData (typeof (TestDrivers))]
  44. public void With_Starts_Stops_Without_Error (TestDriver d)
  45. {
  46. using GuiTestContext context = With.A<Window> (40, 10, d, _out);
  47. // No actual assertions are needed — if no exceptions are thrown, it's working
  48. }
  49. [Theory]
  50. [ClassData (typeof (TestDrivers))]
  51. public void With_Without_Stop_Still_Cleans_Up (TestDriver d)
  52. {
  53. GuiTestContext? context;
  54. using (context = With.A<Window> (40, 10, d, _out))
  55. {
  56. Assert.False (context.Finished);
  57. }
  58. Assert.True (context.Finished);
  59. }
  60. }