BasicFluentAssertionTests.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. namespace UnitTests.FluentTests;
  9. public class BasicFluentAssertionTests
  10. {
  11. [Fact]
  12. public void GuiTestContext_StartsAndStopsWithoutError ()
  13. {
  14. using var context = With.A<Window> (40, 10);
  15. // No actual assertions are needed — if no exceptions are thrown, it's working
  16. context.Stop ();
  17. }
  18. [Fact]
  19. public void GuiTestContext_ForgotToStop ()
  20. {
  21. using var context = With.A<Window> (40, 10);
  22. }
  23. [Fact]
  24. public void TestWindowsResize ()
  25. {
  26. var lbl = new Label ()
  27. {
  28. Width = Dim.Fill ()
  29. };
  30. using var c = With.A<Window> (40, 10)
  31. .Add (lbl )
  32. .Assert (lbl.Frame.Width.Should().Be(38)) // Window has 2 border
  33. .ResizeConsole (20,20)
  34. .Assert (lbl.Frame.Width.Should ().Be (18))
  35. .Stop ();
  36. }
  37. [Fact]
  38. public void ContextMenu_CrashesOnRight ()
  39. {
  40. var clicked = false;
  41. var ctx = new ContextMenu ();
  42. var menuItems = new MenuBarItem (
  43. [
  44. new ("_New File", string.Empty, () => { clicked = true; })
  45. ]
  46. );
  47. using var c = With.A<Window> (40, 10)
  48. .WithContextMenu(ctx,menuItems)
  49. // Click in main area inside border
  50. .RightClick(1,1)
  51. .LeftClick (2, 2)
  52. /*.Assert (Application.Top.Focused.Should ().BeAssignableTo(typeof(MenuBarItem)))
  53. .Down()
  54. .Enter()*/
  55. .Stop ();
  56. Assert.True (clicked);
  57. }
  58. }