AllViewsDrawTests.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Xunit.Abstractions;
  2. namespace Terminal.Gui.LayoutTests;
  3. public class AllViewsDrawTests (ITestOutputHelper _output) : TestsAllViews
  4. {
  5. [Theory]
  6. [MemberData (nameof (AllViewTypes))]
  7. public void AllViews_Draw_Does_Not_Layout (Type viewType)
  8. {
  9. Application.ResetState (true);
  10. var view = (View)CreateInstanceIfNotGeneric (viewType);
  11. if (view == null)
  12. {
  13. _output.WriteLine ($"Ignoring {viewType} - It's a Generic");
  14. return;
  15. }
  16. _output.WriteLine ($"Testing {viewType}");
  17. if (view is IDesignable designable)
  18. {
  19. designable.EnableForDesign ();
  20. }
  21. var drawCompleteCount = 0;
  22. view.DrawComplete += (s, e) => drawCompleteCount++;
  23. var layoutStartedCount = 0;
  24. view.SubviewLayout += (s, e) => layoutStartedCount++;
  25. var layoutCompleteCount = 0;
  26. view.SubviewsLaidOut += (s, e) => layoutCompleteCount++;
  27. view.SetNeedsLayout ();
  28. view.Layout ();
  29. Assert.Equal (0, drawCompleteCount);
  30. Assert.Equal (1, layoutStartedCount);
  31. Assert.Equal (1, layoutCompleteCount);
  32. view.SetNeedsDraw ();
  33. view.Draw ();
  34. Assert.Equal (1, drawCompleteCount);
  35. Assert.Equal (1, layoutStartedCount);
  36. Assert.Equal (1, layoutCompleteCount);
  37. }
  38. }