BasicFluentAssertionTests.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using FluentAssertions;
  7. using TerminalGuiFluentAssertions;
  8. using Xunit.Abstractions;
  9. namespace UnitTests.FluentTests;
  10. public class BasicFluentAssertionTests
  11. {
  12. private readonly TextWriter _out;
  13. public class TestOutputWriter : TextWriter
  14. {
  15. private readonly ITestOutputHelper _output;
  16. public TestOutputWriter (ITestOutputHelper output)
  17. {
  18. _output = output;
  19. }
  20. public override void WriteLine (string? value)
  21. {
  22. _output.WriteLine (value ?? string.Empty);
  23. }
  24. public override Encoding Encoding => Encoding.UTF8;
  25. }
  26. public BasicFluentAssertionTests (ITestOutputHelper outputHelper) { _out = new TestOutputWriter(outputHelper); }
  27. [Fact]
  28. public void GuiTestContext_StartsAndStopsWithoutError ()
  29. {
  30. using var context = With.A<Window> (40, 10);
  31. // No actual assertions are needed — if no exceptions are thrown, it's working
  32. context.Stop ();
  33. }
  34. [Fact]
  35. public void GuiTestContext_ForgotToStop ()
  36. {
  37. using var context = With.A<Window> (40, 10);
  38. }
  39. [Fact]
  40. public void TestWindowsResize ()
  41. {
  42. var lbl = new Label ()
  43. {
  44. Width = Dim.Fill ()
  45. };
  46. using var c = With.A<Window> (40, 10)
  47. .Add (lbl )
  48. .Assert (lbl.Frame.Width.Should().Be(38)) // Window has 2 border
  49. .ResizeConsole (20,20)
  50. .Assert (lbl.Frame.Width.Should ().Be (18))
  51. .Stop ();
  52. }
  53. [Fact]
  54. public void ContextMenu_CrashesOnRight ()
  55. {
  56. var clicked = false;
  57. var ctx = new ContextMenu ();
  58. var menuItems = new MenuBarItem (
  59. [
  60. new ("_New File", string.Empty, () => { clicked = true; })
  61. ]
  62. );
  63. using var c = With.A<Window> (40, 10)
  64. .WithContextMenu(ctx,menuItems)
  65. // Click in main area inside border
  66. .RightClick(1,1)
  67. .ScreenShot ("After open menu",_out)
  68. .LeftClick (3, 3)
  69. /*.Assert (Application.Top.Focused.Should ().BeAssignableTo(typeof(MenuBarItem)))
  70. .Down()
  71. .Enter()*/
  72. .Stop ();
  73. Assert.True (clicked);
  74. }
  75. }