ApplicationScreenTests.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace UnitTests.ApplicationTests;
  4. public class ApplicationScreenTests
  5. {
  6. public ApplicationScreenTests (ITestOutputHelper output)
  7. {
  8. ConsoleDriver.RunningUnitTests = true;
  9. }
  10. [Fact]
  11. public void ClearScreenNextIteration_Resets_To_False_After_LayoutAndDraw ()
  12. {
  13. // Arrange
  14. Application.ResetState (true);
  15. Application.Init ();
  16. // Act
  17. Application.ClearScreenNextIteration = true;
  18. Application.LayoutAndDraw ();
  19. // Assert
  20. Assert.False (Application.ClearScreenNextIteration);
  21. // Cleanup
  22. Application.ResetState (true);
  23. }
  24. [Fact]
  25. [AutoInitShutdown]
  26. public void ClearContents_Called_When_Top_Frame_Changes ()
  27. {
  28. Toplevel top = new Toplevel ();
  29. RunState rs = Application.Begin (top);
  30. // Arrange
  31. var clearedContentsRaised = 0;
  32. Application.Driver!.ClearedContents += OnClearedContents;
  33. // Act
  34. Application.LayoutAndDraw ();
  35. // Assert
  36. Assert.Equal (0, clearedContentsRaised);
  37. // Act
  38. Application.Top!.SetNeedsLayout ();
  39. Application.LayoutAndDraw ();
  40. // Assert
  41. Assert.Equal (0, clearedContentsRaised);
  42. // Act
  43. Application.Top.X = 1;
  44. Application.LayoutAndDraw ();
  45. // Assert
  46. Assert.Equal (1, clearedContentsRaised);
  47. // Act
  48. Application.Top.Width = 10;
  49. Application.LayoutAndDraw ();
  50. // Assert
  51. Assert.Equal (2, clearedContentsRaised);
  52. // Act
  53. Application.Top.Y = 1;
  54. Application.LayoutAndDraw ();
  55. // Assert
  56. Assert.Equal (3, clearedContentsRaised);
  57. // Act
  58. Application.Top.Height = 10;
  59. Application.LayoutAndDraw ();
  60. // Assert
  61. Assert.Equal (4, clearedContentsRaised);
  62. Application.End (rs);
  63. return;
  64. void OnClearedContents (object e, EventArgs a) { clearedContentsRaised++; }
  65. }
  66. [Fact]
  67. public void Screen_Changes_OnScreenChanged_Without_Call_Application_Init ()
  68. {
  69. // Arrange
  70. Application.ResetState (true);
  71. Assert.Null (Application.Driver);
  72. Application.Driver = new FakeDriver { Rows = 25, Cols = 25 };
  73. Application.SubscribeDriverEvents ();
  74. Assert.Equal (new (0, 0, 25, 25), Application.Screen);
  75. // Act
  76. Application.Driver.SetScreenSize(120,30);
  77. // Assert
  78. Assert.Equal (new (0, 0, 120, 30), Application.Screen);
  79. // Cleanup
  80. Application.ResetState (true);
  81. }
  82. }