Sfoglia il codice sorgente

Merge pull request #3369 from tig/v2_3368_unit_tests_dispose

Fixes #3368. Fix unit tests to dispose properly
Tig 1 anno fa
parent
commit
ccfcfdc196
66 ha cambiato i file con 2263 aggiunte e 2197 eliminazioni
  1. 15 1
      Terminal.Gui/View/View.cs
  2. 2 2
      Terminal.Gui/Views/TableView/TableView.cs
  3. 4 4
      UnitTests/Application/ApplicationTests.cs
  4. 5 0
      UnitTests/Application/KeyboardTests.cs
  5. 2 0
      UnitTests/Application/MainLoopTests.cs
  6. 4 0
      UnitTests/Application/MouseTests.cs
  7. 10 1
      UnitTests/Dialogs/DialogTests.cs
  8. 32 41
      UnitTests/Dialogs/WizardTests.cs
  9. 0 6
      UnitTests/Drawing/AttributeTests.cs
  10. 3 3
      UnitTests/Drawing/ColorTests.ParsingAndFormatting.cs
  11. 121 114
      UnitTests/Drawing/LineCanvasTests.cs
  12. 16 16
      UnitTests/Drawing/RulerTests.cs
  13. 10 16
      UnitTests/Drawing/ThicknessTests.cs
  14. 30 21
      UnitTests/FileServices/FileDialogTests.cs
  15. 72 74
      UnitTests/Input/EscSeqUtilsTests.cs
  16. 1 1
      UnitTests/TestHelpers.cs
  17. 38 40
      UnitTests/Text/AutocompleteTests.cs
  18. 58 53
      UnitTests/View/Adornment/BorderTests.cs
  19. 2 5
      UnitTests/View/Adornment/MarginTests.cs
  20. 5 8
      UnitTests/View/Adornment/PaddingTests.cs
  21. 7 6
      UnitTests/View/DiagnosticsTests.cs
  22. 17 14
      UnitTests/View/DrawTests.cs
  23. 4 4
      UnitTests/View/InitTests.cs
  24. 1 0
      UnitTests/View/Layout/Dim.FillTests.cs
  25. 71 72
      UnitTests/View/Layout/Dim.Tests.cs
  26. 2 0
      UnitTests/View/Layout/Pos.AnchorEndTests.cs
  27. 24 24
      UnitTests/View/Layout/Pos.CenterTests.cs
  28. 3 2
      UnitTests/View/Layout/Pos.CombineTests.cs
  29. 12 13
      UnitTests/View/Layout/Pos.PercentTests.cs
  30. 1 0
      UnitTests/View/MouseTests.cs
  31. 17 12
      UnitTests/View/NavigationTests.cs
  32. 14 6
      UnitTests/View/TextTests.cs
  33. 6 3
      UnitTests/View/ViewKeyBindingTests.cs
  34. 118 107
      UnitTests/View/ViewTests.cs
  35. 9 4
      UnitTests/Views/AppendAutocompleteTests.cs
  36. 5 12
      UnitTests/Views/ButtonTests.cs
  37. 43 42
      UnitTests/Views/CheckBoxTests.cs
  38. 5 6
      UnitTests/Views/ColorPickerTests.cs
  39. 16 11
      UnitTests/Views/ComboBoxTests.cs
  40. 86 63
      UnitTests/Views/ContextMenuTests.cs
  41. 1 1
      UnitTests/Views/DateFieldTests.cs
  42. 3 1
      UnitTests/Views/DatePickerTests.cs
  43. 15 17
      UnitTests/Views/FrameViewTests.cs
  44. 15 10
      UnitTests/Views/HexViewTests.cs
  45. 185 184
      UnitTests/Views/LabelTests.cs
  46. 80 59
      UnitTests/Views/ListViewTests.cs
  47. 229 211
      UnitTests/Views/MenuBarTests.cs
  48. 13 1
      UnitTests/Views/OverlappedTests.cs
  49. 15 15
      UnitTests/Views/RadioGroupTests.cs
  50. 28 30
      UnitTests/Views/RuneCellTests.cs
  51. 49 11
      UnitTests/Views/ScrollBarViewTests.cs
  52. 71 65
      UnitTests/Views/ScrollViewTests.cs
  53. 3 0
      UnitTests/Views/SpinnerViewTests.cs
  54. 9 9
      UnitTests/Views/StatusBarTests.cs
  55. 93 91
      UnitTests/Views/TabViewTests.cs
  56. 133 160
      UnitTests/Views/TableViewTests.cs
  57. 63 68
      UnitTests/Views/TextFieldTests.cs
  58. 137 238
      UnitTests/Views/TextViewTests.cs
  59. 0 3
      UnitTests/Views/TileViewTests.cs
  60. 1 1
      UnitTests/Views/TimeFieldTests.cs
  61. 192 155
      UnitTests/Views/ToplevelTests.cs
  62. 6 2
      UnitTests/Views/TreeTableSourceTests.cs
  63. 12 42
      UnitTests/Views/TreeViewTests.cs
  64. 10 12
      UnitTests/Views/ViewDisposalTest.cs
  65. 3 0
      UnitTests/Views/WindowTests.cs
  66. 6 4
      docfx/docs/newinv2.md

+ 15 - 1
Terminal.Gui/View/View.cs

@@ -503,9 +503,23 @@ public partial class View : Responder, ISupportInitializeNotification
     /// <returns></returns>
     public override string ToString () { return $"{GetType ().Name}({Id}){Frame}"; }
 
-    /// <inheritdoc/>
+    /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
+    /// <remarks>
+    /// <para>
+    ///     Subviews added to this view via <see cref="Add(View)"/> have their lifetime owned by this view and <see cref="Dispose"/> will
+    ///     dispose them. To prevent this, and have the creator of the Subview instance handle disposal, use <see cref="Remove"/> to remove
+    ///     the subview first.
+    /// </para>
+    /// <para>
+    ///     If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and
+    ///     unmanaged resources can be disposed. If disposing equals false, the method has been called by the runtime from
+    ///     inside the finalizer, and you should not reference other objects. Only unmanaged resources can be disposed.
+    /// </para>
+    /// </remarks>
+    /// <param name="disposing"></param>
     protected override void Dispose (bool disposing)
     {
+        // BUGBUG: We should only dispose these objects if disposing == true
         LineCanvas.Dispose ();
 
         DisposeAdornments ();

+ 2 - 2
Terminal.Gui/Views/TableView/TableView.cs

@@ -908,10 +908,10 @@ public class TableView : View
         // What columns to render at what X offset in viewport
         ColumnToRender [] columnsToRender = CalculateViewport (Viewport).ToArray ();
 
-        Driver.SetAttribute (GetNormalColor ());
+        Driver?.SetAttribute (GetNormalColor ());
 
         //invalidate current row (prevents scrolling around leaving old characters in the frame
-        Driver.AddStr (new string (' ', Viewport.Width));
+        Driver?.AddStr (new string (' ', Viewport.Width));
 
         var line = 0;
 

+ 4 - 4
UnitTests/Application/ApplicationTests.cs

@@ -40,10 +40,12 @@ public class ApplicationTests
     public void Begin_Sets_Application_Top_To_Console_Size ()
     {
         Assert.Null (Application.Top);
-        Application.Begin (new ());
+        Toplevel top = new ();
+        Application.Begin (top);
         Assert.Equal (new (0, 0, 80, 25), Application.Top.Frame);
         ((FakeDriver)Application.Driver).SetBufferSize (5, 5);
         Assert.Equal (new (0, 0, 5, 5), Application.Top.Frame);
+        top.Dispose ();
     }
 
     [Fact]
@@ -265,8 +267,6 @@ public class ApplicationTests
     {
         Application.Init (new FakeDriver ());
 
-        Toplevel topLevel = null;
-
         Assert.Throws<InvalidOperationException> (
                                                   () =>
                                                       Application.InternalInit (
@@ -280,7 +280,6 @@ public class ApplicationTests
         Assert.Null (Application.Driver);
 
         // Now try the other way
-        topLevel = null;
         Application.InternalInit (new FakeDriver ());
 
         Assert.Throws<InvalidOperationException> (() => Application.Init (new FakeDriver ()));
@@ -347,6 +346,7 @@ public class ApplicationTests
         Assert.Null (Application.MouseGrabView); // public
         Assert.Null (Application.WantContinuousButtonPressedView); // public
         Assert.False (Application.MoveToOverlappedChild (Application.Top));
+        Application.Top.Dispose ();
     }
 
     // Invoke Tests

+ 5 - 0
UnitTests/Application/KeyboardTests.cs

@@ -172,6 +172,7 @@ public class KeyboardTests
         Assert.True (win2.CanFocus);
         Assert.True (win2.HasFocus);
         Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
+        top.Dispose ();
     }
 
     [Fact]
@@ -224,6 +225,7 @@ public class KeyboardTests
         Assert.True (win2.CanFocus);
         Assert.False (win2.HasFocus);
         Assert.Equal ("win", ((Window)top.Subviews [^1]).Title);
+        top.Dispose ();
     }
 
     [Fact]
@@ -358,6 +360,7 @@ public class KeyboardTests
         Assert.True (view.ApplicationCommand);
         Assert.True (view.HotKeyCommand);
         Assert.False (view.FocusedCommand);
+        top.Dispose ();
     }
 
     [Fact]
@@ -385,6 +388,7 @@ public class KeyboardTests
         Assert.False (view.ApplicationCommand);
         Assert.False (view.HotKeyCommand);
         Assert.False (view.FocusedCommand);
+        top.Dispose ();
     }
 
     [Fact]
@@ -423,6 +427,7 @@ public class KeyboardTests
 
         // Reset the QuitKey to avoid throws errors on another tests
         Application.QuitKey = Key.Q.WithCtrl;
+        top.Dispose ();
     }
 
     // test Application key Bindings

+ 2 - 0
UnitTests/Application/MainLoopTests.cs

@@ -640,6 +640,7 @@ public class MainLoopTests
         await task; // Propagate exception if any occurred
 
         Assert.Equal (numIncrements * numPasses, tbCounter);
+        top.Dispose ();
     }
 
     [Theory]
@@ -714,6 +715,7 @@ public class MainLoopTests
                                  };
 
         Application.Run (top);
+        top.Dispose ();
 
         Assert.True (taskCompleted);
         Assert.Equal (clickMe, btn.Text);

+ 4 - 0
UnitTests/Application/MouseTests.cs

@@ -130,6 +130,7 @@ public class MouseTests
 
         Application.OnMouseEvent (mouseEvent);
         Assert.Equal (expectedClicked, clicked);
+        top.Dispose ();
     }
 
     /// <summary>
@@ -224,6 +225,7 @@ public class MouseTests
 
         Application.OnMouseEvent (mouseEvent);
         Assert.Equal (expectedClicked, clicked);
+        top.Dispose ();
     }
 
     #endregion mouse coordinate tests
@@ -290,6 +292,7 @@ public class MouseTests
                                  };
 
         Application.Run (top);
+        top.Dispose ();
     }
 
     [Fact]
@@ -396,6 +399,7 @@ public class MouseTests
         Application.OnMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Pressed });
         Assert.Null (Application.MouseGrabView);
         Assert.Equal (0, count);
+        top.Dispose ();
     }
     #endregion
 }

+ 10 - 1
UnitTests/Dialogs/DialogTests.cs

@@ -906,8 +906,10 @@ public class DialogTests
                                         };
 
                           Run (dlg);
+                          dlg.Dispose ();
                       };
         Run (win);
+        win.Dispose ();
     }
 
     [Theory]
@@ -988,6 +990,7 @@ public class DialogTests
                                  Height = Dim.Percent (85)
                              };
                              Run (dlg);
+                             dlg.Dispose ();
                          }
                          else if (iterations == 1)
                          {
@@ -1001,6 +1004,7 @@ public class DialogTests
                      };
 
         Run (win);
+        win.Dispose ();
     }
 
     [Fact]
@@ -1134,6 +1138,7 @@ public class DialogTests
         // Default location is centered, so 100 / 2 - 85 / 2 = 7
         var expected = 7;
         Assert.Equal (new (expected, expected), d.Frame.Location);
+        d.Dispose ();
     }
 
     [Fact]
@@ -1147,6 +1152,7 @@ public class DialogTests
         // Default location is centered, so 100 / 2 - 85 / 2 = 7
         var expected = 1;
         Assert.Equal (new (expected, expected), d.Frame.Location);
+        d.Dispose ();
     }
 
     [Fact]
@@ -1170,6 +1176,7 @@ public class DialogTests
      └───┘",
                                                       _output
                                                      );
+        d.Dispose ();
     }
 
     [Fact]
@@ -1263,6 +1270,7 @@ public class DialogTests
 
         ((FakeDriver)Driver).SetBufferSize (20, 10);
         Run (top);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1282,7 +1290,7 @@ public class DialogTests
         int width = buttonRow.Length;
         d.SetBufferSize (buttonRow.Length, 10);
 
-        (runstate, Dialog _) = RunButtonTestDialog (
+        (runstate, Dialog dlg) = RunButtonTestDialog (
                                                     title,
                                                     width,
                                                     Alignment.Center,
@@ -1290,6 +1298,7 @@ public class DialogTests
                                                    );
         TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
         End (runstate);
+        dlg.Dispose ();
     }
 
     [Fact]

+ 32 - 41
UnitTests/Dialogs/WizardTests.cs

@@ -2,21 +2,16 @@
 
 namespace Terminal.Gui.DialogTests;
 
-public class WizardTests
+public class WizardTests ()
 {
-    private readonly ITestOutputHelper _output;
-    public WizardTests (ITestOutputHelper output) { _output = output; }
-
     // =========== Wizard Tests
     [Fact]
-    [AutoInitShutdown]
     public void DefaultConstructor_SizedProperly ()
     {
-        var d = (FakeDriver)Application.Driver;
-
         var wizard = new Wizard ();
         Assert.NotEqual (0, wizard.Width);
         Assert.NotEqual (0, wizard.Height);
+        wizard.Dispose ();
     }
 
     [Fact]
@@ -47,9 +42,9 @@ public class WizardTests
         wizard.Dispose ();
 
         // Same test, but with two steps
-        wizard = new Wizard ();
+        wizard = new ();
         firstIteration = false;
-        step1 = new WizardStep { Title = "step1" };
+        step1 = new() { Title = "step1" };
         wizard.AddStep (step1);
         var step2 = new WizardStep { Title = "step2" };
         wizard.AddStep (step2);
@@ -80,11 +75,11 @@ public class WizardTests
         wizard.Dispose ();
 
         // Same test, but with two steps but the 1st one disabled
-        wizard = new Wizard ();
+        wizard = new ();
         firstIteration = false;
-        step1 = new WizardStep { Title = "step1" };
+        step1 = new() { Title = "step1" };
         wizard.AddStep (step1);
-        step2 = new WizardStep { Title = "step2" };
+        step2 = new() { Title = "step2" };
         wizard.AddStep (step2);
         step1.Enabled = false;
 
@@ -103,10 +98,10 @@ public class WizardTests
         Application.End (runstate);
         Assert.True (finishedFired);
         Assert.True (closedFired);
+        wizard.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void Navigate_GetFirstStep_Works ()
     {
         var wizard = new Wizard ();
@@ -134,10 +129,10 @@ public class WizardTests
         step1.Enabled = false;
         step2.Enabled = false;
         Assert.Equal (step3.Title, wizard.GetFirstStep ().Title);
+        wizard.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void Navigate_GetLastStep_Works ()
     {
         var wizard = new Wizard ();
@@ -165,6 +160,7 @@ public class WizardTests
         step3.Enabled = false;
         step2.Enabled = false;
         Assert.Equal (step1.Title, wizard.GetLastStep ().Title);
+        wizard.Dispose ();
     }
 
     [Fact]
@@ -263,6 +259,7 @@ public class WizardTests
         step2.Enabled = false;
         step3.Enabled = false;
         Assert.Equal (step1.Title, wizard.GetNextStep ().Title);
+        wizard.Dispose ();
     }
 
     [Fact]
@@ -356,10 +353,10 @@ public class WizardTests
         step2.Enabled = false;
         step3.Enabled = false;
         Assert.Equal (step1.Title, wizard.GetPreviousStep ().Title);
+        wizard.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void Navigate_GoBack_Works ()
     {
         // If zero steps do nothing
@@ -374,7 +371,6 @@ public class WizardTests
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void Navigate_GoNext_Works ()
     {
         // If zero steps do nothing
@@ -429,16 +425,16 @@ public class WizardTests
             } - {
                 stepTitle
             }╞{
-                new string (CM.Glyphs.HLineDbl.ToString () [0], width - title.Length - stepTitle.Length - 7)
+                new (CM.Glyphs.HLineDbl.ToString () [0], width - title.Length - stepTitle.Length - 7)
             }{
                 CM.Glyphs.URCornerDbl
             }";
-        var row2 = $"{CM.Glyphs.VLineDbl}{new string (' ', width - 2)}{CM.Glyphs.VLineDbl}";
+        var row2 = $"{CM.Glyphs.VLineDbl}{new (' ', width - 2)}{CM.Glyphs.VLineDbl}";
         string row3 = row2;
         string row4 = row3;
 
         var separatorRow =
-            $"{CM.Glyphs.VLineDbl}{new string (CM.Glyphs.HLine.ToString () [0], width - 2)}{CM.Glyphs.VLineDbl}";
+            $"{CM.Glyphs.VLineDbl}{new (CM.Glyphs.HLine.ToString () [0], width - 2)}{CM.Glyphs.VLineDbl}";
 
         var buttonRow =
             $"{
@@ -446,7 +442,7 @@ public class WizardTests
             }{
                 btnBack
             }{
-                new string (' ', width - btnBack.Length - btnNext.Length - 2)
+                new (' ', width - btnBack.Length - btnNext.Length - 2)
             }{
                 btnNext
             }{
@@ -457,13 +453,13 @@ public class WizardTests
             $"{
                 CM.Glyphs.LLCornerDbl
             }{
-                new string (CM.Glyphs.HLineDbl.ToString () [0], width - 2)
+                new (CM.Glyphs.HLineDbl.ToString () [0], width - 2)
             }{
                 CM.Glyphs.LRCornerDbl
             }";
 
         var wizard = new Wizard { Title = title, Width = width, Height = height };
-        wizard.AddStep (new WizardStep { Title = stepTitle });
+        wizard.AddStep (new() { Title = stepTitle });
 
         //wizard.LayoutSubviews ();
         var firstIteration = false;
@@ -476,6 +472,7 @@ public class WizardTests
         //                                              _output
         //                                             );
         Application.End (runstate);
+        wizard.Dispose ();
     }
 
     [Fact]
@@ -516,36 +513,36 @@ public class WizardTests
             }{
                 stepTitle
             }╞{
-                new string (CM.Glyphs.HLineDbl.ToString () [0], width - title.Length - stepTitle.Length - 4)
+                new (CM.Glyphs.HLineDbl.ToString () [0], width - title.Length - stepTitle.Length - 4)
             }{
                 CM.Glyphs.URCornerDbl
             }";
 
         var separatorRow =
-            $"{CM.Glyphs.VLineDbl}{new string (CM.Glyphs.HLine.ToString () [0], width - 2)}{CM.Glyphs.VLineDbl}";
+            $"{CM.Glyphs.VLineDbl}{new (CM.Glyphs.HLine.ToString () [0], width - 2)}{CM.Glyphs.VLineDbl}";
 
         // Once this is fixed, revert to commented out line: https://github.com/gui-cs/Terminal.Gui/issues/1791
         var buttonRow =
-            $"{CM.Glyphs.VLineDbl}{new string (' ', width - btnNext.Length - 2)}{btnNext}{CM.Glyphs.VLineDbl}";
+            $"{CM.Glyphs.VLineDbl}{new (' ', width - btnNext.Length - 2)}{btnNext}{CM.Glyphs.VLineDbl}";
 
         //var buttonRow = $"{CM.Glyphs.VDLine}{new String (' ', width - btnNext.Length - 2)}{btnNext}{CM.Glyphs.VDLine}";
         var bottomRow =
             $"{
                 CM.Glyphs.LLCornerDbl
             }{
-                new string (CM.Glyphs.HLineDbl.ToString () [0], width - 2)
+                new (CM.Glyphs.HLineDbl.ToString () [0], width - 2)
             }{
                 CM.Glyphs.LRCornerDbl
             }";
 
         var wizard = new Wizard { Title = title, Width = width, Height = height };
-        wizard.AddStep (new WizardStep { Title = "ABCD" });
+        wizard.AddStep (new() { Title = "ABCD" });
 
         Application.End (Application.Begin (wizard));
+        wizard.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
 
     // This test verifies that the 2nd step in a wizard with more than 2 steps 
     // shows the correct buttons on all steps
@@ -564,7 +561,6 @@ public class WizardTests
     }
 
     [Fact]
-    [AutoInitShutdown]
 
     // This test verifies that the 2nd step in a wizard with 2 steps 
     // shows the correct buttons on both steps
@@ -585,7 +581,6 @@ public class WizardTests
     // =========== WizardStep Tests
 
     [Fact]
-    [AutoInitShutdown]
     public void WizardStep_ButtonText ()
     {
         // Verify default button text
@@ -684,15 +679,15 @@ public class WizardTests
             }{
                 stepTitle
             }╞{
-                new string (CM.Glyphs.HLineDbl.ToString () [0], width - title.Length - stepTitle.Length - 4)
+                new (CM.Glyphs.HLineDbl.ToString () [0], width - title.Length - stepTitle.Length - 4)
             }{
                 CM.Glyphs.URCornerDbl
             }";
-        var row2 = $"{CM.Glyphs.VLineDbl}{new string (' ', width - 2)}{CM.Glyphs.VLineDbl}";
+        var row2 = $"{CM.Glyphs.VLineDbl}{new (' ', width - 2)}{CM.Glyphs.VLineDbl}";
         string row3 = row2;
 
         var separatorRow =
-            $"{CM.Glyphs.VLineDbl}{new string (CM.Glyphs.HLine.ToString () [0], width - 2)}{CM.Glyphs.VLineDbl}";
+            $"{CM.Glyphs.VLineDbl}{new (CM.Glyphs.HLine.ToString () [0], width - 2)}{CM.Glyphs.VLineDbl}";
 
         var buttonRow =
             $"{
@@ -700,7 +695,7 @@ public class WizardTests
             }{
                 btnBack
             }{
-                new string (' ', width - btnBack.Length - btnNext.Length - 2)
+                new (' ', width - btnBack.Length - btnNext.Length - 2)
             }{
                 btnNext
             }{
@@ -711,24 +706,20 @@ public class WizardTests
             $"{
                 CM.Glyphs.LLCornerDbl
             }{
-                new string (CM.Glyphs.HLineDbl.ToString () [0], width - 2)
+                new (CM.Glyphs.HLineDbl.ToString () [0], width - 2)
             }{
                 CM.Glyphs.LRCornerDbl
             }";
 
         var wizard = new Wizard { Title = title, Width = width, Height = height };
         RunState runstate = Application.Begin (wizard);
+
         // TODO: Disabled until Dim.Auto is used in Dialog
         //TestHelpers.AssertDriverContentsWithFrameAre (
         //                                              $"{topRow}\n{row2}\n{row3}\n{separatorRow}\n{buttonRow}\n{bottomRow}",
         //                                              _output
         //                                             );
         Application.End (runstate);
-    }
-
-    private void RunButtonTestWizard (string title, int width, int height)
-    {
-        var wizard = new Wizard { Title = title, Width = width, Height = height };
-        Application.End (Application.Begin (wizard));
+        wizard.Dispose ();
     }
 }

+ 0 - 6
UnitTests/Drawing/AttributeTests.cs

@@ -12,7 +12,6 @@ public class AttributeTests
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void ColorAndColorNamesConstructor ()
     {
         // Arrange & Act
@@ -26,7 +25,6 @@ public class AttributeTests
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void ColorConstructor ()
     {
         // Arrange & Act
@@ -143,11 +141,8 @@ public class AttributeTests
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void Equals_Initialized ()
     {
-        Assert.NotNull (Application.Driver);
-
         var attr1 = new Attribute (Color.Red, Color.Green);
         var attr2 = new Attribute (Color.Red, Color.Green);
 
@@ -324,7 +319,6 @@ public class AttributeTests
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void NotEquals_Initialized ()
     {
         var attr1 = new Attribute (Color.Red, Color.Green);

+ 3 - 3
UnitTests/Drawing/ColorTests.ParsingAndFormatting.cs

@@ -84,7 +84,7 @@ public partial class ColorTests
                 )]
     public void TryParse_string_Returns_False_For_Invalid_Inputs (string? input)
     {
-        bool tryParseStatus = Color.TryParse (input, out Color? color);
+        bool tryParseStatus = Color.TryParse (input ?? string.Empty, out Color? color);
         Assert.False (tryParseStatus);
         Assert.Null (color);
     }
@@ -94,9 +94,9 @@ public partial class ColorTests
                     nameof (ColorTestsTheoryDataGenerators.TryParse_string_Returns_True_For_Valid_Inputs),
                     MemberType = typeof (ColorTestsTheoryDataGenerators)
                 )]
-    public void TryParse_string_Returns_True_For_Valid_Inputs (string input, int expectedColorArgb)
+    public void TryParse_string_Returns_True_For_Valid_Inputs (string? input, int expectedColorArgb)
     {
-        bool tryParseStatus = Color.TryParse (input, out Color? color);
+        bool tryParseStatus = Color.TryParse (input ?? string.Empty, out Color? color);
         Assert.True (tryParseStatus);
         Assert.NotNull (color);
         Assert.IsType<Color> (color);

+ 121 - 114
UnitTests/Drawing/LineCanvasTests.cs

@@ -3,13 +3,9 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.DrawingTests;
 
-public class LineCanvasTests
+public class LineCanvasTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper output;
-    public LineCanvasTests (ITestOutputHelper output) { this.output = output; }
-
     [Theory]
-    [AutoInitShutdown]
 
     // Horizontal lines with a vertical zero-length
     [InlineData (
@@ -293,12 +289,13 @@ public class LineCanvasTests
         View v = GetCanvas (out LineCanvas lc);
         v.Width = 10;
         v.Height = 10;
-        v.Viewport = new Rectangle (0, 0, 10, 10);
+        v.Viewport = new (0, 0, 10, 10);
 
-        lc.AddLine (new Point (x1, y1), len1, o1, s1);
-        lc.AddLine (new Point (x2, y2), len2, o2, s2);
+        lc.AddLine (new (x1, y1), len1, o1, s1);
+        lc.AddLine (new (x2, y2), len2, o2, s2);
 
         TestHelpers.AssertEqual (output, expected, lc.ToString ());
+        v.Dispose ();
     }
 
     [InlineData (
@@ -377,10 +374,10 @@ public class LineCanvasTests
     )
     {
         var canvas = new LineCanvas ();
-        canvas.AddLine (new Point (x, y), length, Orientation.Horizontal, LineStyle.Single);
-        canvas.AddLine (new Point (x, y), length, Orientation.Vertical, LineStyle.Single);
+        canvas.AddLine (new (x, y), length, Orientation.Horizontal, LineStyle.Single);
+        canvas.AddLine (new (x, y), length, Orientation.Vertical, LineStyle.Single);
 
-        Assert.Equal (new Rectangle (expectedX, expectedY, expectedWidth, expectedHeight), canvas.Viewport);
+        Assert.Equal (new (expectedX, expectedY, expectedWidth, expectedHeight), canvas.Viewport);
     }
 
     [InlineData (
@@ -459,9 +456,9 @@ public class LineCanvasTests
     )
     {
         var canvas = new LineCanvas ();
-        canvas.AddLine (new Point (x, y), length, Orientation.Horizontal, LineStyle.Single);
+        canvas.AddLine (new (x, y), length, Orientation.Horizontal, LineStyle.Single);
 
-        Assert.Equal (new Rectangle (expectedX, expectedY, expectedWidth, expectedHeight), canvas.Viewport);
+        Assert.Equal (new (expectedX, expectedY, expectedWidth, expectedHeight), canvas.Viewport);
     }
 
     [Fact]
@@ -482,28 +479,28 @@ public class LineCanvasTests
         // ║  ║2
 
         // Add a short horiz line for ╔╡
-        lc.AddLine (new Point (x, y), 2, Orientation.Horizontal, LineStyle.Double);
-        Assert.Equal (new Rectangle (x, y, 2, 1), lc.Viewport);
+        lc.AddLine (new (x, y), 2, Orientation.Horizontal, LineStyle.Double);
+        Assert.Equal (new (x, y, 2, 1), lc.Viewport);
 
         //LHS line down
-        lc.AddLine (new Point (x, y), height, Orientation.Vertical, LineStyle.Double);
-        Assert.Equal (new Rectangle (x, y, 2, 2), lc.Viewport);
+        lc.AddLine (new (x, y), height, Orientation.Vertical, LineStyle.Double);
+        Assert.Equal (new (x, y, 2, 2), lc.Viewport);
 
         //Vertical line before Title, results in a ╡
-        lc.AddLine (new Point (x + 1, y), 0, Orientation.Vertical, LineStyle.Single);
-        Assert.Equal (new Rectangle (x, y, 2, 2), lc.Viewport);
+        lc.AddLine (new (x + 1, y), 0, Orientation.Vertical, LineStyle.Single);
+        Assert.Equal (new (x, y, 2, 2), lc.Viewport);
 
         //Vertical line after Title, results in a ╞
-        lc.AddLine (new Point (x + 2, y), 0, Orientation.Vertical, LineStyle.Single);
-        Assert.Equal (new Rectangle (x, y, 3, 2), lc.Viewport);
+        lc.AddLine (new (x + 2, y), 0, Orientation.Vertical, LineStyle.Single);
+        Assert.Equal (new (x, y, 3, 2), lc.Viewport);
 
         // remainder of top line
-        lc.AddLine (new Point (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double);
-        Assert.Equal (new Rectangle (x, y, 4, 2), lc.Viewport);
+        lc.AddLine (new (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double);
+        Assert.Equal (new (x, y, 4, 2), lc.Viewport);
 
         //RHS line down
-        lc.AddLine (new Point (x + width, y), height, Orientation.Vertical, LineStyle.Double);
-        Assert.Equal (new Rectangle (x, y, 4, 2), lc.Viewport);
+        lc.AddLine (new (x + width, y), height, Orientation.Vertical, LineStyle.Double);
+        Assert.Equal (new (x, y, 4, 2), lc.Viewport);
 
         TestHelpers.AssertEqual (
                                  output,
@@ -532,28 +529,28 @@ public class LineCanvasTests
         // ║  ║2
 
         // Add a short horiz line for ╔╡
-        lc.AddLine (new Point (x, y), 2, Orientation.Horizontal, LineStyle.Double);
-        Assert.Equal (new Rectangle (x, y, 2, 1), lc.Viewport);
+        lc.AddLine (new (x, y), 2, Orientation.Horizontal, LineStyle.Double);
+        Assert.Equal (new (x, y, 2, 1), lc.Viewport);
 
         //LHS line down
-        lc.AddLine (new Point (x, y), height, Orientation.Vertical, LineStyle.Double);
-        Assert.Equal (new Rectangle (x, y, 2, 2), lc.Viewport);
+        lc.AddLine (new (x, y), height, Orientation.Vertical, LineStyle.Double);
+        Assert.Equal (new (x, y, 2, 2), lc.Viewport);
 
         //Vertical line before Title, results in a ╡
-        lc.AddLine (new Point (x + 1, y), 0, Orientation.Vertical, LineStyle.Single);
-        Assert.Equal (new Rectangle (x, y, 2, 2), lc.Viewport);
+        lc.AddLine (new (x + 1, y), 0, Orientation.Vertical, LineStyle.Single);
+        Assert.Equal (new (x, y, 2, 2), lc.Viewport);
 
         //Vertical line after Title, results in a ╞
-        lc.AddLine (new Point (x + 2, y), 0, Orientation.Vertical, LineStyle.Single);
-        Assert.Equal (new Rectangle (x, y, 3, 2), lc.Viewport);
+        lc.AddLine (new (x + 2, y), 0, Orientation.Vertical, LineStyle.Single);
+        Assert.Equal (new (x, y, 3, 2), lc.Viewport);
 
         // remainder of top line
-        lc.AddLine (new Point (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double);
-        Assert.Equal (new Rectangle (x, y, 4, 2), lc.Viewport);
+        lc.AddLine (new (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double);
+        Assert.Equal (new (x, y, 4, 2), lc.Viewport);
 
         //RHS line down
-        lc.AddLine (new Point (x + width, y), height, Orientation.Vertical, LineStyle.Double);
-        Assert.Equal (new Rectangle (x, y, 4, 2), lc.Viewport);
+        lc.AddLine (new (x + width, y), height, Orientation.Vertical, LineStyle.Double);
+        Assert.Equal (new (x, y, 4, 2), lc.Viewport);
 
         TestHelpers.AssertEqual (
                                  output,
@@ -598,7 +595,7 @@ public class LineCanvasTests
         var canvas = new LineCanvas ();
 
         // Add a line at 5, 5 that's has length of 1
-        canvas.AddLine (new Point (x, y), 1, orientation, LineStyle.Single);
+        canvas.AddLine (new (x, y), 1, orientation, LineStyle.Single);
         TestHelpers.AssertEqual (output, $"{expected}", $"{canvas}");
     }
 
@@ -653,7 +650,7 @@ public class LineCanvasTests
     public void Length_n_Is_n_Long (int x, int y, int length, Orientation orientation, string expected)
     {
         var canvas = new LineCanvas ();
-        canvas.AddLine (new Point (x, y), length, orientation, LineStyle.Single);
+        canvas.AddLine (new (x, y), length, orientation, LineStyle.Single);
 
         var result = canvas.ToString ();
         TestHelpers.AssertEqual (output, expected, result);
@@ -731,7 +728,6 @@ public class LineCanvasTests
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void TestLineCanvas_LeaveMargin_Top1_Left1 ()
     {
         var canvas = new LineCanvas ();
@@ -748,19 +744,19 @@ public class LineCanvasTests
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void TestLineCanvas_Window_Heavy ()
     {
         View v = GetCanvas (out LineCanvas canvas);
 
         // outer box
         canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Heavy);
-        canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Heavy);
-        canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Heavy);
-        canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Heavy);
+        canvas.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Heavy);
+        canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Heavy);
+        canvas.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Heavy);
 
-        canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Heavy);
-        canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Heavy);
+        canvas.AddLine (new (5, 0), 5, Orientation.Vertical, LineStyle.Heavy);
+        canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, LineStyle.Heavy);
 
         v.Draw ();
 
@@ -772,10 +768,11 @@ public class LineCanvasTests
 ┃    ┃   ┃
 ┗━━━━┻━━━┛";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     [Theory]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     [InlineData (LineStyle.Single)]
     [InlineData (LineStyle.Rounded)]
     public void TestLineCanvas_Window_HeavyTop_ThinSides (LineStyle thinStyle)
@@ -784,12 +781,12 @@ public class LineCanvasTests
 
         // outer box
         canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Heavy);
-        canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, thinStyle);
-        canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Heavy);
-        canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, thinStyle);
+        canvas.AddLine (new (9, 0), 5, Orientation.Vertical, thinStyle);
+        canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Heavy);
+        canvas.AddLine (new (0, 4), -5, Orientation.Vertical, thinStyle);
 
-        canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, thinStyle);
-        canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Heavy);
+        canvas.AddLine (new (5, 0), 5, Orientation.Vertical, thinStyle);
+        canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, LineStyle.Heavy);
 
         v.Draw ();
 
@@ -802,10 +799,11 @@ public class LineCanvasTests
 ┕━━━━┷━━━┙
 ";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     [Theory]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     [InlineData (LineStyle.Single)]
     [InlineData (LineStyle.Rounded)]
     public void TestLineCanvas_Window_ThinTop_HeavySides (LineStyle thinStyle)
@@ -814,12 +812,12 @@ public class LineCanvasTests
 
         // outer box
         canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, thinStyle);
-        canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Heavy);
-        canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, thinStyle);
-        canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Heavy);
+        canvas.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Heavy);
+        canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, thinStyle);
+        canvas.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Heavy);
 
-        canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Heavy);
-        canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, thinStyle);
+        canvas.AddLine (new (5, 0), 5, Orientation.Vertical, LineStyle.Heavy);
+        canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, thinStyle);
 
         v.Draw ();
 
@@ -833,6 +831,7 @@ public class LineCanvasTests
 
 ";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     [Fact]
@@ -843,7 +842,7 @@ public class LineCanvasTests
 
         // Upper box
         canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Single);
-        canvas.AddLine (new Point (0, 1), -2, Orientation.Vertical, LineStyle.Single);
+        canvas.AddLine (new (0, 1), -2, Orientation.Vertical, LineStyle.Single);
 
         var looksLike =
             @"
@@ -862,7 +861,7 @@ public class LineCanvasTests
         canvas.AddLine (Point.Empty, 1, Orientation.Horizontal, LineStyle.Single);
 
         // Bottom   ─
-        canvas.AddLine (new Point (1, 1), -1, Orientation.Horizontal, LineStyle.Single);
+        canvas.AddLine (new (1, 1), -1, Orientation.Horizontal, LineStyle.Single);
 
         //// Right down
         //canvas.AddLine (new Point (9, 0), 3, Orientation.Vertical, LineStyle.Single);
@@ -873,7 +872,7 @@ public class LineCanvasTests
         //// Left Up
         //canvas.AddLine (new Point (0, 3), -3, Orientation.Vertical, LineStyle.Single);
 
-        Assert.Equal (new Rectangle (0, 0, 2, 2), canvas.Viewport);
+        Assert.Equal (new (0, 0, 2, 2), canvas.Viewport);
 
         Dictionary<Point, Rune> map = canvas.GetMap ();
         Assert.Equal (2, map.Count);
@@ -910,7 +909,7 @@ public class LineCanvasTests
     public void ToString_Positive_Horizontal_1Line_Offset (int x, int y, string expected)
     {
         var lc = new LineCanvas ();
-        lc.AddLine (new Point (x, y), 3, Orientation.Horizontal, LineStyle.Double);
+        lc.AddLine (new (x, y), 3, Orientation.Horizontal, LineStyle.Double);
         TestHelpers.AssertEqual (output, expected, $"{lc}");
     }
 
@@ -933,8 +932,8 @@ public class LineCanvasTests
     public void ToString_Positive_Horizontal_2Line_Offset (int x1, int y1, int x2, int y2, string expected)
     {
         var lc = new LineCanvas ();
-        lc.AddLine (new Point (x1, y1), 3, Orientation.Horizontal, LineStyle.Double);
-        lc.AddLine (new Point (x2, y2), 3, Orientation.Horizontal, LineStyle.Double);
+        lc.AddLine (new (x1, y1), 3, Orientation.Horizontal, LineStyle.Double);
+        lc.AddLine (new (x2, y2), 3, Orientation.Horizontal, LineStyle.Double);
 
         TestHelpers.AssertEqual (output, expected, $"{lc}");
     }
@@ -976,7 +975,7 @@ public class LineCanvasTests
     [InlineData (0, 0, 2, Orientation.Vertical, LineStyle.Double, "║\n║")]
     [InlineData (0, 0, 2, Orientation.Horizontal, LineStyle.Single, "──")]
     [InlineData (0, 0, 2, Orientation.Vertical, LineStyle.Single, "│\n│")]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     [Theory]
     public void View_Draws_1LineTests (
         int x1,
@@ -990,18 +989,19 @@ public class LineCanvasTests
         View v = GetCanvas (out LineCanvas lc);
         v.Width = 10;
         v.Height = 10;
-        v.Viewport = new Rectangle (0, 0, 10, 10);
+        v.Viewport = new (0, 0, 10, 10);
 
-        lc.AddLine (new Point (x1, y1), length, o1, s1);
+        lc.AddLine (new (x1, y1), length, o1, s1);
 
         v.Draw ();
 
         TestHelpers.AssertDriverContentsAre (expected, output);
+        v.Dispose ();
     }
 
     /// <summary>This test demonstrates how to correctly trigger a corner.  By overlapping the lines in the same cell</summary>
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void View_Draws_Corner_Correct ()
     {
         View v = GetCanvas (out LineCanvas canvas);
@@ -1015,6 +1015,7 @@ public class LineCanvasTests
 ┌─
 │";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     /// <summary>
@@ -1022,12 +1023,12 @@ public class LineCanvasTests
     ///     another.
     /// </summary>
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void View_Draws_Corner_NoOverlap ()
     {
         View v = GetCanvas (out LineCanvas canvas);
         canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Single);
-        canvas.AddLine (new Point (0, 1), 2, Orientation.Vertical, LineStyle.Single);
+        canvas.AddLine (new (0, 1), 2, Orientation.Vertical, LineStyle.Single);
 
         v.Draw ();
 
@@ -1037,12 +1038,13 @@ public class LineCanvasTests
 │";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     [InlineData (LineStyle.Single)]
     [InlineData (LineStyle.Rounded)]
     [Theory]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void View_Draws_Horizontal (LineStyle style)
     {
         View v = GetCanvas (out LineCanvas canvas);
@@ -1054,10 +1056,11 @@ public class LineCanvasTests
             @"    
 ──";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void View_Draws_Horizontal_Double ()
     {
         View v = GetCanvas (out LineCanvas canvas);
@@ -1069,12 +1072,13 @@ public class LineCanvasTests
             @" 
 ══";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     [InlineData (LineStyle.Single)]
     [InlineData (LineStyle.Rounded)]
     [Theory]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void View_Draws_Vertical (LineStyle style)
     {
         View v = GetCanvas (out LineCanvas canvas);
@@ -1087,10 +1091,11 @@ public class LineCanvasTests
 │";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void View_Draws_Vertical_Double ()
     {
         View v = GetCanvas (out LineCanvas canvas);
@@ -1103,22 +1108,23 @@ public class LineCanvasTests
 ║";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void View_Draws_Window_Double ()
     {
         View v = GetCanvas (out LineCanvas canvas);
 
         // outer box
         canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Double);
-        canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Double);
-        canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Double);
-        canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Double);
+        canvas.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Double);
+        canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Double);
+        canvas.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Double);
 
-        canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Double);
-        canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Double);
+        canvas.AddLine (new (5, 0), 5, Orientation.Vertical, LineStyle.Double);
+        canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, LineStyle.Double);
 
         v.Draw ();
 
@@ -1130,10 +1136,11 @@ public class LineCanvasTests
 ║    ║   ║
 ╚════╩═══╝";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     [Theory]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     [InlineData (LineStyle.Single)]
     [InlineData (LineStyle.Rounded)]
     public void View_Draws_Window_DoubleTop_SingleSides (LineStyle thinStyle)
@@ -1142,12 +1149,12 @@ public class LineCanvasTests
 
         // outer box
         canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Double);
-        canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, thinStyle);
-        canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Double);
-        canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, thinStyle);
+        canvas.AddLine (new (9, 0), 5, Orientation.Vertical, thinStyle);
+        canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Double);
+        canvas.AddLine (new (0, 4), -5, Orientation.Vertical, thinStyle);
 
-        canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, thinStyle);
-        canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Double);
+        canvas.AddLine (new (5, 0), 5, Orientation.Vertical, thinStyle);
+        canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, LineStyle.Double);
 
         v.Draw ();
 
@@ -1160,6 +1167,7 @@ public class LineCanvasTests
 ╘════╧═══╛
 ";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     /// <summary>
@@ -1168,7 +1176,7 @@ public class LineCanvasTests
     ///     used.
     /// </summary>
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void View_Draws_Window_Rounded ()
     {
         View v = GetCanvas (out LineCanvas canvas);
@@ -1178,13 +1186,13 @@ public class LineCanvasTests
 
         // LineStyle.Single is ignored because corner overlaps with the above line which is Rounded
         // this results in a rounded corner being used.
-        canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Single);
-        canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Rounded);
-        canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Single);
+        canvas.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Single);
+        canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Rounded);
+        canvas.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Single);
 
         // These lines say rounded but they will result in the T sections which are never rounded.
-        canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Rounded);
-        canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Rounded);
+        canvas.AddLine (new (5, 0), 5, Orientation.Vertical, LineStyle.Rounded);
+        canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, LineStyle.Rounded);
 
         v.Draw ();
 
@@ -1196,24 +1204,25 @@ public class LineCanvasTests
 │    │   │
 ╰────┴───╯";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     [Theory]
-    [AutoInitShutdown]
     [InlineData (LineStyle.Single)]
     [InlineData (LineStyle.Rounded)]
+    [SetupFakeDriver]
     public void View_Draws_Window_SingleTop_DoubleSides (LineStyle thinStyle)
     {
         View v = GetCanvas (out LineCanvas canvas);
 
         // outer box
         canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, thinStyle);
-        canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Double);
-        canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, thinStyle);
-        canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Double);
+        canvas.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Double);
+        canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, thinStyle);
+        canvas.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Double);
 
-        canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Double);
-        canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, thinStyle);
+        canvas.AddLine (new (5, 0), 5, Orientation.Vertical, LineStyle.Double);
+        canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, thinStyle);
 
         v.Draw ();
 
@@ -1227,6 +1236,7 @@ public class LineCanvasTests
 
 ";
         TestHelpers.AssertDriverContentsAre (looksLike, output);
+        v.Dispose ();
     }
 
     [Fact]
@@ -1237,13 +1247,13 @@ public class LineCanvasTests
 
         // Frame
         canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Single);
-        canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Single);
-        canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Single);
-        canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Single);
+        canvas.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Single);
+        canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Single);
+        canvas.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Single);
 
         // Cross
-        canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Single);
-        canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Single);
+        canvas.AddLine (new (5, 0), 5, Orientation.Vertical, LineStyle.Single);
+        canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, LineStyle.Single);
 
         var looksLike =
             @"
@@ -1270,22 +1280,22 @@ public class LineCanvasTests
 
         // ╔╡╞═════╗
         // Add a short horiz line for ╔╡
-        lc.AddLine (new Point (x, y), 2, Orientation.Horizontal, LineStyle.Double);
+        lc.AddLine (new (x, y), 2, Orientation.Horizontal, LineStyle.Double);
 
         //LHS line down
-        lc.AddLine (new Point (x, y), height, Orientation.Vertical, LineStyle.Double);
+        lc.AddLine (new (x, y), height, Orientation.Vertical, LineStyle.Double);
 
         //Vertical line before Title, results in a ╡
-        lc.AddLine (new Point (x + 1, y), 0, Orientation.Vertical, LineStyle.Single);
+        lc.AddLine (new (x + 1, y), 0, Orientation.Vertical, LineStyle.Single);
 
         //Vertical line after Title, results in a ╞
-        lc.AddLine (new Point (x + 2, y), 0, Orientation.Vertical, LineStyle.Single);
+        lc.AddLine (new (x + 2, y), 0, Orientation.Vertical, LineStyle.Single);
 
         // remainder of top line
-        lc.AddLine (new Point (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double);
+        lc.AddLine (new (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double);
 
         //RHS line down
-        lc.AddLine (new Point (x + width, y), height, Orientation.Vertical, LineStyle.Double);
+        lc.AddLine (new (x + width, y), height, Orientation.Vertical, LineStyle.Double);
 
         var looksLike = @"
 ╔╡╞══╗
@@ -1304,12 +1314,9 @@ public class LineCanvasTests
     /// <returns></returns>
     private View GetCanvas (out LineCanvas canvas, int offsetX = 0, int offsetY = 0)
     {
-        var v = new View { Width = 10, Height = 5, Viewport = new Rectangle (0, 0, 10, 5) };
-        var top = new Toplevel ();
-        top.Add (v);
-        Application.Begin (top);
+        var v = new View { Width = 10, Height = 5, Viewport = new (0, 0, 10, 5) };
 
-        LineCanvas canvasCopy = canvas = new LineCanvas ();
+        LineCanvas canvasCopy = canvas = new ();
 
         v.DrawContentComplete += (s, e) =>
                                  {

+ 16 - 16
UnitTests/Drawing/RulerTests.cs

@@ -1,9 +1,5 @@
 using Xunit.Abstractions;
 
-//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
-
-// Alias Console to MockConsole so we don't accidentally use Console
-
 namespace Terminal.Gui.DrawingTests;
 
 public class RulerTests
@@ -52,7 +48,7 @@ public class RulerTests
         top.Add (f);
         Application.Begin (top);
         ((FakeDriver)Application.Driver).SetBufferSize (len + 5, 5);
-        Assert.Equal (new Rectangle (0, 0, len + 5, 5), f.Frame);
+        Assert.Equal (new (0, 0, len + 5, 5), f.Frame);
 
         var r = new Ruler ();
         Assert.Equal (Orientation.Horizontal, r.Orientation);
@@ -72,7 +68,7 @@ public class RulerTests
 
         // Postive offset
         Application.Refresh ();
-        r.Draw (new Point (1, 1));
+        r.Draw (new (1, 1));
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -86,7 +82,7 @@ public class RulerTests
 
         // Negative offset
         Application.Refresh ();
-        r.Draw (new Point (-1, 1));
+        r.Draw (new (-1, 1));
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -100,7 +96,7 @@ public class RulerTests
 
         // Clip
         Application.Refresh ();
-        r.Draw (new Point (10, 1));
+        r.Draw (new (10, 1));
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -111,6 +107,7 @@ public class RulerTests
 └──────────────────┘",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -125,7 +122,7 @@ public class RulerTests
         top.Add (f);
         Application.Begin (top);
         ((FakeDriver)Application.Driver).SetBufferSize (len + 5, 5);
-        Assert.Equal (new Rectangle (0, 0, len + 5, 5), f.Frame);
+        Assert.Equal (new (0, 0, len + 5, 5), f.Frame);
 
         var r = new Ruler ();
         Assert.Equal (Orientation.Horizontal, r.Orientation);
@@ -145,7 +142,7 @@ public class RulerTests
 
         Application.Refresh ();
         r.Length = len;
-        r.Draw (new Point (1, 0), 1);
+        r.Draw (new (1, 0), 1);
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -156,6 +153,7 @@ public class RulerTests
 └──────────────────┘",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -171,7 +169,7 @@ public class RulerTests
         top.Add (f);
         Application.Begin (top);
         ((FakeDriver)Application.Driver).SetBufferSize (5, len + 5);
-        Assert.Equal (new Rectangle (0, 0, 5, len + 5), f.Frame);
+        Assert.Equal (new (0, 0, 5, len + 5), f.Frame);
 
         var r = new Ruler ();
         r.Orientation = Orientation.Vertical;
@@ -205,7 +203,7 @@ public class RulerTests
 
         // Postive offset
         Application.Refresh ();
-        r.Draw (new Point (1, 1));
+        r.Draw (new (1, 1));
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -234,7 +232,7 @@ public class RulerTests
 
         // Negative offset
         Application.Refresh ();
-        r.Draw (new Point (1, -1));
+        r.Draw (new (1, -1));
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -263,7 +261,7 @@ public class RulerTests
 
         // Clip
         Application.Refresh ();
-        r.Draw (new Point (1, 10));
+        r.Draw (new (1, 10));
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -289,6 +287,7 @@ public class RulerTests
 └9──┘",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -304,7 +303,7 @@ public class RulerTests
         top.Add (f);
         Application.Begin (top);
         ((FakeDriver)Application.Driver).SetBufferSize (5, len + 5);
-        Assert.Equal (new Rectangle (0, 0, 5, len + 5), f.Frame);
+        Assert.Equal (new (0, 0, 5, len + 5), f.Frame);
 
         var r = new Ruler ();
         r.Orientation = Orientation.Vertical;
@@ -338,7 +337,7 @@ public class RulerTests
 
         Application.Refresh ();
         r.Length = len;
-        r.Draw (new Point (0, 1), 1);
+        r.Draw (new (0, 1), 1);
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
@@ -364,6 +363,7 @@ public class RulerTests
 └───┘",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]

+ 10 - 16
UnitTests/Drawing/ThicknessTests.cs

@@ -1,17 +1,10 @@
 using System.Text;
 using Xunit.Abstractions;
 
-//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
-
-// Alias Console to MockConsole so we don't accidentally use Console
-
 namespace Terminal.Gui.DrawingTests;
 
-public class ThicknessTests
+public class ThicknessTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public ThicknessTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     public void Constructor_Defaults ()
     {
@@ -73,7 +66,7 @@ public class ThicknessTests
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
        Test (Left=0,Top=0,Right=0,Bottom=0)",
-                                                      _output
+                                                      output
                                                      );
 
         t = new Thickness (1, 1, 1, 1);
@@ -104,7 +97,7 @@ public class ThicknessTests
      T                                      T
      T                                      T
      TTTest (Left=1,Top=1,Right=1,Bottom=1)TT",
-                                                      _output
+                                                      output
                                                      );
 
         t = new Thickness (1, 2, 3, 4);
@@ -135,7 +128,7 @@ public class ThicknessTests
      TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
      TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
      TTTest (Left=1,Top=2,Right=3,Bottom=4)TT",
-                                                      _output
+                                                      output
                                                      );
 
         t = new Thickness (-1, 1, 1, 1);
@@ -166,7 +159,7 @@ public class ThicknessTests
                                             T
                                             T
      TTest (Left=-1,Top=1,Right=1,Bottom=1)TT",
-                                                      _output
+                                                      output
                                                      );
     }
 
@@ -211,7 +204,7 @@ public class ThicknessTests
 │                                           │
 │                                           │
 └───────────────────────────────────────────┘",
-                                             _output
+                                             output
                                             );
 
         t = new Thickness (1, 1, 1, 1);
@@ -243,7 +236,7 @@ public class ThicknessTests
 │                                           │
 │                                           │
 └───────────────────────────────────────────┘",
-                                             _output
+                                             output
                                             );
 
         t = new Thickness (1, 2, 3, 4);
@@ -275,7 +268,7 @@ public class ThicknessTests
 │                                           │
 │                                           │
 └───────────────────────────────────────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         t = new Thickness (-1, 1, 1, 1);
@@ -307,8 +300,9 @@ public class ThicknessTests
 │                                           2
 │                                           3
 └────|123456789|123456789|123456789|123456789",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]

+ 30 - 21
UnitTests/FileServices/FileDialogTests.cs

@@ -1,19 +1,15 @@
-using System.Globalization;
 using System.IO.Abstractions.TestingHelpers;
 using System.Runtime.InteropServices;
 using Xunit.Abstractions;
 
 namespace Terminal.Gui.FileServicesTests;
 
-public class FileDialogTests
+public class FileDialogTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper output;
-    public FileDialogTests (ITestOutputHelper output) { this.output = output; }
-
     [Theory]
-    [AutoInitShutdown]
     [InlineData (true)]
     [InlineData (false)]
+    [AutoInitShutdown]
     public void CancelSelection (bool cancel)
     {
         FileDialog dlg = GetInitializedFileDialog ();
@@ -28,6 +24,7 @@ public class FileDialogTests
         Send ('\n', ConsoleKey.Enter);
 
         Assert.Equal (cancel, dlg.Canceled);
+        dlg.Dispose ();
     }
 
     [Fact]
@@ -57,6 +54,7 @@ public class FileDialogTests
         Send ('\n', ConsoleKey.Enter);
         Assert.False (dlg.Canceled);
         Assert.Equal ("bob.csv", Path.GetFileName (dlg.Path));
+        dlg.Dispose ();
     }
 
     [Fact]
@@ -90,6 +88,7 @@ public class FileDialogTests
         Send ('\n', ConsoleKey.Enter);
         Assert.False (dlg.Canceled);
         Assert.EndsWith ("xx" + Path.DirectorySeparatorChar, dlg.Path);
+        dlg.Dispose ();
     }
 
     [Fact]
@@ -128,6 +127,7 @@ public class FileDialogTests
 
         // Dialog has not yet been confirmed with a choice
         Assert.False (dlg.Canceled);
+        dlg.Dispose ();
     }
 
     [Fact]
@@ -166,6 +166,7 @@ public class FileDialogTests
 
         Assert.True (dlg.Canceled);
         Assert.False (selected);
+        dlg.Dispose ();
     }
 
     [Theory]
@@ -220,6 +221,7 @@ public class FileDialogTests
                              AssertIsTheSubfolder (eventMultiSelected.Single ());
                          }
                         );
+        dlg.Dispose ();
     }
 
     [Theory]
@@ -273,6 +275,7 @@ public class FileDialogTests
                              AssertIsTheSubfolder (eventMultiSelected.Single ());
                          }
                         );
+        dlg.Dispose ();
     }
 
     [Fact]
@@ -301,6 +304,7 @@ public class FileDialogTests
         Assert.True (dlg.Canceled);
         Assert.Empty (dlg.MultiSelected);
         Assert.Null (eventMultiSelected);
+        dlg.Dispose ();
     }
 
     [Fact]
@@ -312,6 +316,7 @@ public class FileDialogTests
         View tf = dlg.Subviews.FirstOrDefault (t => t.HasFocus);
         Assert.NotNull (tf);
         Assert.IsType<TextField> (tf);
+        dlg.Dispose ();
     }
 
     [Theory]
@@ -341,6 +346,7 @@ public class FileDialogTests
         Assert.False (dlg.Canceled);
 
         AssertIsTheSubfolder (dlg.Path);
+        dlg.Dispose ();
     }
 
     [Theory]
@@ -368,6 +374,7 @@ public class FileDialogTests
         Send ('\n', ConsoleKey.Enter);
         Assert.False (dlg.Canceled);
         AssertIsTheSubfolder (dlg.Path);
+        dlg.Dispose ();
     }
 
     [Theory]
@@ -413,7 +420,7 @@ public class FileDialogTests
         FileDialog fd = GetLinuxDialog ();
         fd.Title = string.Empty;
 
-        fd.Style.Culture = new CultureInfo ("en-US");
+        fd.Style.Culture = new ("en-US");
 
         fd.Draw ();
 
@@ -456,6 +463,7 @@ public class FileDialogTests
 └─────────────────────────────────────────────────────────────────────────┘
 ";
         TestHelpers.AssertDriverContentsAre (expected, output, ignoreLeadingWhitespace: true);
+        fd.Dispose ();
     }
 
     [Fact]
@@ -470,7 +478,7 @@ public class FileDialogTests
         FileDialog fd = GetWindowsDialog ();
         fd.Title = string.Empty;
 
-        fd.Style.Culture = new CultureInfo ("en-US");
+        fd.Style.Culture = new ("en-US");
 
         fd.Draw ();
 
@@ -513,6 +521,7 @@ public class FileDialogTests
 └─────────────────────────────────────────────────────────────────────────┘
 ";
         TestHelpers.AssertDriverContentsAre (expected, output, ignoreLeadingWhitespace: true);
+        fd.Dispose ();
     }
 
     private void AssertIsTheRootDirectory (string path)
@@ -572,21 +581,21 @@ public class FileDialogTests
     {
         // Arrange
         var fileSystem = new MockFileSystem (new Dictionary<string, MockFileData> (), "/");
-        fileSystem.MockTime (() => new DateTime (2010, 01, 01, 11, 12, 43));
+        fileSystem.MockTime (() => new (2010, 01, 01, 11, 12, 43));
 
         fileSystem.AddFile (
                             @"/myfile.txt",
-                            new MockFileData ("Testing is meh.") { LastWriteTime = new DateTime (2001, 01, 01, 11, 12, 11) }
+                            new ("Testing is meh.") { LastWriteTime = new DateTime (2001, 01, 01, 11, 12, 11) }
                            );
 
         fileSystem.AddFile (
                             @"/demo/jQuery.js",
-                            new MockFileData ("some js") { LastWriteTime = new DateTime (2001, 01, 01, 11, 44, 42) }
+                            new ("some js") { LastWriteTime = new DateTime (2001, 01, 01, 11, 44, 42) }
                            );
 
         fileSystem.AddFile (
                             @"/demo/image.gif",
-                            new MockFileData (new byte [] { 0x12, 0x34, 0x56, 0xd2 })
+                            new (new byte [] { 0x12, 0x34, 0x56, 0xd2 })
                             {
                                 LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10)
                             }
@@ -594,11 +603,11 @@ public class FileDialogTests
 
         var m = (MockDirectoryInfo)fileSystem.DirectoryInfo.New (@"/demo/subfolder");
         m.Create ();
-        m.LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10);
+        m.LastWriteTime = new (2002, 01, 01, 22, 42, 10);
 
         fileSystem.AddFile (
                             @"/demo/subfolder/image2.gif",
-                            new MockFileData (new byte [] { 0x12, 0x34, 0x56, 0xd2 })
+                            new (new byte [] { 0x12, 0x34, 0x56, 0xd2 })
                             {
                                 LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10)
                             }
@@ -615,26 +624,26 @@ public class FileDialogTests
     {
         // Arrange
         var fileSystem = new MockFileSystem (new Dictionary<string, MockFileData> (), @"c:\");
-        fileSystem.MockTime (() => new DateTime (2010, 01, 01, 11, 12, 43));
+        fileSystem.MockTime (() => new (2010, 01, 01, 11, 12, 43));
 
         fileSystem.AddFile (
                             @"c:\myfile.txt",
-                            new MockFileData ("Testing is meh.") { LastWriteTime = new DateTime (2001, 01, 01, 11, 12, 11) }
+                            new ("Testing is meh.") { LastWriteTime = new DateTime (2001, 01, 01, 11, 12, 11) }
                            );
 
         fileSystem.AddFile (
                             @"c:\demo\jQuery.js",
-                            new MockFileData ("some js") { LastWriteTime = new DateTime (2001, 01, 01, 11, 44, 42) }
+                            new ("some js") { LastWriteTime = new DateTime (2001, 01, 01, 11, 44, 42) }
                            );
 
         fileSystem.AddFile (
                             @"c:\demo\mybinary.exe",
-                            new MockFileData ("some js") { LastWriteTime = new DateTime (2001, 01, 01, 11, 44, 42) }
+                            new ("some js") { LastWriteTime = new DateTime (2001, 01, 01, 11, 44, 42) }
                            );
 
         fileSystem.AddFile (
                             @"c:\demo\image.gif",
-                            new MockFileData (new byte [] { 0x12, 0x34, 0x56, 0xd2 })
+                            new (new byte [] { 0x12, 0x34, 0x56, 0xd2 })
                             {
                                 LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10)
                             }
@@ -642,11 +651,11 @@ public class FileDialogTests
 
         var m = (MockDirectoryInfo)fileSystem.DirectoryInfo.New (@"c:\demo\subfolder");
         m.Create ();
-        m.LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10);
+        m.LastWriteTime = new (2002, 01, 01, 22, 42, 10);
 
         fileSystem.AddFile (
                             @"c:\demo\subfolder\image2.gif",
-                            new MockFileData (new byte [] { 0x12, 0x34, 0x56, 0xd2 })
+                            new (new byte [] { 0x12, 0x34, 0x56, 0xd2 })
                             {
                                 LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10)
                             }

+ 72 - 74
UnitTests/Input/EscSeqUtilsTests.cs

@@ -1,7 +1,4 @@
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-namespace Terminal.Gui.InputTests;
+namespace Terminal.Gui.InputTests;
 
 public class EscSeqUtilsTests
 {
@@ -53,7 +50,7 @@ public class EscSeqUtilsTests
         Assert.Null (_values);
         Assert.Null (_terminating);
         Assert.False (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { 0 }, _mouseFlags);
+        Assert.Equal (new() { 0 }, _mouseFlags);
         Assert.Equal (Point.Empty, _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
@@ -61,7 +58,7 @@ public class EscSeqUtilsTests
 
         ClearAll ();
         _cki = new ConsoleKeyInfo [] { new ('\u001b', 0, false, false, false), new ('\u0012', 0, false, false, false) };
-        expectedCki = new ConsoleKeyInfo ('\u0012', ConsoleKey.R, false, true, true);
+        expectedCki = new ('\u0012', ConsoleKey.R, false, true, true);
 
         EscSeqUtils.DecodeEscSeq (
                                   _escSeqReqProc,
@@ -88,7 +85,7 @@ public class EscSeqUtilsTests
         Assert.Null (_values);
         Assert.Equal ("\u0012", _terminating);
         Assert.False (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { 0 }, _mouseFlags);
+        Assert.Equal (new() { 0 }, _mouseFlags);
         Assert.Equal (Point.Empty, _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
@@ -96,7 +93,7 @@ public class EscSeqUtilsTests
 
         ClearAll ();
         _cki = new ConsoleKeyInfo [] { new ('\u001b', 0, false, false, false), new ('r', 0, false, false, false) };
-        expectedCki = new ConsoleKeyInfo ('R', ConsoleKey.R, false, true, false);
+        expectedCki = new ('R', ConsoleKey.R, false, true, false);
 
         EscSeqUtils.DecodeEscSeq (
                                   _escSeqReqProc,
@@ -123,7 +120,7 @@ public class EscSeqUtilsTests
         Assert.Null (_values);
         Assert.Equal ("r", _terminating);
         Assert.False (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { 0 }, _mouseFlags);
+        Assert.Equal (new() { 0 }, _mouseFlags);
         Assert.Equal (Point.Empty, _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
@@ -136,7 +133,7 @@ public class EscSeqUtilsTests
         {
             new ('\u001b', 0, false, false, false), new ('O', 0, false, false, false), new ('R', 0, false, false, false)
         };
-        expectedCki = new ConsoleKeyInfo ('\0', ConsoleKey.F3, false, false, false);
+        expectedCki = new ('\0', ConsoleKey.F3, false, false, false);
 
         EscSeqUtils.DecodeEscSeq (
                                   _escSeqReqProc,
@@ -164,7 +161,7 @@ public class EscSeqUtilsTests
         Assert.Null (_values [0]);
         Assert.Equal ("R", _terminating);
         Assert.False (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { 0 }, _mouseFlags);
+        Assert.Equal (new() { 0 }, _mouseFlags);
         Assert.Equal (Point.Empty, _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
@@ -182,7 +179,7 @@ public class EscSeqUtilsTests
             new ('2', 0, false, false, false),
             new ('R', 0, false, false, false)
         };
-        expectedCki = new ConsoleKeyInfo ('\0', ConsoleKey.F3, true, false, false);
+        expectedCki = new ('\0', ConsoleKey.F3, true, false, false);
 
         EscSeqUtils.DecodeEscSeq (
                                   _escSeqReqProc,
@@ -211,7 +208,7 @@ public class EscSeqUtilsTests
         Assert.Equal ("2", _values [^1]);
         Assert.Equal ("R", _terminating);
         Assert.False (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { 0 }, _mouseFlags);
+        Assert.Equal (new() { 0 }, _mouseFlags);
         Assert.Equal (Point.Empty, _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
@@ -228,7 +225,7 @@ public class EscSeqUtilsTests
             new ('3', 0, false, false, false),
             new ('R', 0, false, false, false)
         };
-        expectedCki = new ConsoleKeyInfo ('\0', ConsoleKey.F3, false, true, false);
+        expectedCki = new ('\0', ConsoleKey.F3, false, true, false);
 
         EscSeqUtils.DecodeEscSeq (
                                   _escSeqReqProc,
@@ -257,7 +254,7 @@ public class EscSeqUtilsTests
         Assert.Equal ("3", _values [^1]);
         Assert.Equal ("R", _terminating);
         Assert.False (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { 0 }, _mouseFlags);
+        Assert.Equal (new() { 0 }, _mouseFlags);
         Assert.Equal (Point.Empty, _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
@@ -274,7 +271,7 @@ public class EscSeqUtilsTests
             new ('4', 0, false, false, false),
             new ('R', 0, false, false, false)
         };
-        expectedCki = new ConsoleKeyInfo ('\0', ConsoleKey.F3, true, true, false);
+        expectedCki = new ('\0', ConsoleKey.F3, true, true, false);
 
         EscSeqUtils.DecodeEscSeq (
                                   _escSeqReqProc,
@@ -303,7 +300,7 @@ public class EscSeqUtilsTests
         Assert.Equal ("4", _values [^1]);
         Assert.Equal ("R", _terminating);
         Assert.False (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { 0 }, _mouseFlags);
+        Assert.Equal (new() { 0 }, _mouseFlags);
         Assert.Equal (Point.Empty, _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
@@ -320,7 +317,7 @@ public class EscSeqUtilsTests
             new ('5', 0, false, false, false),
             new ('R', 0, false, false, false)
         };
-        expectedCki = new ConsoleKeyInfo ('\0', ConsoleKey.F3, false, false, true);
+        expectedCki = new ('\0', ConsoleKey.F3, false, false, true);
 
         EscSeqUtils.DecodeEscSeq (
                                   _escSeqReqProc,
@@ -349,7 +346,7 @@ public class EscSeqUtilsTests
         Assert.Equal ("5", _values [^1]);
         Assert.Equal ("R", _terminating);
         Assert.False (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { 0 }, _mouseFlags);
+        Assert.Equal (new() { 0 }, _mouseFlags);
         Assert.Equal (Point.Empty, _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
@@ -366,7 +363,7 @@ public class EscSeqUtilsTests
             new ('6', 0, false, false, false),
             new ('R', 0, false, false, false)
         };
-        expectedCki = new ConsoleKeyInfo ('\0', ConsoleKey.F3, true, false, true);
+        expectedCki = new ('\0', ConsoleKey.F3, true, false, true);
 
         EscSeqUtils.DecodeEscSeq (
                                   _escSeqReqProc,
@@ -395,7 +392,7 @@ public class EscSeqUtilsTests
         Assert.Equal ("6", _values [^1]);
         Assert.Equal ("R", _terminating);
         Assert.False (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { 0 }, _mouseFlags);
+        Assert.Equal (new() { 0 }, _mouseFlags);
         Assert.Equal (Point.Empty, _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
@@ -412,7 +409,7 @@ public class EscSeqUtilsTests
             new ('7', 0, false, false, false),
             new ('R', 0, false, false, false)
         };
-        expectedCki = new ConsoleKeyInfo ('\0', ConsoleKey.F3, false, true, true);
+        expectedCki = new ('\0', ConsoleKey.F3, false, true, true);
 
         EscSeqUtils.DecodeEscSeq (
                                   _escSeqReqProc,
@@ -441,7 +438,7 @@ public class EscSeqUtilsTests
         Assert.Equal ("7", _values [^1]);
         Assert.Equal ("R", _terminating);
         Assert.False (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { 0 }, _mouseFlags);
+        Assert.Equal (new() { 0 }, _mouseFlags);
         Assert.Equal (Point.Empty, _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
@@ -458,7 +455,7 @@ public class EscSeqUtilsTests
             new ('8', 0, false, false, false),
             new ('R', 0, false, false, false)
         };
-        expectedCki = new ConsoleKeyInfo ('\0', ConsoleKey.F3, true, true, true);
+        expectedCki = new ('\0', ConsoleKey.F3, true, true, true);
 
         EscSeqUtils.DecodeEscSeq (
                                   _escSeqReqProc,
@@ -487,7 +484,7 @@ public class EscSeqUtilsTests
         Assert.Equal ("8", _values [^1]);
         Assert.Equal ("R", _terminating);
         Assert.False (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { 0 }, _mouseFlags);
+        Assert.Equal (new() { 0 }, _mouseFlags);
         Assert.Equal (Point.Empty, _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
@@ -537,8 +534,8 @@ public class EscSeqUtilsTests
         Assert.Equal ("3", _values [^1]);
         Assert.Equal ("M", _terminating);
         Assert.True (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { MouseFlags.Button1Pressed }, _mouseFlags);
-        Assert.Equal (new Point (1, 2), _pos);
+        Assert.Equal (new() { MouseFlags.Button1Pressed }, _mouseFlags);
+        Assert.Equal (new (1, 2), _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
         Assert.Equal (Point.Empty, _arg2);
@@ -590,10 +587,10 @@ public class EscSeqUtilsTests
         Assert.Equal (2, _mouseFlags.Count);
 
         Assert.Equal (
-                      new List<MouseFlags> { MouseFlags.Button1Released, MouseFlags.Button1Clicked },
+                      new() { MouseFlags.Button1Released, MouseFlags.Button1Clicked },
                       _mouseFlags
                      );
-        Assert.Equal (new Point (1, 2), _pos);
+        Assert.Equal (new (1, 2), _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
         Assert.Equal (Point.Empty, _arg2);
@@ -642,8 +639,8 @@ public class EscSeqUtilsTests
         Assert.Equal ("3", _values [^1]);
         Assert.Equal ("M", _terminating);
         Assert.True (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { MouseFlags.Button1DoubleClicked }, _mouseFlags);
-        Assert.Equal (new Point (1, 2), _pos);
+        Assert.Equal (new() { MouseFlags.Button1DoubleClicked }, _mouseFlags);
+        Assert.Equal (new (1, 2), _pos);
         Assert.False (_isReq);
 
         ClearAll ();
@@ -690,8 +687,8 @@ public class EscSeqUtilsTests
         Assert.Equal ("3", _values [^1]);
         Assert.Equal ("M", _terminating);
         Assert.True (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { MouseFlags.Button1TripleClicked }, _mouseFlags);
-        Assert.Equal (new Point (1, 2), _pos);
+        Assert.Equal (new() { MouseFlags.Button1TripleClicked }, _mouseFlags);
+        Assert.Equal (new (1, 2), _pos);
         Assert.False (_isReq);
 
         var view = new View { Width = Dim.Fill (), Height = Dim.Fill (), WantContinuousButtonPressed = true };
@@ -699,7 +696,7 @@ public class EscSeqUtilsTests
         top.Add (view);
         Application.Begin (top);
 
-        Application.OnMouseEvent (new MouseEvent { Position = new (0, 0), Flags = 0 });
+        Application.OnMouseEvent (new() { Position = new (0, 0), Flags = 0 });
 
         ClearAll ();
 
@@ -745,8 +742,8 @@ public class EscSeqUtilsTests
         Assert.Equal ("3", _values [^1]);
         Assert.Equal ("M", _terminating);
         Assert.True (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { MouseFlags.Button1Pressed }, _mouseFlags);
-        Assert.Equal (new Point (1, 2), _pos);
+        Assert.Equal (new() { MouseFlags.Button1Pressed }, _mouseFlags);
+        Assert.Equal (new (1, 2), _pos);
         Assert.False (_isReq);
 
         Application.Iteration += (s, a) =>
@@ -756,18 +753,19 @@ public class EscSeqUtilsTests
                                          // set Application.WantContinuousButtonPressedView to null
                                          view.WantContinuousButtonPressed = false;
 
-                                         Application.OnMouseEvent (new MouseEvent { Position = new (0, 0), Flags = 0 });
+                                         Application.OnMouseEvent (new() { Position = new (0, 0), Flags = 0 });
 
                                          Application.RequestStop ();
                                      }
                                  };
 
         Application.Run (top);
+        top.Dispose ();
 
         Assert.Null (Application.WantContinuousButtonPressedView);
 
         Assert.Equal (MouseFlags.Button1Pressed, _arg1);
-        Assert.Equal (new Point (1, 2), _arg2);
+        Assert.Equal (new (1, 2), _arg2);
 
         ClearAll ();
 
@@ -813,8 +811,8 @@ public class EscSeqUtilsTests
         Assert.Equal ("3", _values [^1]);
         Assert.Equal ("m", _terminating);
         Assert.True (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { MouseFlags.Button1Released }, _mouseFlags);
-        Assert.Equal (new Point (1, 2), _pos);
+        Assert.Equal (new() { MouseFlags.Button1Released }, _mouseFlags);
+        Assert.Equal (new (1, 2), _pos);
         Assert.False (_isReq);
         Assert.Equal (0, (int)_arg1);
         Assert.Equal (Point.Empty, _arg2);
@@ -822,7 +820,7 @@ public class EscSeqUtilsTests
         ClearAll ();
 
         Assert.Null (_escSeqReqProc);
-        _escSeqReqProc = new EscSeqRequests ();
+        _escSeqReqProc = new ();
         _escSeqReqProc.Add ("t");
 
         _cki = new ConsoleKeyInfo []
@@ -870,7 +868,7 @@ public class EscSeqUtilsTests
         Assert.Equal ("20", _values [^1]);
         Assert.Equal ("t", _terminating);
         Assert.False (_isKeyMouse);
-        Assert.Equal (new List<MouseFlags> { 0 }, _mouseFlags);
+        Assert.Equal (new() { 0 }, _mouseFlags);
         Assert.Equal (Point.Empty, _pos);
         Assert.True (_isReq);
         Assert.Equal (0, (int)_arg1);
@@ -921,48 +919,48 @@ public class EscSeqUtilsTests
         var expectedCki = new ConsoleKeyInfo ('r', 0, false, false, false);
         Assert.Equal (expectedCki, EscSeqUtils.MapConsoleKeyInfo (cki));
 
-        cki = new ConsoleKeyInfo ('r', 0, true, false, false);
-        expectedCki = new ConsoleKeyInfo ('r', 0, true, false, false);
+        cki = new ('r', 0, true, false, false);
+        expectedCki = new ('r', 0, true, false, false);
         Assert.Equal (expectedCki, EscSeqUtils.MapConsoleKeyInfo (cki));
 
-        cki = new ConsoleKeyInfo ('r', 0, false, true, false);
-        expectedCki = new ConsoleKeyInfo ('r', 0, false, true, false);
+        cki = new ('r', 0, false, true, false);
+        expectedCki = new ('r', 0, false, true, false);
         Assert.Equal (expectedCki, EscSeqUtils.MapConsoleKeyInfo (cki));
 
-        cki = new ConsoleKeyInfo ('r', 0, false, false, true);
-        expectedCki = new ConsoleKeyInfo ('r', 0, false, false, true);
+        cki = new ('r', 0, false, false, true);
+        expectedCki = new ('r', 0, false, false, true);
         Assert.Equal (expectedCki, EscSeqUtils.MapConsoleKeyInfo (cki));
 
-        cki = new ConsoleKeyInfo ('r', 0, true, true, false);
-        expectedCki = new ConsoleKeyInfo ('r', 0, true, true, false);
+        cki = new ('r', 0, true, true, false);
+        expectedCki = new ('r', 0, true, true, false);
         Assert.Equal (expectedCki, EscSeqUtils.MapConsoleKeyInfo (cki));
 
-        cki = new ConsoleKeyInfo ('r', 0, false, true, true);
-        expectedCki = new ConsoleKeyInfo ('r', 0, false, true, true);
+        cki = new ('r', 0, false, true, true);
+        expectedCki = new ('r', 0, false, true, true);
         Assert.Equal (expectedCki, EscSeqUtils.MapConsoleKeyInfo (cki));
 
-        cki = new ConsoleKeyInfo ('r', 0, true, true, true);
-        expectedCki = new ConsoleKeyInfo ('r', 0, true, true, true);
+        cki = new ('r', 0, true, true, true);
+        expectedCki = new ('r', 0, true, true, true);
         Assert.Equal (expectedCki, EscSeqUtils.MapConsoleKeyInfo (cki));
 
-        cki = new ConsoleKeyInfo ('\u0012', 0, false, false, false);
-        expectedCki = new ConsoleKeyInfo ('R', ConsoleKey.R, false, false, true);
+        cki = new ('\u0012', 0, false, false, false);
+        expectedCki = new ('R', ConsoleKey.R, false, false, true);
         Assert.Equal (expectedCki, EscSeqUtils.MapConsoleKeyInfo (cki));
 
-        cki = new ConsoleKeyInfo ('\0', (ConsoleKey)64, false, false, true);
-        expectedCki = new ConsoleKeyInfo (' ', ConsoleKey.Spacebar, false, false, true);
+        cki = new ('\0', (ConsoleKey)64, false, false, true);
+        expectedCki = new (' ', ConsoleKey.Spacebar, false, false, true);
         Assert.Equal (expectedCki, EscSeqUtils.MapConsoleKeyInfo (cki));
 
-        cki = new ConsoleKeyInfo ('\r', 0, false, false, false);
-        expectedCki = new ConsoleKeyInfo ('\r', ConsoleKey.Enter, false, false, false);
+        cki = new ('\r', 0, false, false, false);
+        expectedCki = new ('\r', ConsoleKey.Enter, false, false, false);
         Assert.Equal (expectedCki, EscSeqUtils.MapConsoleKeyInfo (cki));
 
-        cki = new ConsoleKeyInfo ('\u007f', 0, false, false, false);
-        expectedCki = new ConsoleKeyInfo ('\u007f', ConsoleKey.Backspace, false, false, false);
+        cki = new ('\u007f', 0, false, false, false);
+        expectedCki = new ('\u007f', ConsoleKey.Backspace, false, false, false);
         Assert.Equal (expectedCki, EscSeqUtils.MapConsoleKeyInfo (cki));
 
-        cki = new ConsoleKeyInfo ('R', 0, false, false, false);
-        expectedCki = new ConsoleKeyInfo ('R', 0, false, false, false);
+        cki = new ('R', 0, false, false, false);
+        expectedCki = new ('R', 0, false, false, false);
         Assert.Equal (expectedCki, EscSeqUtils.MapConsoleKeyInfo (cki));
     }
 
@@ -1062,8 +1060,8 @@ public class EscSeqUtilsTests
             new ('M', 0, false, false, false)
         };
         EscSeqUtils.GetMouse (cki, out List<MouseFlags> mouseFlags, out Point pos, ProcessContinuousButtonPressed);
-        Assert.Equal (new List<MouseFlags> { MouseFlags.Button1Pressed }, mouseFlags);
-        Assert.Equal (new Point (1, 2), pos);
+        Assert.Equal (new() { MouseFlags.Button1Pressed }, mouseFlags);
+        Assert.Equal (new (1, 2), pos);
 
         cki = new ConsoleKeyInfo []
         {
@@ -1081,10 +1079,10 @@ public class EscSeqUtilsTests
         Assert.Equal (2, mouseFlags.Count);
 
         Assert.Equal (
-                      new List<MouseFlags> { MouseFlags.Button1Released, MouseFlags.Button1Clicked },
+                      new() { MouseFlags.Button1Released, MouseFlags.Button1Clicked },
                       mouseFlags
                      );
-        Assert.Equal (new Point (1, 2), pos);
+        Assert.Equal (new (1, 2), pos);
 
         cki = new ConsoleKeyInfo []
         {
@@ -1099,8 +1097,8 @@ public class EscSeqUtilsTests
             new ('M', 0, false, false, false)
         };
         EscSeqUtils.GetMouse (cki, out mouseFlags, out pos, ProcessContinuousButtonPressed);
-        Assert.Equal (new List<MouseFlags> { MouseFlags.Button1DoubleClicked }, mouseFlags);
-        Assert.Equal (new Point (1, 2), pos);
+        Assert.Equal (new() { MouseFlags.Button1DoubleClicked }, mouseFlags);
+        Assert.Equal (new (1, 2), pos);
 
         cki = new ConsoleKeyInfo []
         {
@@ -1115,8 +1113,8 @@ public class EscSeqUtilsTests
             new ('M', 0, false, false, false)
         };
         EscSeqUtils.GetMouse (cki, out mouseFlags, out pos, ProcessContinuousButtonPressed);
-        Assert.Equal (new List<MouseFlags> { MouseFlags.Button1TripleClicked }, mouseFlags);
-        Assert.Equal (new Point (1, 2), pos);
+        Assert.Equal (new() { MouseFlags.Button1TripleClicked }, mouseFlags);
+        Assert.Equal (new (1, 2), pos);
 
         cki = new ConsoleKeyInfo []
         {
@@ -1131,8 +1129,8 @@ public class EscSeqUtilsTests
             new ('m', 0, false, false, false)
         };
         EscSeqUtils.GetMouse (cki, out mouseFlags, out pos, ProcessContinuousButtonPressed);
-        Assert.Equal (new List<MouseFlags> { MouseFlags.Button1Released }, mouseFlags);
-        Assert.Equal (new Point (1, 2), pos);
+        Assert.Equal (new() { MouseFlags.Button1Released }, mouseFlags);
+        Assert.Equal (new (1, 2), pos);
     }
 
     [Fact]

+ 1 - 1
UnitTests/TestHelpers.cs

@@ -77,7 +77,7 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute
         if (AutoInit)
         {
             // TODO: This Dispose call is here until all unit tests that don't correctly dispose Toplevel's they create are fixed.
-            Application.Top?.Dispose ();
+            //Application.Top?.Dispose ();
             Application.Shutdown ();
 #if DEBUG_IDISPOSABLE
             if (Responder.Instances.Count == 0)

+ 38 - 40
UnitTests/Text/AutocompleteTests.cs

@@ -3,11 +3,8 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.TextTests;
 
-public class AutocompleteTests
+public class AutocompleteTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public AutocompleteTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     [AutoInitShutdown]
     public void CursorLeft_CursorRight_Mouse_Button_Pressed_Does_Not_Show_Popup ()
@@ -34,7 +31,7 @@ public class AutocompleteTests
                 TestHelpers.AssertDriverContentsWithFrameAre (
                                                               @"
 This a long line and against TextView.",
-                                                              _output
+                                                              output
                                                              );
             }
             else
@@ -44,15 +41,15 @@ This a long line and against TextView.",
 This a long line and against TextView.
      and                              
      against                          ",
-                                                              _output
+                                                              output
                                                              );
             }
         }
 
         Assert.True (
                      tv.NewMouseEvent (
-                                    new MouseEvent { Position = new (6, 0), Flags = MouseFlags.Button1Pressed }
-                                   )
+                                       new() { Position = new (6, 0), Flags = MouseFlags.Button1Pressed }
+                                      )
                     );
         Application.Refresh ();
 
@@ -61,7 +58,7 @@ This a long line and against TextView.
 This a long line and against TextView.
      and                              
      against                          ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (tv.NewKeyDownEvent (Key.G));
@@ -71,7 +68,7 @@ This a long line and against TextView.
                                                       @"
 This ag long line and against TextView.
      against                           ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (tv.NewKeyDownEvent (Key.CursorLeft));
@@ -81,7 +78,7 @@ This ag long line and against TextView.
                                                       @"
 This ag long line and against TextView.
      against                           ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (tv.NewKeyDownEvent (Key.CursorLeft));
@@ -91,7 +88,7 @@ This ag long line and against TextView.
                                                       @"
 This ag long line and against TextView.
      against                           ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (tv.NewKeyDownEvent (Key.CursorLeft));
@@ -100,7 +97,7 @@ This ag long line and against TextView.
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 This ag long line and against TextView.",
-                                                      _output
+                                                      output
                                                      );
 
         for (var i = 0; i < 3; i++)
@@ -112,7 +109,7 @@ This ag long line and against TextView.",
                                                           @"
 This ag long line and against TextView.
      against                           ",
-                                                          _output
+                                                          output
                                                          );
         }
 
@@ -124,7 +121,7 @@ This ag long line and against TextView.
 This a long line and against TextView.
      and                              
      against                          ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (tv.NewKeyDownEvent (Key.N));
@@ -134,7 +131,7 @@ This a long line and against TextView.
                                                       @"
 This an long line and against TextView.
      and                               ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (tv.NewKeyDownEvent (Key.CursorRight));
@@ -143,8 +140,9 @@ This an long line and against TextView.
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 This an long line and against TextView.",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -175,7 +173,7 @@ This an long line and against TextView.",
         Assert.True (tv.NewKeyDownEvent (Key.F.WithShift));
         top.Draw ();
         Assert.Equal ("F Fortunately super feature.", tv.Text);
-        Assert.Equal (new Point (1, 0), tv.CursorPosition);
+        Assert.Equal (new (1, 0), tv.CursorPosition);
         Assert.Equal (2, tv.Autocomplete.Suggestions.Count);
         Assert.Equal ("Fortunately", tv.Autocomplete.Suggestions [0].Replacement);
         Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement);
@@ -184,7 +182,7 @@ This an long line and against TextView.",
         Assert.True (tv.NewKeyDownEvent (Key.CursorDown));
         top.Draw ();
         Assert.Equal ("F Fortunately super feature.", tv.Text);
-        Assert.Equal (new Point (1, 0), tv.CursorPosition);
+        Assert.Equal (new (1, 0), tv.CursorPosition);
         Assert.Equal (2, tv.Autocomplete.Suggestions.Count);
         Assert.Equal ("Fortunately", tv.Autocomplete.Suggestions [0].Replacement);
         Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement);
@@ -193,7 +191,7 @@ This an long line and against TextView.",
         Assert.True (tv.NewKeyDownEvent (Key.CursorDown));
         top.Draw ();
         Assert.Equal ("F Fortunately super feature.", tv.Text);
-        Assert.Equal (new Point (1, 0), tv.CursorPosition);
+        Assert.Equal (new (1, 0), tv.CursorPosition);
         Assert.Equal (2, tv.Autocomplete.Suggestions.Count);
         Assert.Equal ("Fortunately", tv.Autocomplete.Suggestions [0].Replacement);
         Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement);
@@ -202,7 +200,7 @@ This an long line and against TextView.",
         Assert.True (tv.NewKeyDownEvent (Key.CursorUp));
         top.Draw ();
         Assert.Equal ("F Fortunately super feature.", tv.Text);
-        Assert.Equal (new Point (1, 0), tv.CursorPosition);
+        Assert.Equal (new (1, 0), tv.CursorPosition);
         Assert.Equal (2, tv.Autocomplete.Suggestions.Count);
         Assert.Equal ("Fortunately", tv.Autocomplete.Suggestions [0].Replacement);
         Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement);
@@ -211,7 +209,7 @@ This an long line and against TextView.",
         Assert.True (tv.NewKeyDownEvent (Key.CursorUp));
         top.Draw ();
         Assert.Equal ("F Fortunately super feature.", tv.Text);
-        Assert.Equal (new Point (1, 0), tv.CursorPosition);
+        Assert.Equal (new (1, 0), tv.CursorPosition);
         Assert.Equal (2, tv.Autocomplete.Suggestions.Count);
         Assert.Equal ("Fortunately", tv.Autocomplete.Suggestions [0].Replacement);
         Assert.Equal ("feature", tv.Autocomplete.Suggestions [^1].Replacement);
@@ -219,25 +217,26 @@ This an long line and against TextView.",
         Assert.Equal ("Fortunately", tv.Autocomplete.Suggestions [tv.Autocomplete.SelectedIdx].Replacement);
         Assert.True (tv.Autocomplete.Visible);
         top.Draw ();
-        Assert.True (tv.NewKeyDownEvent (new Key (tv.Autocomplete.CloseKey)));
+        Assert.True (tv.NewKeyDownEvent (new (tv.Autocomplete.CloseKey)));
         Assert.Equal ("F Fortunately super feature.", tv.Text);
-        Assert.Equal (new Point (1, 0), tv.CursorPosition);
+        Assert.Equal (new (1, 0), tv.CursorPosition);
         Assert.Empty (tv.Autocomplete.Suggestions);
         Assert.Equal (3, g.AllSuggestions.Count);
         Assert.False (tv.Autocomplete.Visible);
         tv.PositionCursor ();
-        Assert.True (tv.NewKeyDownEvent (new Key (tv.Autocomplete.Reopen)));
+        Assert.True (tv.NewKeyDownEvent (new (tv.Autocomplete.Reopen)));
         Assert.Equal ("F Fortunately super feature.", tv.Text);
-        Assert.Equal (new Point (1, 0), tv.CursorPosition);
+        Assert.Equal (new (1, 0), tv.CursorPosition);
         Assert.Equal (2, tv.Autocomplete.Suggestions.Count);
         Assert.Equal (3, g.AllSuggestions.Count);
-        Assert.True (tv.NewKeyDownEvent (new Key (tv.Autocomplete.SelectionKey)));
+        Assert.True (tv.NewKeyDownEvent (new (tv.Autocomplete.SelectionKey)));
         tv.PositionCursor ();
         Assert.Equal ("Fortunately Fortunately super feature.", tv.Text);
-        Assert.Equal (new Point (11, 0), tv.CursorPosition);
+        Assert.Equal (new (11, 0), tv.CursorPosition);
         Assert.Empty (tv.Autocomplete.Suggestions);
         Assert.Equal (3, g.AllSuggestions.Count);
         Assert.False (tv.Autocomplete.Visible);
+        top.Dispose ();
     }
 
     [Fact]
@@ -246,7 +245,7 @@ This an long line and against TextView.",
         var ac = new TextViewAutocomplete ();
 
         ((SingleWordSuggestionGenerator)ac.SuggestionGenerator).AllSuggestions =
-            new List<string> { "fish", "const", "Cobble" };
+            new() { "fish", "const", "Cobble" };
 
         var tv = new TextView ();
         tv.InsertText ("co");
@@ -254,10 +253,10 @@ This an long line and against TextView.",
         ac.HostControl = tv;
 
         ac.GenerateSuggestions (
-                                new AutocompleteContext (
-                                                         TextModel.ToRuneCellList (tv.Text),
-                                                         2
-                                                        )
+                                new (
+                                     TextModel.ToRuneCellList (tv.Text),
+                                     2
+                                    )
                                );
 
         Assert.Equal (2, ac.Suggestions.Count);
@@ -266,7 +265,6 @@ This an long line and against TextView.",
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void TestSettingColorSchemeOnAutocomplete ()
     {
         var tv = new TextView ();
@@ -275,19 +273,19 @@ This an long line and against TextView.",
         Assert.Same (Colors.ColorSchemes ["Menu"], tv.Autocomplete.ColorScheme);
 
         // allocate a new custom scheme
-        tv.Autocomplete.ColorScheme = new ColorScheme
+        tv.Autocomplete.ColorScheme = new()
         {
-            Normal = new Attribute (Color.Black, Color.Blue), Focus = new Attribute (Color.Black, Color.Cyan)
+            Normal = new (Color.Black, Color.Blue), Focus = new (Color.Black, Color.Cyan)
         };
 
         // should be separate instance
         Assert.NotSame (Colors.ColorSchemes ["Menu"], tv.Autocomplete.ColorScheme);
 
         // with the values we set on it
-        Assert.Equal (new Color (Color.Black), tv.Autocomplete.ColorScheme.Normal.Foreground);
-        Assert.Equal (new Color (Color.Blue), tv.Autocomplete.ColorScheme.Normal.Background);
+        Assert.Equal (new (Color.Black), tv.Autocomplete.ColorScheme.Normal.Foreground);
+        Assert.Equal (new (Color.Blue), tv.Autocomplete.ColorScheme.Normal.Background);
 
-        Assert.Equal (new Color (Color.Black), tv.Autocomplete.ColorScheme.Focus.Foreground);
-        Assert.Equal (new Color (Color.Cyan), tv.Autocomplete.ColorScheme.Focus.Background);
+        Assert.Equal (new (Color.Black), tv.Autocomplete.ColorScheme.Focus.Foreground);
+        Assert.Equal (new (Color.Cyan), tv.Autocomplete.ColorScheme.Focus.Background);
     }
 }

+ 58 - 53
UnitTests/View/Adornment/BorderTests.cs

@@ -2,11 +2,8 @@
 
 namespace Terminal.Gui.ViewTests;
 
-public class BorderTests
+public class BorderTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public BorderTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     [SetupFakeDriver]
     public void Border_Parent_HasFocus_Title_Uses_FocusAttribute ()
@@ -18,13 +15,13 @@ public class BorderTests
         var view = new View { Title = "A", Height = 2, Width = 5 };
         superView.Add (view);
 
-        view.Border.Thickness = new Thickness (0, 1, 0, 0);
+        view.Border.Thickness = new (0, 1, 0, 0);
         view.Border.LineStyle = LineStyle.Single;
 
-        view.ColorScheme = new ColorScheme
+        view.ColorScheme = new()
         {
-            Normal = new Attribute (Color.Red, Color.Green), 
-            Focus = new Attribute (Color.Green, Color.Red)
+            Normal = new (Color.Red, Color.Green),
+            Focus = new (Color.Green, Color.Red)
         };
         Assert.NotEqual (view.ColorScheme.Normal.Foreground, view.ColorScheme.Focus.Foreground);
         Assert.Equal (ColorName.Red, view.Border.GetNormalColor ().Foreground.GetClosestNamedColor ());
@@ -36,7 +33,7 @@ public class BorderTests
         superView.Draw ();
 
         var expected = @"─┤A├─";
-        TestHelpers.AssertDriverContentsAre (expected, _output);
+        TestHelpers.AssertDriverContentsAre (expected, output);
         TestHelpers.AssertDriverAttributesAre ("00000", null, view.ColorScheme.Normal);
 
         view.CanFocus = true;
@@ -53,12 +50,12 @@ public class BorderTests
     public void Border_Uses_Parent_ColorScheme ()
     {
         var view = new View { Title = "A", Height = 2, Width = 5 };
-        view.Border.Thickness = new Thickness (0, 1, 0, 0);
+        view.Border.Thickness = new (0, 1, 0, 0);
         view.Border.LineStyle = LineStyle.Single;
 
-        view.ColorScheme = new ColorScheme
+        view.ColorScheme = new()
         {
-            Normal = new Attribute (Color.Red, Color.Green), Focus = new Attribute (Color.Green, Color.Red)
+            Normal = new (Color.Red, Color.Green), Focus = new (Color.Green, Color.Red)
         };
         Assert.Equal (ColorName.Red, view.Border.GetNormalColor ().Foreground.GetClosestNamedColor ());
         Assert.Equal (ColorName.Green, view.Border.GetFocusColor ().Foreground.GetClosestNamedColor ());
@@ -70,7 +67,7 @@ public class BorderTests
         view.Draw ();
 
         var expected = @"─┤A├─";
-        TestHelpers.AssertDriverContentsAre (expected, _output);
+        TestHelpers.AssertDriverContentsAre (expected, output);
         TestHelpers.AssertDriverAttributesAre ("00000", null, view.ColorScheme.Normal);
     }
 
@@ -105,7 +102,7 @@ public class BorderTests
         switch (width)
         {
             case 1:
-                Assert.Equal (new Rectangle (0, 0, 1, 5), win.Frame);
+                Assert.Equal (new (0, 0, 1, 5), win.Frame);
 
                 expected = @"
@@ -114,7 +111,7 @@ public class BorderTests
 
                 break;
             case 2:
-                Assert.Equal (new Rectangle (0, 0, 2, 5), win.Frame);
+                Assert.Equal (new (0, 0, 2, 5), win.Frame);
 
                 expected = @"
 ╔╗
@@ -123,7 +120,7 @@ public class BorderTests
 
                 break;
             case 3:
-                Assert.Equal (new Rectangle (0, 0, 3, 5), win.Frame);
+                Assert.Equal (new (0, 0, 3, 5), win.Frame);
 
                 expected = @"
 ╔═╗
@@ -132,7 +129,7 @@ public class BorderTests
 
                 break;
             case 4:
-                Assert.Equal (new Rectangle (0, 0, 4, 5), win.Frame);
+                Assert.Equal (new (0, 0, 4, 5), win.Frame);
 
                 expected = @"
  ╒╕ 
@@ -142,7 +139,7 @@ public class BorderTests
 
                 break;
             case 5:
-                Assert.Equal (new Rectangle (0, 0, 5, 5), win.Frame);
+                Assert.Equal (new (0, 0, 5, 5), win.Frame);
 
                 expected = @"
  ╒═╕ 
@@ -152,7 +149,7 @@ public class BorderTests
 
                 break;
             case 6:
-                Assert.Equal (new Rectangle (0, 0, 6, 5), win.Frame);
+                Assert.Equal (new (0, 0, 6, 5), win.Frame);
 
                 expected = @"
  ╒══╕ 
@@ -162,7 +159,7 @@ public class BorderTests
 
                 break;
             case 7:
-                Assert.Equal (new Rectangle (0, 0, 7, 5), win.Frame);
+                Assert.Equal (new (0, 0, 7, 5), win.Frame);
 
                 expected = @"
  ╒═══╕ 
@@ -172,7 +169,7 @@ public class BorderTests
 
                 break;
             case 8:
-                Assert.Equal (new Rectangle (0, 0, 8, 5), win.Frame);
+                Assert.Equal (new (0, 0, 8, 5), win.Frame);
 
                 expected = @"
  ╒════╕ 
@@ -182,7 +179,7 @@ public class BorderTests
 
                 break;
             case 9:
-                Assert.Equal (new Rectangle (0, 0, 9, 5), win.Frame);
+                Assert.Equal (new (0, 0, 9, 5), win.Frame);
 
                 expected = @"
  ╒════╕  
@@ -192,7 +189,7 @@ public class BorderTests
 
                 break;
             case 10:
-                Assert.Equal (new Rectangle (0, 0, 10, 5), win.Frame);
+                Assert.Equal (new (0, 0, 10, 5), win.Frame);
 
                 expected = @"
  ╒════╕   
@@ -203,8 +200,9 @@ public class BorderTests
                 break;
         }
 
-        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        win.Dispose ();
     }
 
     [Theory]
@@ -238,7 +236,7 @@ public class BorderTests
         switch (width)
         {
             case 1:
-                Assert.Equal (new Rectangle (0, 0, 1, 4), win.Frame);
+                Assert.Equal (new (0, 0, 1, 4), win.Frame);
 
                 expected = @"
@@ -247,7 +245,7 @@ public class BorderTests
 
                 break;
             case 2:
-                Assert.Equal (new Rectangle (0, 0, 2, 4), win.Frame);
+                Assert.Equal (new (0, 0, 2, 4), win.Frame);
 
                 expected = @"
 ╔╗
@@ -256,7 +254,7 @@ public class BorderTests
 
                 break;
             case 3:
-                Assert.Equal (new Rectangle (0, 0, 3, 4), win.Frame);
+                Assert.Equal (new (0, 0, 3, 4), win.Frame);
 
                 expected = @"
 ╔═╗
@@ -265,7 +263,7 @@ public class BorderTests
 
                 break;
             case 4:
-                Assert.Equal (new Rectangle (0, 0, 4, 4), win.Frame);
+                Assert.Equal (new (0, 0, 4, 4), win.Frame);
 
                 expected = @"
  ╒╕ 
@@ -275,7 +273,7 @@ public class BorderTests
 
                 break;
             case 5:
-                Assert.Equal (new Rectangle (0, 0, 5, 4), win.Frame);
+                Assert.Equal (new (0, 0, 5, 4), win.Frame);
 
                 expected = @"
  ╒═╕ 
@@ -285,7 +283,7 @@ public class BorderTests
 
                 break;
             case 6:
-                Assert.Equal (new Rectangle (0, 0, 6, 4), win.Frame);
+                Assert.Equal (new (0, 0, 6, 4), win.Frame);
 
                 expected = @"
  ╒══╕ 
@@ -295,7 +293,7 @@ public class BorderTests
 
                 break;
             case 7:
-                Assert.Equal (new Rectangle (0, 0, 7, 4), win.Frame);
+                Assert.Equal (new (0, 0, 7, 4), win.Frame);
 
                 expected = @"
  ╒═══╕ 
@@ -305,7 +303,7 @@ public class BorderTests
 
                 break;
             case 8:
-                Assert.Equal (new Rectangle (0, 0, 8, 4), win.Frame);
+                Assert.Equal (new (0, 0, 8, 4), win.Frame);
 
                 expected = @"
  ╒════╕ 
@@ -315,7 +313,7 @@ public class BorderTests
 
                 break;
             case 9:
-                Assert.Equal (new Rectangle (0, 0, 9, 4), win.Frame);
+                Assert.Equal (new (0, 0, 9, 4), win.Frame);
 
                 expected = @"
  ╒════╕  
@@ -325,7 +323,7 @@ public class BorderTests
 
                 break;
             case 10:
-                Assert.Equal (new Rectangle (0, 0, 10, 4), win.Frame);
+                Assert.Equal (new (0, 0, 10, 4), win.Frame);
 
                 expected = @"
  ╒════╕   
@@ -336,8 +334,9 @@ public class BorderTests
                 break;
         }
 
-        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        win.Dispose ();
     }
 
     [Theory]
@@ -371,7 +370,7 @@ public class BorderTests
         switch (width)
         {
             case 1:
-                Assert.Equal (new Rectangle (0, 0, 1, 4), win.Frame);
+                Assert.Equal (new (0, 0, 1, 4), win.Frame);
 
                 expected = @"
@@ -380,7 +379,7 @@ public class BorderTests
 
                 break;
             case 2:
-                Assert.Equal (new Rectangle (0, 0, 2, 4), win.Frame);
+                Assert.Equal (new (0, 0, 2, 4), win.Frame);
 
                 expected = @"
 ╔╗
@@ -389,7 +388,7 @@ public class BorderTests
 
                 break;
             case 3:
-                Assert.Equal (new Rectangle (0, 0, 3, 4), win.Frame);
+                Assert.Equal (new (0, 0, 3, 4), win.Frame);
 
                 expected = @"
 ╔═╗
@@ -398,7 +397,7 @@ public class BorderTests
 
                 break;
             case 4:
-                Assert.Equal (new Rectangle (0, 0, 4, 4), win.Frame);
+                Assert.Equal (new (0, 0, 4, 4), win.Frame);
 
                 expected = @"
  ╒╕ 
@@ -408,7 +407,7 @@ public class BorderTests
 
                 break;
             case 5:
-                Assert.Equal (new Rectangle (0, 0, 5, 4), win.Frame);
+                Assert.Equal (new (0, 0, 5, 4), win.Frame);
 
                 expected = @"
  ╒═╕ 
@@ -418,7 +417,7 @@ public class BorderTests
 
                 break;
             case 6:
-                Assert.Equal (new Rectangle (0, 0, 6, 4), win.Frame);
+                Assert.Equal (new (0, 0, 6, 4), win.Frame);
 
                 expected = @"
  ╒══╕ 
@@ -428,7 +427,7 @@ public class BorderTests
 
                 break;
             case 7:
-                Assert.Equal (new Rectangle (0, 0, 7, 4), win.Frame);
+                Assert.Equal (new (0, 0, 7, 4), win.Frame);
 
                 expected = @"
  ╒═══╕ 
@@ -438,7 +437,7 @@ public class BorderTests
 
                 break;
             case 8:
-                Assert.Equal (new Rectangle (0, 0, 8, 4), win.Frame);
+                Assert.Equal (new (0, 0, 8, 4), win.Frame);
 
                 expected = @"
  ╒════╕ 
@@ -448,7 +447,7 @@ public class BorderTests
 
                 break;
             case 9:
-                Assert.Equal (new Rectangle (0, 0, 9, 4), win.Frame);
+                Assert.Equal (new (0, 0, 9, 4), win.Frame);
 
                 expected = @"
  ╒════╕  
@@ -458,7 +457,7 @@ public class BorderTests
 
                 break;
             case 10:
-                Assert.Equal (new Rectangle (0, 0, 10, 4), win.Frame);
+                Assert.Equal (new (0, 0, 10, 4), win.Frame);
 
                 expected = @"
  ╒════╕   
@@ -469,8 +468,9 @@ public class BorderTests
                 break;
         }
 
-        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        win.Dispose ();
     }
 
     [Theory]
@@ -523,8 +523,9 @@ public class BorderTests
                 break;
         }
 
-        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        win.Dispose ();
     }
 
     [Theory]
@@ -636,7 +637,8 @@ public class BorderTests
                 break;
         }
 
-        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        win.Dispose ();
     }
 
     [Theory]
@@ -736,8 +738,9 @@ public class BorderTests
 ║└─┘║
 ╚═══╝";
 
-        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
@@ -762,8 +765,9 @@ public class BorderTests
 ║└──────┘║
 ╚════════╝";
 
-        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
@@ -783,7 +787,8 @@ public class BorderTests
 │ │
 └─┘";
 
-        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        win.Dispose ();
     }
 
     [Fact]
@@ -801,11 +806,11 @@ public class BorderTests
         var view = new View ();
         view.BorderStyle = LineStyle.Single;
         Assert.Equal (LineStyle.Single, view.BorderStyle);
-        Assert.Equal (new Thickness (1), view.Border.Thickness);
+        Assert.Equal (new (1), view.Border.Thickness);
 
         view.BorderStyle = LineStyle.Double;
         Assert.Equal (LineStyle.Double, view.BorderStyle);
-        Assert.Equal (new Thickness (1), view.Border.Thickness);
+        Assert.Equal (new (1), view.Border.Thickness);
 
         view.BorderStyle = LineStyle.None;
         Assert.Equal (LineStyle.None, view.BorderStyle);

+ 2 - 5
UnitTests/View/Adornment/MarginTests.cs

@@ -2,11 +2,8 @@
 
 namespace Terminal.Gui.ViewTests;
 
-public class MarginTests
+public class MarginTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public MarginTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     [SetupFakeDriver]
     public void Margin_Uses_SuperView_ColorScheme ()
@@ -39,7 +36,7 @@ public class MarginTests
 MMM
 M M
 MMM",
-                                             _output
+                                             output
                                             );
         TestHelpers.AssertDriverAttributesAre ("0", null, superView.GetNormalColor ());
     }

+ 5 - 8
UnitTests/View/Adornment/PaddingTests.cs

@@ -2,22 +2,19 @@
 
 namespace Terminal.Gui.ViewTests;
 
-public class PaddingTests
+public class PaddingTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public PaddingTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     [SetupFakeDriver]
     public void Padding_Uses_Parent_ColorScheme ()
     {
         ((FakeDriver)Application.Driver).SetBufferSize (5, 5);
         var view = new View { Height = 3, Width = 3 };
-        view.Padding.Thickness = new Thickness (1);
+        view.Padding.Thickness = new (1);
 
-        view.ColorScheme = new ColorScheme
+        view.ColorScheme = new()
         {
-            Normal = new Attribute (Color.Red, Color.Green), Focus = new Attribute (Color.Green, Color.Red)
+            Normal = new (Color.Red, Color.Green), Focus = new (Color.Green, Color.Red)
         };
 
         Assert.Equal (ColorName.Red, view.Padding.GetNormalColor ().Foreground.GetClosestNamedColor ());
@@ -34,7 +31,7 @@ public class PaddingTests
 PPP
 P P
 PPP",
-                                             _output
+                                             output
                                             );
         TestHelpers.AssertDriverAttributesAre ("0", null, view.GetNormalColor ());
     }

+ 7 - 6
UnitTests/View/DiagnosticsTests.cs

@@ -4,21 +4,22 @@ using Xunit.Abstractions;
 namespace Terminal.Gui.ViewTests;
 
 /// <summary>
-/// Tests <see cref="View.Diagnostics"/> static property and <see cref="ViewDiagnosticFlags"/> enum.
+///     Tests <see cref="View.Diagnostics"/> static property and <see cref="ViewDiagnosticFlags"/> enum.
 /// </summary>
 /// <param name="output"></param>
-[Trait("Category","Output")]
-public class DiagnosticTests (ITestOutputHelper output)
+[Trait ("Category", "Output")]
+public class DiagnosticTests ()
 {
     /// <summary>
-    ///    /// Tests <see cref="View.Diagnostics"/> static property and <see cref="ViewDiagnosticFlags"/> enum.
-    ///    /// </summary>
+    ///     /// Tests <see cref="View.Diagnostics"/> static property and <see cref="ViewDiagnosticFlags"/> enum.
+    ///     ///
+    /// </summary>
     [Fact]
     public void Diagnostics_Sets ()
     {
         // View.Diagnostics is a static property that returns the current diagnostic flags.
         Assert.Equal (ViewDiagnosticFlags.Off, View.Diagnostics);
-    
+
         // View.Diagnostics can be set to a new value.
         View.Diagnostics = ViewDiagnosticFlags.Padding;
         Assert.Equal (ViewDiagnosticFlags.Padding, View.Diagnostics);

+ 17 - 14
UnitTests/View/DrawTests.cs

@@ -155,12 +155,9 @@ public class DrawTests (ITestOutputHelper _output)
                                                       _output);
     }
 
-    [Theory]
-    [InlineData (0, 0, 1, 1)]
-    [InlineData (0, 0, 2, 2)]
-    [InlineData (-1, -1, 2, 2)]
+    [Fact]
     [SetupFakeDriver]
-    public void Clear_ClearsEntireViewport (int x, int y, int width, int height)
+    public void Clear_ClearsEntireViewport ()
     {
         var superView = new View { Width = Dim.Fill (), Height = Dim.Fill () };
 
@@ -193,12 +190,9 @@ public class DrawTests (ITestOutputHelper _output)
                                                       _output);
     }
 
-    [Theory]
-    [InlineData (0, 0, 1, 1)]
-    [InlineData (0, 0, 2, 2)]
-    [InlineData (-1, -1, 2, 2)]
+    [Fact]
     [SetupFakeDriver]
-    public void Clear_WithClearVisibleContentOnly_ClearsVisibleContentOnly (int x, int y, int width, int height)
+    public void Clear_WithClearVisibleContentOnly_ClearsVisibleContentOnly ()
     {
         var superView = new View { Width = Dim.Fill (), Height = Dim.Fill () };
 
@@ -270,6 +264,7 @@ public class DrawTests (ITestOutputHelper _output)
         TestHelpers.AssertDriverContentsAre (expectedOutput, _output);
 
         // This test has nothing to do with color - removing as it is not relevant and fragile
+        top.Dispose ();
     }
 
     // TODO: Refactor this test to not depend on TextView etc... Make it as primitive as possible
@@ -326,7 +321,9 @@ public class DrawTests (ITestOutputHelper _output)
         Assert.Equal (new Rectangle (0, 0, 30, 10), pos);
 
         Application.End (rsDiag);
+        dg.Dispose ();
         Application.End (rsTop);
+        top.Dispose ();
     }
 
     [Fact]
@@ -385,8 +382,9 @@ public class DrawTests (ITestOutputHelper _output)
                                                0
                                                """,
                                                Application.Driver,
-                                               Colors.ColorSchemes ["Base"].Normal
+                                               Colors.ColorSchemes ["Base"]!.Normal
                                               );
+        top.Dispose ();
     }
 
     [Fact]
@@ -647,6 +645,7 @@ public class DrawTests (ITestOutputHelper _output)
         content.Y = 0;
         Application.Refresh ();
         TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
+        top.Dispose ();
     }
 
     [Fact]
@@ -681,8 +680,6 @@ public class DrawTests (ITestOutputHelper _output)
 
         // BUGBUG: v2 - it's bogus to reference .Frame before BeginInit. And why is the clip being set anyway???
 
-        void Top_LayoutComplete (object sender, LayoutEventArgs e) { Application.Driver.Clip = container.Frame; }
-
         top.LayoutComplete += Top_LayoutComplete;
         Application.Begin (top);
 
@@ -726,6 +723,11 @@ public class DrawTests (ITestOutputHelper _output)
         content.Y = 0;
         Application.Refresh ();
         TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
+        top.Dispose ();
+
+        return;
+
+        void Top_LayoutComplete (object? sender, LayoutEventArgs e) { Application.Driver.Clip = container.Frame; }
     }
 
     [Fact]
@@ -849,6 +851,7 @@ public class DrawTests (ITestOutputHelper _output)
         content.Y = 0;
         Application.Refresh ();
         TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
+        top.Dispose ();
     }
 
     [Theory]
@@ -898,7 +901,7 @@ public class DrawTests (ITestOutputHelper _output)
         TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
 
         TestHelpers.AssertDriverContentsAre (expected, _output);
-
+        top.Dispose ();
         // This test has nothing to do with color - removing as it is not relevant and fragile
     }
 

+ 4 - 4
UnitTests/View/InitTests.cs

@@ -125,11 +125,11 @@ public class InitTests
         var superView = new View ();
         superView.Add (view);
 
-        var initialized = false;
-        view.Initialized += (s, e) => initialized = true;
+        //var initialized = false;
+        //view.Initialized += (s, e) => initialized = true;
 
-        var superViewInitialized = false;
-        superView.Initialized += (s, e) => superViewInitialized = true;
+        //var superViewInitialized = false;
+        //superView.Initialized += (s, e) => superViewInitialized = true;
 
         Assert.False (view.IsInitialized, "View should not be initialized");
         Assert.False (superView.IsInitialized, "SuperView should not be initialized");

+ 1 - 0
UnitTests/View/Layout/Dim.FillTests.cs

@@ -22,6 +22,7 @@ public class DimFillTests (ITestOutputHelper output)
         //view.SetRelativeLayout (new (0, 0, 32, 5));
         Assert.Equal (32, view.Frame.Width);
         Assert.Equal (5, view.Frame.Height);
+        top.Dispose ();
     }
 
 

+ 71 - 72
UnitTests/View/Layout/Dim.Tests.cs

@@ -3,10 +3,6 @@ using System.Text;
 using Xunit.Abstractions;
 using static Terminal.Gui.Dim;
 
-
-// Alias Console to MockConsole so we don't accidentally use Console
-using Console = Terminal.Gui.FakeConsole;
-
 namespace Terminal.Gui.LayoutTests;
 
 public class DimTests
@@ -28,7 +24,7 @@ public class DimTests
     public void DimAbsolute_Calculate_ReturnsCorrectValue ()
     {
         var dim = new DimAbsolute (10);
-        var result = dim.Calculate (0, 100, null, Dimension.None);
+        int result = dim.Calculate (0, 100, null, Dimension.None);
         Assert.Equal (10, result);
     }
 
@@ -144,6 +140,7 @@ public class DimTests
         Application.Run (top);
 
         Assert.Equal (0, count);
+        top.Dispose ();
     }
 
     // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
@@ -173,7 +170,7 @@ public class DimTests
     [Fact]
     public void DimHeight_Set_To_Null_Throws ()
     {
-        Dim dim = Dim.Height (null);
+        Dim dim = Height (null);
         Assert.Throws<NullReferenceException> (() => dim.ToString ());
     }
 
@@ -183,13 +180,13 @@ public class DimTests
     {
         var testVal = Rectangle.Empty;
         var testValview = new View { Frame = testVal };
-        Dim dim = Dim.Height (testValview);
+        Dim dim = Height (testValview);
         Assert.Equal ($"View(Height,View(){testVal})", dim.ToString ());
         testValview.Dispose ();
 
-        testVal = new Rectangle (1, 2, 3, 4);
-        testValview = new View { Frame = testVal };
-        dim = Dim.Height (testValview);
+        testVal = new (1, 2, 3, 4);
+        testValview = new() { Frame = testVal };
+        dim = Height (testValview);
         Assert.Equal ($"View(Height,View(){testVal})", dim.ToString ());
         testValview.Dispose ();
     }
@@ -212,7 +209,7 @@ public class DimTests
         Assert.Equal (dimCombine.Right, dimAbsolute);
         Assert.Equal (20, dimCombine.GetAnchor (100));
 
-        var view = new View { Frame = new Rectangle (20, 10, 20, 1) };
+        var view = new View { Frame = new (20, 10, 20, 1) };
         var dimViewHeight = new DimView (view, Dimension.Height);
         Assert.Equal (1, dimViewHeight.GetAnchor (0));
         var dimViewWidth = new DimView (view, Dimension.Width);
@@ -236,7 +233,7 @@ public class DimTests
         {
             X = 0,
             Y = 0,
-            Width = Dim.Percent (50),
+            Width = Percent (50),
             Height = 5,
             Title = "f1"
         };
@@ -245,7 +242,7 @@ public class DimTests
         {
             X = Pos.Right (f1),
             Y = 0,
-            Width = Dim.Fill (),
+            Width = Fill (),
             Height = 5,
             Title = "f2"
         };
@@ -254,8 +251,8 @@ public class DimTests
         {
             X = Pos.X (f1) + 2,
             Y = Pos.Bottom (f1) + 2,
-            Width = Dim.Width (f1) - 2,
-            Height = Dim.Fill () - 2,
+            Width = Width (f1) - 2,
+            Height = Fill () - 2,
             ValidatePosDim = true,
             Text = "v1"
         };
@@ -264,32 +261,32 @@ public class DimTests
         {
             X = Pos.X (f2) + 2,
             Y = Pos.Bottom (f2) + 2,
-            Width = Dim.Width (f2) - 2,
-            Height = Dim.Fill () - 2,
+            Width = Width (f2) - 2,
+            Height = Fill () - 2,
             ValidatePosDim = true,
             Text = "v2"
         };
 
         var v3 = new Button
         {
-            Width = Dim.Percent (10),
-            Height = Dim.Percent (10),
+            Width = Percent (10),
+            Height = Percent (10),
             ValidatePosDim = true,
             Text = "v3"
         };
 
         var v4 = new Button
         {
-            Width = Dim.Absolute (50),
-            Height = Dim.Absolute (50),
+            Width = Absolute (50),
+            Height = Absolute (50),
             ValidatePosDim = true,
             Text = "v4"
         };
 
         var v5 = new Button
         {
-            Width = Dim.Width (v1) - Dim.Width (v3),
-            Height = Dim.Height (v1) - Dim.Height (v3),
+            Width = Width (v1) - Width (v3),
+            Height = Height (v1) - Height (v3),
             ValidatePosDim = true,
             Text = "v5"
         };
@@ -298,8 +295,8 @@ public class DimTests
         {
             X = Pos.X (f2),
             Y = Pos.Bottom (f2) + 2,
-            Width = Dim.Percent (20, DimPercentMode.Position),
-            Height = Dim.Percent (20, DimPercentMode.Position),
+            Width = Percent (20, DimPercentMode.Position),
+            Height = Percent (20, DimPercentMode.Position),
             ValidatePosDim = true,
             Text = "v6"
         };
@@ -362,10 +359,10 @@ public class DimTests
 #else
                        Assert.Equal ($"Combine(View(Height,Button(){v1.Frame})-View(Height,Button(){v3.Viewport}))", v5.Height.ToString ( ));
 #endif
-                       Assert.Equal (38, v5.Frame.Width);  // 47-9=38
+                       Assert.Equal (38, v5.Frame.Width); // 47-9=38
                        Assert.Equal (80, v5.Frame.Height); // 89-9=80
 
-                       Assert.Equal (9, v6.Frame.Width);   // 47*20%=9
+                       Assert.Equal (9, v6.Frame.Width); // 47*20%=9
                        Assert.Equal (18, v6.Frame.Height); // 89*20%=18
 
                        w.Width = 200;
@@ -395,7 +392,7 @@ public class DimTests
                        Assert.Equal ($"Combine(View(Width,FrameView(){f1.Frame})-Absolute(2))", v1.Width.ToString ());
 #endif
                        Assert.Equal ("Combine(Fill(0)-Absolute(2))", v1.Height.ToString ());
-                       Assert.Equal (97, v1.Frame.Width);   // 99-2=97
+                       Assert.Equal (97, v1.Frame.Width); // 99-2=97
                        Assert.Equal (189, v1.Frame.Height); // 198-2-7=189
 
                        v2.Text = "Button2";
@@ -406,21 +403,22 @@ public class DimTests
                        Assert.Equal ($"Combine(View(Width,FrameView(){f2.Frame})-Absolute(2))", v2.Width.ToString ());
 #endif
                        Assert.Equal ("Combine(Fill(0)-Absolute(2))", v2.Height.ToString ());
-                       Assert.Equal (97, v2.Frame.Width);   // 99-2=97
+                       Assert.Equal (97, v2.Frame.Width); // 99-2=97
                        Assert.Equal (189, v2.Frame.Height); // 198-2-7=189
 
                        v3.Text = "Button3";
 
                        // 198*10%=19 * Percent is related to the super-view if it isn't null otherwise the view width
                        Assert.Equal (19, v3.Frame.Width);
+
                        // 199*10%=19
                        Assert.Equal (19, v3.Frame.Height);
 
                        v4.Text = "Button4";
-                       v4.Width = Auto(DimAutoStyle.Text);
+                       v4.Width = Auto (DimAutoStyle.Text);
                        v4.Height = Auto (DimAutoStyle.Text);
-                       Assert.Equal (Dim.Auto (DimAutoStyle.Text), v4.Width);
-                       Assert.Equal (Dim.Auto (DimAutoStyle.Text), v4.Height);
+                       Assert.Equal (Auto (DimAutoStyle.Text), v4.Width);
+                       Assert.Equal (Auto (DimAutoStyle.Text), v4.Height);
                        Assert.Equal (11, v4.Frame.Width); // 11 is the text length and because is DimAbsolute
                        Assert.Equal (1, v4.Frame.Height); // 1 because is DimAbsolute
 
@@ -434,17 +432,18 @@ public class DimTests
                        Assert.Equal ($"Combine(View(Height,Button(){v1.Frame})-View(Height,Button(){v3.Frame}))", v5.Height.ToString ());
 #endif
 
-                       Assert.Equal (78, v5.Frame.Width);   // 97-9=78
+                       Assert.Equal (78, v5.Frame.Width); // 97-9=78
                        Assert.Equal (170, v5.Frame.Height); // 189-19=170
 
                        v6.Text = "Button6";
-                       Assert.Equal (19, v6.Frame.Width);  // 99*20%=19
+                       Assert.Equal (19, v6.Frame.Width); // 99*20%=19
                        Assert.Equal (38, v6.Frame.Height); // 198-7*20=18
                    };
 
         Application.Iteration += (s, a) => Application.RequestStop ();
 
         Application.Run (t);
+        t.Dispose ();
     }
 
     // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
@@ -457,8 +456,8 @@ public class DimTests
 
         var view = new View
         {
-            Width = Dim.Width (super), // this is allowed
-            Height = Dim.Height (super), // this is allowed
+            Width = Width (super), // this is allowed
+            Height = Height (super), // this is allowed
             Text = "view"
         };
 
@@ -476,39 +475,39 @@ public class DimTests
     {
         var n1 = 0;
         var n2 = 0;
-        Dim dim1 = Dim.Absolute (n1);
-        Dim dim2 = Dim.Absolute (n2);
+        Dim dim1 = Absolute (n1);
+        Dim dim2 = Absolute (n2);
         Assert.Equal (dim1, dim2);
 
         n1 = n2 = 1;
-        dim1 = Dim.Absolute (n1);
-        dim2 = Dim.Absolute (n2);
+        dim1 = Absolute (n1);
+        dim2 = Absolute (n2);
         Assert.Equal (dim1, dim2);
 
         n1 = n2 = -1;
-        dim1 = Dim.Absolute (n1);
-        dim2 = Dim.Absolute (n2);
+        dim1 = Absolute (n1);
+        dim2 = Absolute (n2);
         Assert.Equal (dim1, dim2);
 
         n1 = 0;
         n2 = 1;
-        dim1 = Dim.Absolute (n1);
-        dim2 = Dim.Absolute (n2);
+        dim1 = Absolute (n1);
+        dim2 = Absolute (n2);
         Assert.NotEqual (dim1, dim2);
     }
 
     [Fact]
     public void DimSized_SetsValue ()
     {
-        Dim dim = Dim.Absolute (0);
+        Dim dim = Absolute (0);
         Assert.Equal ("Absolute(0)", dim.ToString ());
 
         var testVal = 5;
-        dim = Dim.Absolute (testVal);
+        dim = Absolute (testVal);
         Assert.Equal ($"Absolute({testVal})", dim.ToString ());
 
         testVal = -1;
-        dim = Dim.Absolute (testVal);
+        dim = Absolute (testVal);
         Assert.Equal ($"Absolute({testVal})", dim.ToString ());
     }
 
@@ -523,8 +522,8 @@ public class DimTests
 
         var view = new View
         {
-            Width = Dim.Width (view2), // this is not allowed
-            Height = Dim.Height (view2), // this is not allowed
+            Width = Width (view2), // this is not allowed
+            Height = Height (view2), // this is not allowed
             Text = "view"
         };
 
@@ -570,39 +569,39 @@ public class DimTests
         var testRect2 = Rectangle.Empty;
         var view2 = new View { Frame = testRect2 };
 
-        Dim dim1 = Dim.Width (view1);
-        Dim dim2 = Dim.Width (view1);
+        Dim dim1 = Width (view1);
+        Dim dim2 = Width (view1);
 
         // FIXED: Dim.Width should support Equals() and this should change to Equal.
         Assert.Equal (dim1, dim2);
 
-        dim2 = Dim.Width (view2);
+        dim2 = Width (view2);
         Assert.NotEqual (dim1, dim2);
 
-        testRect1 = new Rectangle (0, 1, 2, 3);
-        view1 = new View { Frame = testRect1 };
-        testRect2 = new Rectangle (0, 1, 2, 3);
-        dim1 = Dim.Width (view1);
-        dim2 = Dim.Width (view1);
+        testRect1 = new (0, 1, 2, 3);
+        view1 = new() { Frame = testRect1 };
+        testRect2 = new (0, 1, 2, 3);
+        dim1 = Width (view1);
+        dim2 = Width (view1);
 
         // FIXED: Dim.Width should support Equals() and this should change to Equal.
         Assert.Equal (dim1, dim2);
 
-        testRect1 = new Rectangle (0, -1, 2, 3);
-        view1 = new View { Frame = testRect1 };
-        testRect2 = new Rectangle (0, -1, 2, 3);
-        dim1 = Dim.Width (view1);
-        dim2 = Dim.Width (view1);
+        testRect1 = new (0, -1, 2, 3);
+        view1 = new() { Frame = testRect1 };
+        testRect2 = new (0, -1, 2, 3);
+        dim1 = Width (view1);
+        dim2 = Width (view1);
 
         // FIXED: Dim.Width should support Equals() and this should change to Equal.
         Assert.Equal (dim1, dim2);
 
-        testRect1 = new Rectangle (0, -1, 2, 3);
-        view1 = new View { Frame = testRect1 };
+        testRect1 = new (0, -1, 2, 3);
+        view1 = new() { Frame = testRect1 };
         testRect2 = Rectangle.Empty;
-        view2 = new View { Frame = testRect2 };
-        dim1 = Dim.Width (view1);
-        dim2 = Dim.Width (view2);
+        view2 = new() { Frame = testRect2 };
+        dim1 = Width (view1);
+        dim2 = Width (view2);
         Assert.NotEqual (dim1, dim2);
 #if DEBUG_IDISPOSABLE
 
@@ -615,7 +614,7 @@ public class DimTests
     [Fact]
     public void DimWidth_Set_To_Null_Throws ()
     {
-        Dim dim = Dim.Width (null);
+        Dim dim = Width (null);
         Assert.Throws<NullReferenceException> (() => dim.ToString ());
     }
 
@@ -625,13 +624,13 @@ public class DimTests
     {
         var testVal = Rectangle.Empty;
         var testValView = new View { Frame = testVal };
-        Dim dim = Dim.Width (testValView);
+        Dim dim = Width (testValView);
         Assert.Equal ($"View(Width,View(){testVal})", dim.ToString ());
         testValView.Dispose ();
 
-        testVal = new Rectangle (1, 2, 3, 4);
-        testValView = new View { Frame = testVal };
-        dim = Dim.Width (testValView);
+        testVal = new (1, 2, 3, 4);
+        testValView = new() { Frame = testVal };
+        dim = Width (testValView);
         Assert.Equal ($"View(Width,View(){testVal})", dim.ToString ());
         testValView.Dispose ();
     }

+ 2 - 0
UnitTests/View/Layout/Pos.AnchorEndTests.cs

@@ -260,6 +260,7 @@ public class PosAnchorEndTests (ITestOutputHelper output)
         Assert.Equal (new (0, 0, 80, 25), win.Frame);
         Assert.Equal (new (68, 22, 10, 1), tv.Frame);
         Application.End (rs);
+        top.Dispose ();
     }
 
     // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
@@ -293,6 +294,7 @@ public class PosAnchorEndTests (ITestOutputHelper output)
         Assert.Equal (new (68, 20, 10, 1), tv.Frame);
 
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]

+ 24 - 24
UnitTests/View/Layout/Pos.CenterTests.cs

@@ -1,5 +1,4 @@
-using Microsoft.VisualStudio.TestPlatform.Utilities;
-using Xunit.Abstractions;
+using Xunit.Abstractions;
 using static Terminal.Gui.Dim;
 using static Terminal.Gui.Pos;
 
@@ -16,7 +15,6 @@ public class PosCenterTests (ITestOutputHelper output)
         Assert.NotNull (posCenter);
     }
 
-
     [Fact]
     public void PosCenter_Equals ()
     {
@@ -27,7 +25,6 @@ public class PosCenterTests (ITestOutputHelper output)
         Assert.False (posCenter2.Equals (posCenter1));
     }
 
-
     [Fact]
     public void PosCenter_ToString ()
     {
@@ -42,7 +39,7 @@ public class PosCenterTests (ITestOutputHelper output)
     {
         var posCenter = new PosCenter ();
         var width = 50;
-        var expectedAnchor = width / 2;
+        int expectedAnchor = width / 2;
 
         Assert.Equal (expectedAnchor, posCenter.GetAnchor (width));
     }
@@ -50,16 +47,15 @@ public class PosCenterTests (ITestOutputHelper output)
     [Fact]
     public void PosCenter_CreatesCorrectInstance ()
     {
-        var pos = Pos.Center ();
+        Pos pos = Center ();
         Assert.IsType<PosCenter> (pos);
     }
 
-
     [Fact]
     public void PosCenter_Calculate_ReturnsExpectedValue ()
     {
         var posCenter = new PosCenter ();
-        var result = posCenter.Calculate (10, new DimAbsolute (2), null, Dimension.None);
+        int result = posCenter.Calculate (10, new DimAbsolute (2), null, Dimension.None);
         Assert.Equal (4, result);
     }
 
@@ -77,11 +73,11 @@ public class PosCenterTests (ITestOutputHelper output)
     [InlineData (10)]
     public void PosCenter_SubView_85_Percent_Height (int height)
     {
-        var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
+        var win = new Window { Width = Fill (), Height = Fill () };
 
         var subview = new Window
         {
-            X = Pos.Center (), Y = Pos.Center (), Width = Dim.Percent (85), Height = Dim.Percent (85)
+            X = Center (), Y = Center (), Width = Dim.Percent (85), Height = Dim.Percent (85)
         };
 
         win.Add (subview);
@@ -200,12 +196,14 @@ public class PosCenterTests (ITestOutputHelper output)
 │ └─────────────┘  │
 │                  │
 └──────────────────┘"
-                ;
+                    ;
+
                 break;
         }
 
         _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
         Application.End (rs);
+        win.Dispose ();
     }
 
     [Theory]
@@ -222,11 +220,11 @@ public class PosCenterTests (ITestOutputHelper output)
     [InlineData (10)]
     public void PosCenter_SubView_85_Percent_Width (int width)
     {
-        var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
+        var win = new Window { Width = Fill (), Height = Fill () };
 
         var subview = new Window
         {
-            X = Pos.Center (), Y = Pos.Center (), Width = Dim.Percent (85), Height = Dim.Percent (85)
+            X = Center (), Y = Center (), Width = Dim.Percent (85), Height = Dim.Percent (85)
         };
 
         win.Add (subview);
@@ -241,7 +239,7 @@ public class PosCenterTests (ITestOutputHelper output)
         switch (width)
         {
             case 1:
-                Assert.Equal (new Rectangle (0, 0, 0, 4), subview.Frame);
+                Assert.Equal (new (0, 0, 0, 4), subview.Frame);
 
                 expected = @"
@@ -254,7 +252,7 @@ public class PosCenterTests (ITestOutputHelper output)
 
                 break;
             case 2:
-                Assert.Equal (new Rectangle (0, 0, 0, 4), subview.Frame);
+                Assert.Equal (new (0, 0, 0, 4), subview.Frame);
 
                 expected = @"
 ┌┐
@@ -267,7 +265,7 @@ public class PosCenterTests (ITestOutputHelper output)
 
                 break;
             case 3:
-                Assert.Equal (new Rectangle (0, 0, 0, 4), subview.Frame);
+                Assert.Equal (new (0, 0, 0, 4), subview.Frame);
 
                 expected = @"
 ┌─┐
@@ -280,7 +278,7 @@ public class PosCenterTests (ITestOutputHelper output)
 
                 break;
             case 4:
-                Assert.Equal (new Rectangle (0, 0, 1, 4), subview.Frame);
+                Assert.Equal (new (0, 0, 1, 4), subview.Frame);
 
                 expected = @"
 ┌──┐
@@ -293,7 +291,7 @@ public class PosCenterTests (ITestOutputHelper output)
 
                 break;
             case 5:
-                Assert.Equal (new Rectangle (0, 0, 2, 4), subview.Frame);
+                Assert.Equal (new (0, 0, 2, 4), subview.Frame);
 
                 expected = @"
 ┌───┐
@@ -306,7 +304,7 @@ public class PosCenterTests (ITestOutputHelper output)
 
                 break;
             case 6:
-                Assert.Equal (new Rectangle (0, 0, 3, 4), subview.Frame);
+                Assert.Equal (new (0, 0, 3, 4), subview.Frame);
 
                 expected = @"
 ┌────┐
@@ -319,7 +317,7 @@ public class PosCenterTests (ITestOutputHelper output)
 
                 break;
             case 7:
-                Assert.Equal (new Rectangle (0, 0, 4, 4), subview.Frame);
+                Assert.Equal (new (0, 0, 4, 4), subview.Frame);
 
                 expected = @"
 ┌─────┐
@@ -332,7 +330,7 @@ public class PosCenterTests (ITestOutputHelper output)
 
                 break;
             case 8:
-                Assert.Equal (new Rectangle (0, 0, 5, 4), subview.Frame);
+                Assert.Equal (new (0, 0, 5, 4), subview.Frame);
 
                 expected = @"
 ┌──────┐
@@ -345,7 +343,7 @@ public class PosCenterTests (ITestOutputHelper output)
 
                 break;
             case 9:
-                Assert.Equal (new Rectangle (1, 0, 5, 4), subview.Frame);
+                Assert.Equal (new (1, 0, 5, 4), subview.Frame);
 
                 expected = @"
 ┌───────┐
@@ -358,7 +356,7 @@ public class PosCenterTests (ITestOutputHelper output)
 
                 break;
             case 10:
-                Assert.Equal (new Rectangle (1, 0, 6, 4), subview.Frame);
+                Assert.Equal (new (1, 0, 6, 4), subview.Frame);
 
                 expected = @"
 ┌────────┐
@@ -368,11 +366,13 @@ public class PosCenterTests (ITestOutputHelper output)
 │ └────┘ │
 │        │
 └────────┘"
-                ;
+                    ;
+
                 break;
         }
 
         _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
         Application.End (rs);
+        win.Dispose ();
     }
 }

+ 3 - 2
UnitTests/View/Layout/Pos.CombineTests.cs

@@ -66,7 +66,6 @@ public class PosCombineTests (ITestOutputHelper output)
     [SetupFakeDriver]
     public void PosCombine_DimCombine_View_With_SubViews ()
     {
-        var clicked = false;
         Toplevel top = new Toplevel () { Width = 80, Height = 25 };
         var win1 = new Window { Id = "win1", Width = 20, Height = 10 };
         var view1 = new View
@@ -78,7 +77,9 @@ public class PosCombineTests (ITestOutputHelper output)
         };
         var win2 = new Window { Id = "win2", Y = Pos.Bottom (view1) + 1, Width = 10, Height = 3 };
         var view2 = new View { Id = "view2", Width = Dim.Fill (), Height = 1, CanFocus = true };
-        view2.MouseClick += (sender, e) => clicked = true;
+
+        //var clicked = false;
+        //view2.MouseClick += (sender, e) => clicked = true;
         var view3 = new View { Id = "view3", Width = Dim.Fill (1), Height = 1, CanFocus = true };
 
         view2.Add (view3);

+ 12 - 13
UnitTests/View/Layout/Pos.PercentTests.cs

@@ -1,6 +1,4 @@
-using Microsoft.VisualStudio.TestPlatform.Utilities;
-using Xunit.Abstractions;
-using static Terminal.Gui.Dim;
+using Xunit.Abstractions;
 using static Terminal.Gui.Pos;
 
 namespace Terminal.Gui.LayoutTests;
@@ -12,7 +10,6 @@ public class PosPercentTests (ITestOutputHelper output)
     // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
     // TODO: A new test that calls SetRelativeLayout directly is needed.
     [Theory]
-    [AutoInitShutdown]
     [InlineData (true)]
     [InlineData (false)]
     public void PosPercent_PlusOne (bool testHorizontal)
@@ -21,8 +18,8 @@ public class PosPercentTests (ITestOutputHelper output)
 
         var view = new View
         {
-            X = testHorizontal ? Pos.Percent (50) + Pos.Percent (10) + 1 : 1,
-            Y = testHorizontal ? 1 : Pos.Percent (50) + Pos.Percent (10) + 1,
+            X = testHorizontal ? Percent (50) + Percent (10) + 1 : 1,
+            Y = testHorizontal ? 1 : Percent (50) + Percent (10) + 1,
             Width = 10,
             Height = 10
         };
@@ -45,29 +42,31 @@ public class PosPercentTests (ITestOutputHelper output)
             Assert.Equal (1, view.Frame.X);
             Assert.Equal (61, view.Frame.Y);
         }
+
+        top.Dispose ();
     }
 
     [Fact]
     public void PosPercent_SetsValue ()
     {
-        int f = 0;
-        Pos pos = Pos.Percent (f);
+        var f = 0;
+        Pos pos = Percent (f);
         Assert.Equal ($"Percent({f})", pos.ToString ());
         f = 50;
-        pos = Pos.Percent (f);
+        pos = Percent (f);
         Assert.Equal ($"Percent({f})", pos.ToString ());
         f = 100;
-        pos = Pos.Percent (f);
+        pos = Percent (f);
         Assert.Equal ($"Percent({f})", pos.ToString ());
     }
 
     [Fact]
     public void PosPercent_ThrowsOnIvalid ()
     {
-        Pos pos = Pos.Percent (0);
-        Assert.Throws<ArgumentException> (() => pos = Pos.Percent (-1));
+        Pos pos = Percent (0);
+        Assert.Throws<ArgumentException> (() => pos = Percent (-1));
+
         //Assert.Throws<ArgumentException> (() => pos = Pos.Percent (101));
         //Assert.Throws<ArgumentException> (() => pos = Pos.Percent (1000001));
     }
-
 }

+ 1 - 0
UnitTests/View/MouseTests.cs

@@ -78,6 +78,7 @@ public class MouseTests (ITestOutputHelper output) : TestsAllViews
         Application.OnMouseEvent (new () { Position = new (xy + 1, xy + 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition });
 
         Assert.Equal (expectedMoved, new Point (5, 5) == testView.Frame.Location);
+        top.Dispose ();
     }
 
     [Theory]

+ 17 - 12
UnitTests/View/NavigationTests.cs

@@ -1,15 +1,9 @@
 using Xunit.Abstractions;
 
-// Alias Console to MockConsole so we don't accidentally use Console
-using Console = Terminal.Gui.FakeConsole;
-
 namespace Terminal.Gui.ViewTests;
 
-public class NavigationTests
+public class NavigationTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public NavigationTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     public void BringSubviewForward_Subviews_vs_TabIndexes ()
     {
@@ -308,6 +302,7 @@ public class NavigationTests
         Assert.False (view.HasFocus);
         Assert.Null (Application.Current.Focused);
         Assert.Null (Application.Current.MostFocused);
+        top.Dispose ();
     }
 
     [Fact]
@@ -348,6 +343,7 @@ public class NavigationTests
         Assert.True (view2.HasFocus);
         Assert.Equal (win2, Application.Current.Focused);
         Assert.Equal (view2, Application.Current.MostFocused);
+        top.Dispose ();
     }
 
     [Fact]
@@ -390,6 +386,7 @@ public class NavigationTests
         Assert.True (view2.HasFocus);
         Assert.Equal (win2, Application.Current.Focused);
         Assert.Equal (view2, Application.Current.MostFocused);
+        top.Dispose ();
     }
 
     [Fact]
@@ -440,10 +437,10 @@ public class NavigationTests
         Assert.False (view2.HasFocus);
         Assert.Equal (win1, Application.Current.Focused);
         Assert.Equal (view12, Application.Current.MostFocused);
+        top.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void Enabled_False_Sets_HasFocus_To_False ()
     {
         var wasClicked = false;
@@ -529,6 +526,7 @@ public class NavigationTests
         Application.Run (top);
 
         Assert.Equal (1, iterations);
+        top.Dispose ();
     }
 
     [Fact]
@@ -619,6 +617,7 @@ public class NavigationTests
         Assert.Null (exception);
         Assert.True (removed);
         Assert.Null (view3);
+        top1.Dispose ();
     }
 
     [Fact]
@@ -694,6 +693,7 @@ public class NavigationTests
 // This test is now invalid because `win` is focused, so it will receive the keypress
         Assert.True (topQuiting);
 #endif
+        top.Dispose ();
     }
 
     [Fact]
@@ -745,9 +745,11 @@ public class NavigationTests
         Assert.True (sbQuiting);
         Assert.False (tfQuiting);
 #endif
+        top.Dispose ();
     }
 
     [Fact]
+    [SetupFakeDriver]
     public void Navigation_With_Null_Focused_View ()
     {
         // Non-regression test for #882 (NullReferenceException during keyboard navigation when Focused is null)
@@ -758,7 +760,7 @@ public class NavigationTests
         top.Ready += (s, e) => { Assert.Null (top.Focused); };
 
         // Keyboard navigation with tab
-        Console.MockKeyPresses.Push (new ConsoleKeyInfo ('\t', ConsoleKey.Tab, false, false, false));
+        FakeConsole.MockKeyPresses.Push (new ConsoleKeyInfo ('\t', ConsoleKey.Tab, false, false, false));
 
         Application.Iteration += (s, a) => Application.RequestStop ();
 
@@ -805,6 +807,7 @@ public class NavigationTests
         Assert.True (container.HasFocus);
         Assert.Null (child);
         Assert.False (leave);
+        top.Dispose ();
     }
 
     [Fact]
@@ -847,7 +850,7 @@ public class NavigationTests
 │                  │
 │                  │
 └──────────────────┘",
-                                                          _output
+                                                          output
                                                          );
 
         // top
@@ -948,6 +951,7 @@ public class NavigationTests
         Assert.Equal (4, screen.Y);
         found = View.FindDeepestView (top, new (15, 4));
         Assert.Equal (top, found);
+        top.Dispose ();
     }
 
     [Fact]
@@ -997,7 +1001,7 @@ public class NavigationTests
    │                  │
    │                  │
    └──────────────────┘",
-                                                                   _output
+                                                                   output
                                                                   );
 
         // mean the output started at col 3 and line 2
@@ -1083,6 +1087,7 @@ public class NavigationTests
         Assert.Equal (24, screen.X);
         Assert.Equal (4, screen.Y);
         Assert.Null (View.FindDeepestView (top, new (24, 4)));
+        top.Dispose ();
     }
 
     [Fact]
@@ -1128,7 +1133,6 @@ public class NavigationTests
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void SetFocus_View_With_Null_Superview_Does_Not_Throw_Exception ()
     {
         var top = new Toplevel ();
@@ -1177,6 +1181,7 @@ public class NavigationTests
         Assert.False (subView1subView1Leave);
         Application.End (rs);
         subView1subView1.Dispose ();
+        top.Dispose ();
     }
 
     [Fact]

+ 14 - 6
UnitTests/View/TextTests.cs

@@ -10,8 +10,6 @@ namespace Terminal.Gui.ViewTests;
 /// </summary>
 public class TextTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output = output;
-
     // TextFormatter.Size should be empty unless DimAuto is set or ContentSize is set
     [Theory]
     [InlineData ("", 0, 0)]
@@ -32,7 +30,7 @@ public class TextTests (ITestOutputHelper output)
     public void TextFormatter_Size_Tracks_ContentSize (string text, int expectedW, int expectedH)
     {
         var view = new View ();
-        view.SetContentSize (new (1,1));
+        view.SetContentSize (new (1, 1));
         view.Text = text;
         Assert.Equal (new (expectedW, expectedH), view.TextFormatter.Size);
     }
@@ -135,6 +133,7 @@ Y
 
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
@@ -394,6 +393,7 @@ Y
 
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
@@ -422,7 +422,7 @@ Y
 
         Assert.Equal (new (0, 0, 1, 5), view.Frame);
         Assert.Equal (new (1, 5), view.TextFormatter.Size);
-        Assert.Equal (new() { "Views" }, view.TextFormatter.GetLines ());
+        Assert.Equal (new () { "Views" }, view.TextFormatter.GetLines ());
         Assert.Equal (new (0, 0, 4, 10), win.Frame);
         Assert.Equal (new (0, 0, 4, 10), Application.Top.Frame);
 
@@ -468,6 +468,7 @@ Y
 
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 4, 10), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -493,7 +494,7 @@ Y
         Assert.Equal (5, text.Length);
         Assert.Equal (new (0, 0, 2, 5), view.Frame);
         Assert.Equal (new (2, 5), view.TextFormatter.Size);
-        Assert.Equal (new() { "界View" }, view.TextFormatter.GetLines ());
+        Assert.Equal (new () { "界View" }, view.TextFormatter.GetLines ());
         Assert.Equal (new (0, 0, 4, 10), win.Frame);
         Assert.Equal (new (0, 0, 4, 10), Application.Top.Frame);
 
@@ -524,7 +525,7 @@ Y
 
         Exception exception = Record.Exception (
                                                 () => Assert.Equal (
-                                                                    new() { "界View" },
+                                                                    new () { "界View" },
                                                                     view.TextFormatter.GetLines ()
                                                                    )
                                                );
@@ -545,6 +546,7 @@ Y
 
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 4, 10), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -641,6 +643,7 @@ Y
 
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
@@ -737,6 +740,7 @@ Y
 
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
@@ -772,6 +776,7 @@ Y
         }
 
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
@@ -820,6 +825,7 @@ Y
         Assert.Equal (new (0, 0, 2, 10), verticalView.Frame);
         Assert.Equal (new (2, 10), verticalView.GetSizeNeededForTextWithoutHotKey ());
         Assert.Equal (verticalView.Frame.Size, verticalView.GetSizeNeededForTextWithoutHotKey ());
+        top.Dispose ();
     }
 
     [Theory]
@@ -942,6 +948,7 @@ Y
 
         Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, width + 2, 6), pos);
+        top.Dispose ();
     }
 
     [Theory]
@@ -1099,6 +1106,7 @@ Y
 
         Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 9, height + 2), pos);
+        top.Dispose ();
     }
 
     // Test that View.PreserveTrailingSpaces removes trailing spaces

+ 6 - 3
UnitTests/View/ViewKeyBindingTests.cs

@@ -2,10 +2,9 @@
 
 namespace Terminal.Gui.ViewTests;
 
-public class ViewKeyBindingTests
+public class ViewKeyBindingTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public ViewKeyBindingTests (ITestOutputHelper output) { _output = output; }
+    private readonly ITestOutputHelper _output = output;
 
     [Fact]
     [AutoInitShutdown]
@@ -42,6 +41,7 @@ public class ViewKeyBindingTests
         Assert.True (view.ApplicationCommand);
         Assert.True (view.HotKeyCommand);
         Assert.True (view.FocusedCommand);
+        top.Dispose ();
     }
 
     [Fact]
@@ -69,6 +69,7 @@ public class ViewKeyBindingTests
         Assert.False (view.ApplicationCommand);
         Assert.False (view.HotKeyCommand);
         Assert.False (view.FocusedCommand);
+        top.Dispose ();
     }
 
     [Fact]
@@ -98,6 +99,7 @@ public class ViewKeyBindingTests
         Application.OnKeyDown (Key.Z); // new hot key
         Assert.True (invoked);
         Assert.True (view.HotKeyCommand);
+        top.Dispose ();
     }
 
     [Fact]
@@ -119,6 +121,7 @@ public class ViewKeyBindingTests
         invoked = false;
         Application.OnKeyDown (Key.F);
         Assert.False (view.HotKeyCommand);
+        top.Dispose ();
     }
 
     // tests that test KeyBindingScope.Focus and KeyBindingScope.HotKey (tests for KeyBindingScope.Application are in Application/KeyboardTests.cs)

+ 118 - 107
UnitTests/View/ViewTests.cs

@@ -4,11 +4,8 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewTests;
 
-public class ViewTests
+public class ViewTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public ViewTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     [AutoInitShutdown]
     public void Clear_Viewport_Can_Use_Driver_AddRune_Or_AddStr_Methods ()
@@ -18,7 +15,7 @@ public class ViewTests
         view.DrawContent += (s, e) =>
                             {
                                 Rectangle savedClip = Application.Driver.Clip;
-                                Application.Driver.Clip = new Rectangle (1, 1, view.Viewport.Width, view.Viewport.Height);
+                                Application.Driver.Clip = new (1, 1, view.Viewport.Width, view.Viewport.Height);
 
                                 for (var row = 0; row < view.Viewport.Height; row++)
                                 {
@@ -51,8 +48,8 @@ public class ViewTests
 └──────────────────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (0, 0, 20, 10), pos);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (0, 0, 20, 10), pos);
 
         view.FillRect (view.Viewport);
 
@@ -69,7 +66,7 @@ public class ViewTests
 └──────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         top.Dispose ();
     }
 
@@ -82,7 +79,7 @@ public class ViewTests
         view.DrawContent += (s, e) =>
                             {
                                 Rectangle savedClip = Application.Driver.Clip;
-                                Application.Driver.Clip = new Rectangle (1, 1, view.Viewport.Width, view.Viewport.Height);
+                                Application.Driver.Clip = new (1, 1, view.Viewport.Width, view.Viewport.Height);
 
                                 for (var row = 0; row < view.Viewport.Height; row++)
                                 {
@@ -115,8 +112,8 @@ public class ViewTests
 └──────────────────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (0, 0, 20, 10), pos);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (0, 0, 20, 10), pos);
 
         view.FillRect (view.Viewport);
 
@@ -133,7 +130,7 @@ public class ViewTests
 └──────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
 
         top.Dispose ();
     }
@@ -147,8 +144,8 @@ public class ViewTests
         var root = new View { Width = 20, Height = 10, ColorScheme = Colors.ColorSchemes ["Base"] };
 
         View v = label
-                     ? new Label { Text = new string ('c', 100) }
-                     : new TextView { Height = 1, Text = new string ('c', 100), Width = Dim.Fill () };
+                     ? new Label { Text = new ('c', 100) }
+                     : new TextView { Height = 1, Text = new ('c', 100), Width = Dim.Fill () };
 
         root.Add (v);
 
@@ -159,18 +156,19 @@ public class ViewTests
         if (label)
         {
             Assert.False (v.CanFocus);
+
             //Assert.Equal (new Rectangle (0, 0, 20, 1), v.Frame);
         }
         else
         {
             Assert.True (v.CanFocus);
-            Assert.Equal (new Rectangle (0, 0, 20, 1), v.Frame);
+            Assert.Equal (new (0, 0, 20, 1), v.Frame);
         }
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 cccccccccccccccccccc",
-                                                      _output
+                                                      output
                                                      );
 
         Attribute [] attributes =
@@ -220,6 +218,7 @@ cccccccccccccccccccc",
         }
 
         Application.End (runState);
+        top.Dispose ();
     }
 
     [Fact]
@@ -246,13 +245,13 @@ At 0,0
                              
   A text with some long width
    and also with two lines.  ",
-                                                      _output
+                                                      output
                                                      );
 
-        view.Frame = new Rectangle (3, 3, 10, 1);
-        Assert.Equal (new Rectangle (3, 3, 10, 1), view.Frame);
-        Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
-        Assert.Equal (new Rectangle (0, 0, 10, 1), view._needsDisplayRect);
+        view.Frame = new (3, 3, 10, 1);
+        Assert.Equal (new (3, 3, 10, 1), view.Frame);
+        Assert.Equal (new (0, 0, 10, 1), view.Viewport);
+        Assert.Equal (new (0, 0, 10, 1), view._needsDisplayRect);
         top.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -261,9 +260,10 @@ At 0,0
              
              
    A text wit",
-                                                      _output
+                                                      output
                                                      );
         Application.End (runState);
+        top.Dispose ();
     }
 
     [Fact]
@@ -292,16 +292,16 @@ At 0,0
                              
   A text with some long width
    and also with two lines.  ",
-                                                      _output
+                                                      output
                                                      );
 
         view.X = 3;
         view.Y = 3;
         view.Width = 10;
         view.Height = 1;
-        Assert.Equal (new Rectangle (3, 3, 10, 1), view.Frame);
-        Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
-        Assert.Equal (new Rectangle (0, 0, 30, 2), view._needsDisplayRect);
+        Assert.Equal (new (3, 3, 10, 1), view.Frame);
+        Assert.Equal (new (0, 0, 10, 1), view.Viewport);
+        Assert.Equal (new (0, 0, 30, 2), view._needsDisplayRect);
         top.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -310,9 +310,10 @@ At 0,0
              
              
    A text wit",
-                                                      _output
+                                                      output
                                                      );
         Application.End (runState);
+        top.Dispose ();
     }
 
     [Fact]
@@ -341,22 +342,23 @@ At 0,0
                              
   A text with some long width
    and also with two lines.  ",
-                                                      _output
+                                                      output
                                                      );
 
-        view.Frame = new Rectangle (1, 1, 10, 1);
-        Assert.Equal (new Rectangle (1, 1, 10, 1), view.Frame);
-        Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
-        Assert.Equal (new Rectangle (0, 0, 10, 1), view._needsDisplayRect);
+        view.Frame = new (1, 1, 10, 1);
+        Assert.Equal (new (1, 1, 10, 1), view.Frame);
+        Assert.Equal (new (0, 0, 10, 1), view.Viewport);
+        Assert.Equal (new (0, 0, 10, 1), view._needsDisplayRect);
         top.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 At 0,0     
  A text wit",
-                                                      _output
+                                                      output
                                                      );
         Application.End (runState);
+        top.Dispose ();
     }
 
     [Fact]
@@ -385,25 +387,26 @@ At 0,0
                              
   A text with some long width
    and also with two lines.  ",
-                                                      _output
+                                                      output
                                                      );
 
         view.X = 1;
         view.Y = 1;
         view.Width = 10;
         view.Height = 1;
-        Assert.Equal (new Rectangle (1, 1, 10, 1), view.Frame);
-        Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
-        Assert.Equal (new Rectangle (0, 0, 30, 2), view._needsDisplayRect);
+        Assert.Equal (new (1, 1, 10, 1), view.Frame);
+        Assert.Equal (new (0, 0, 10, 1), view.Viewport);
+        Assert.Equal (new (0, 0, 30, 2), view._needsDisplayRect);
         top.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 At 0,0     
  A text wit",
-                                                      _output
+                                                      output
                                                      );
         Application.End (runState);
+        top.Dispose ();
     }
 
     [Fact]
@@ -443,6 +446,7 @@ At 0,0
 
         Assert.True (viewCalled);
         Assert.True (tvCalled);
+        top.Dispose ();
     }
 
     [Fact]
@@ -476,33 +480,33 @@ At 0,0
 
         RunState runState = Application.Begin (top);
 
-        top.LayoutComplete += (s, e) => { Assert.Equal (new Rectangle (0, 0, 80, 25), top._needsDisplayRect); };
+        top.LayoutComplete += (s, e) => { Assert.Equal (new (0, 0, 80, 25), top._needsDisplayRect); };
 
-        frame.LayoutComplete += (s, e) => { Assert.Equal (new Rectangle (0, 0, 40, 8), frame._needsDisplayRect); };
+        frame.LayoutComplete += (s, e) => { Assert.Equal (new (0, 0, 40, 8), frame._needsDisplayRect); };
 
-        label.LayoutComplete += (s, e) => { Assert.Equal (new Rectangle (0, 0, 38, 1), label._needsDisplayRect); };
+        label.LayoutComplete += (s, e) => { Assert.Equal (new (0, 0, 38, 1), label._needsDisplayRect); };
 
-        button.LayoutComplete += (s, e) => { Assert.Equal (new Rectangle (0, 0, 13, 1), button._needsDisplayRect); };
+        button.LayoutComplete += (s, e) => { Assert.Equal (new (0, 0, 13, 1), button._needsDisplayRect); };
 
-        Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame);
-        Assert.Equal (new Rectangle (20, 8, 40, 8), frame.Frame);
+        Assert.Equal (new (0, 0, 80, 25), top.Frame);
+        Assert.Equal (new (20, 8, 40, 8), frame.Frame);
 
         Assert.Equal (
-                      new Rectangle (20, 8, 60, 16),
+                      new (20, 8, 60, 16),
                       new Rectangle (
-                                frame.Frame.Left,
-                                frame.Frame.Top,
-                                frame.Frame.Right,
-                                frame.Frame.Bottom
-                               )
+                                     frame.Frame.Left,
+                                     frame.Frame.Top,
+                                     frame.Frame.Right,
+                                     frame.Frame.Bottom
+                                    )
                      );
-        Assert.Equal (new Rectangle (0, 0, 30, 1), label.Frame);
-        Assert.Equal (new Rectangle (0, 1, 13, 1), button.Frame); // this proves frame was set
+        Assert.Equal (new (0, 0, 30, 1), label.Frame);
+        Assert.Equal (new (0, 1, 13, 1), button.Frame); // this proves frame was set
         Application.End (runState);
+        top.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void GetHotNormalColor_ColorScheme ()
     {
         var view = new View { ColorScheme = Colors.ColorSchemes ["Base"] };
@@ -515,7 +519,6 @@ At 0,0
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void GetNormalColor_ColorScheme ()
     {
         var view = new View { ColorScheme = Colors.ColorSchemes ["Base"] };
@@ -553,12 +556,12 @@ At 0,0
                              
   A text with some long width
    and also with two lines.  ",
-                                                      _output
+                                                      output
                                                      );
 
-        view.Frame = new Rectangle (3, 3, 10, 1);
-        Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
-        Assert.Equal (new Rectangle (0, 0, 10, 1), view._needsDisplayRect);
+        view.Frame = new (3, 3, 10, 1);
+        Assert.Equal (new (0, 0, 10, 1), view.Viewport);
+        Assert.Equal (new (0, 0, 10, 1), view._needsDisplayRect);
         view.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -567,9 +570,10 @@ At 0,0
                              
   A text with some long width
    A text witith two lines.  ",
-                                                      _output
+                                                      output
                                                      );
         Application.End (runState);
+        top.Dispose ();
     }
 
     [Fact]
@@ -598,16 +602,16 @@ At 0,0
                              
   A text with some long width
    and also with two lines.  ",
-                                                      _output
+                                                      output
                                                      );
 
         view.X = 3;
         view.Y = 3;
         view.Width = 10;
         view.Height = 1;
-        Assert.Equal (new Rectangle (3, 3, 10, 1), view.Frame);
-        Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
-        Assert.Equal (new Rectangle (0, 0, 30, 2), view._needsDisplayRect);
+        Assert.Equal (new (3, 3, 10, 1), view.Frame);
+        Assert.Equal (new (0, 0, 10, 1), view.Viewport);
+        Assert.Equal (new (0, 0, 30, 2), view._needsDisplayRect);
         view.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -616,9 +620,10 @@ At 0,0
                              
   A text with some long width
    A text witith two lines.  ",
-                                                      _output
+                                                      output
                                                      );
         Application.End (runState);
+        top.Dispose ();
     }
 
     [Fact]
@@ -647,13 +652,13 @@ At 0,0
                              
   A text with some long width
    and also with two lines.  ",
-                                                      _output
+                                                      output
                                                      );
 
-        view.Frame = new Rectangle (1, 1, 10, 1);
-        Assert.Equal (new Rectangle (1, 1, 10, 1), view.Frame);
-        Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
-        Assert.Equal (new Rectangle (0, 0, 10, 1), view._needsDisplayRect);
+        view.Frame = new (1, 1, 10, 1);
+        Assert.Equal (new (1, 1, 10, 1), view.Frame);
+        Assert.Equal (new (0, 0, 10, 1), view.Viewport);
+        Assert.Equal (new (0, 0, 10, 1), view._needsDisplayRect);
         view.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -662,9 +667,10 @@ At 0,0
  A text wit                  
   A text with some long width
    and also with two lines.  ",
-                                                      _output
+                                                      output
                                                      );
         Application.End (runState);
+        top.Dispose ();
     }
 
     [Fact]
@@ -693,16 +699,16 @@ At 0,0
                              
   A text with some long width
    and also with two lines.  ",
-                                                      _output
+                                                      output
                                                      );
 
         view.X = 1;
         view.Y = 1;
         view.Width = 10;
         view.Height = 1;
-        Assert.Equal (new Rectangle (1, 1, 10, 1), view.Frame);
-        Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
-        Assert.Equal (new Rectangle (0, 0, 30, 2), view._needsDisplayRect);
+        Assert.Equal (new (1, 1, 10, 1), view.Frame);
+        Assert.Equal (new (0, 0, 10, 1), view.Viewport);
+        Assert.Equal (new (0, 0, 30, 2), view._needsDisplayRect);
         view.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -711,9 +717,10 @@ At 0,0
  A text wit                  
   A text with some long width
    and also with two lines.  ",
-                                                      _output
+                                                      output
                                                      );
         Application.End (runState);
+        top.Dispose ();
     }
 
     [Fact]
@@ -735,7 +742,7 @@ At 0,0
         view.EndInit ();
         view.Draw ();
 
-        TestHelpers.AssertDriverContentsWithFrameAre (text, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (text, output);
     }
 
     [Fact]
@@ -751,8 +758,8 @@ At 0,0
         Assert.Equal ($"View(){r.Viewport}", r.ToString ());
         Assert.False (r.CanFocus);
         Assert.False (r.HasFocus);
-        Assert.Equal (new Rectangle (0, 0, 0, 0), r.Viewport);
-        Assert.Equal (new Rectangle (0, 0, 0, 0), r.Frame);
+        Assert.Equal (new (0, 0, 0, 0), r.Viewport);
+        Assert.Equal (new (0, 0, 0, 0), r.Frame);
         Assert.Null (r.Focused);
         Assert.Null (r.ColorScheme);
         Assert.Equal (0, r.Width);
@@ -770,13 +777,13 @@ At 0,0
         r.Dispose ();
 
         // Empty Rect
-        r = new View { Frame = Rectangle.Empty };
+        r = new() { Frame = Rectangle.Empty };
         Assert.NotNull (r);
         Assert.Equal ($"View(){r.Viewport}", r.ToString ());
         Assert.False (r.CanFocus);
         Assert.False (r.HasFocus);
-        Assert.Equal (new Rectangle (0, 0, 0, 0), r.Viewport);
-        Assert.Equal (new Rectangle (0, 0, 0, 0), r.Frame);
+        Assert.Equal (new (0, 0, 0, 0), r.Viewport);
+        Assert.Equal (new (0, 0, 0, 0), r.Frame);
         Assert.Null (r.Focused);
         Assert.Null (r.ColorScheme);
         Assert.Equal (0, r.Width);
@@ -794,13 +801,13 @@ At 0,0
         r.Dispose ();
 
         // Rect with values
-        r = new View { Frame = new Rectangle (1, 2, 3, 4) };
+        r = new() { Frame = new (1, 2, 3, 4) };
         Assert.NotNull (r);
         Assert.Equal ($"View(){r.Frame}", r.ToString ());
         Assert.False (r.CanFocus);
         Assert.False (r.HasFocus);
-        Assert.Equal (new Rectangle (0, 0, 3, 4), r.Viewport);
-        Assert.Equal (new Rectangle (1, 2, 3, 4), r.Frame);
+        Assert.Equal (new (0, 0, 3, 4), r.Viewport);
+        Assert.Equal (new (1, 2, 3, 4), r.Frame);
         Assert.Null (r.Focused);
         Assert.Null (r.ColorScheme);
         Assert.Equal (3, r.Width);
@@ -818,7 +825,7 @@ At 0,0
         r.Dispose ();
 
         // Initializes a view with a vertical direction
-        r = new View
+        r = new()
         {
             Text = "Vertical View",
             TextDirection = TextDirection.TopBottom_LeftRight,
@@ -832,8 +839,8 @@ At 0,0
         r.EndInit ();
         Assert.False (r.CanFocus);
         Assert.False (r.HasFocus);
-        Assert.Equal (new Rectangle (0, 0, 1, 13), r.Viewport);
-        Assert.Equal (new Rectangle (0, 0, 1, 13), r.Frame);
+        Assert.Equal (new (0, 0, 1, 13), r.Viewport);
+        Assert.Equal (new (0, 0, 1, 13), r.Frame);
         Assert.Null (r.Focused);
         Assert.Null (r.ColorScheme);
         Assert.False (r.IsCurrentTop);
@@ -857,13 +864,13 @@ At 0,0
     {
         var r = new View ();
 
-        Assert.False (r.OnKeyDown (new Key { KeyCode = KeyCode.Null }));
+        Assert.False (r.OnKeyDown (new() { KeyCode = KeyCode.Null }));
 
         //Assert.False (r.OnKeyDown (new KeyEventArgs () { Key = Key.Unknown }));
-        Assert.False (r.OnKeyUp (new Key { KeyCode = KeyCode.Null }));
-        Assert.False (r.NewMouseEvent (new MouseEvent { Flags = MouseFlags.AllEvents }));
-        Assert.False (r.NewMouseEnterEvent (new MouseEvent { Flags = MouseFlags.AllEvents }));
-        Assert.False (r.NewMouseLeaveEvent (new MouseEvent { Flags = MouseFlags.AllEvents }));
+        Assert.False (r.OnKeyUp (new() { KeyCode = KeyCode.Null }));
+        Assert.False (r.NewMouseEvent (new() { Flags = MouseFlags.AllEvents }));
+        Assert.False (r.NewMouseEnterEvent (new() { Flags = MouseFlags.AllEvents }));
+        Assert.False (r.NewMouseLeaveEvent (new() { Flags = MouseFlags.AllEvents }));
 
         var v1 = new View ();
         Assert.False (r.OnEnter (v1));
@@ -882,7 +889,7 @@ At 0,0
     [AutoInitShutdown]
     public void Test_Nested_Views_With_Height_Equal_To_One ()
     {
-        var v = new View { Width = 11, Height = 3, ColorScheme = new ColorScheme () };
+        var v = new View { Width = 11, Height = 3, ColorScheme = new () };
 
         var top = new View { Width = Dim.Fill (), Height = 1 };
         var bottom = new View { Width = Dim.Fill (), Height = 1, Y = 2 };
@@ -903,7 +910,7 @@ At 0,0
 111
 ───────────
 222";
-        TestHelpers.AssertDriverContentsAre (looksLike, _output);
+        TestHelpers.AssertDriverContentsAre (looksLike, output);
         v.Dispose ();
         top.Dispose ();
         bottom.Dispose ();
@@ -917,7 +924,7 @@ At 0,0
         var view = new View { X = 1, Y = 2, Width = 3, Height = 4 };
 
         // Object Initializer Absolute
-        var super = new View { Frame = new Rectangle (0, 0, 10, 10) };
+        var super = new View { Frame = new (0, 0, 10, 10) };
         super.Add (view);
         super.BeginInit ();
         super.EndInit ();
@@ -928,9 +935,9 @@ At 0,0
         Assert.Equal (3, view.Width);
         Assert.Equal (4, view.Height);
         Assert.False (view.Frame.IsEmpty);
-        Assert.Equal (new Rectangle (1, 2, 3, 4), view.Frame);
+        Assert.Equal (new (1, 2, 3, 4), view.Frame);
         Assert.False (view.Viewport.IsEmpty);
-        Assert.Equal (new Rectangle (0, 0, 3, 4), view.Viewport);
+        Assert.Equal (new (0, 0, 3, 4), view.Viewport);
 
         view.LayoutSubviews ();
 
@@ -947,7 +954,7 @@ At 0,0
 #endif
 
         // Default Constructor
-        view = new View ();
+        view = new ();
         Assert.Equal (0, view.X);
         Assert.Equal (0, view.Y);
         Assert.Equal (0, view.Width);
@@ -957,7 +964,7 @@ At 0,0
         view.Dispose ();
 
         // Object Initializer
-        view = new View { X = 1, Y = 2, Text = "" };
+        view = new() { X = 1, Y = 2, Text = "" };
         Assert.Equal (1, view.X);
         Assert.Equal (2, view.Y);
         Assert.Equal (0, view.Width);
@@ -967,12 +974,12 @@ At 0,0
         view.Dispose ();
 
         // Default Constructor and post assignment equivalent to Object Initializer
-        view = new View ();
+        view = new ();
         view.X = 1;
         view.Y = 2;
         view.Width = 3;
         view.Height = 4;
-        super = new View { Frame = new Rectangle (0, 0, 10, 10) };
+        super = new() { Frame = new (0, 0, 10, 10) };
         super.Add (view);
         super.BeginInit ();
         super.EndInit ();
@@ -982,9 +989,9 @@ At 0,0
         Assert.Equal (3, view.Width);
         Assert.Equal (4, view.Height);
         Assert.False (view.Frame.IsEmpty);
-        Assert.Equal (new Rectangle (1, 2, 3, 4), view.Frame);
+        Assert.Equal (new (1, 2, 3, 4), view.Frame);
         Assert.False (view.Viewport.IsEmpty);
-        Assert.Equal (new Rectangle (0, 0, 3, 4), view.Viewport);
+        Assert.Equal (new (0, 0, 3, 4), view.Viewport);
         super.Dispose ();
     }
 
@@ -1017,7 +1024,7 @@ At 0,0
 │                            │
 └────────────────────────────┘
 ",
-                                                      _output
+                                                      output
                                                      );
 
         view.Visible = false;
@@ -1033,9 +1040,10 @@ At 0,0
 │                            │
 └────────────────────────────┘
 ",
-                                                      _output
+                                                      output
                                                      );
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1089,7 +1097,7 @@ At 0,0
                                  };
 
         Application.Run (top);
-
+        top.Dispose ();
         Assert.Equal (1, iterations);
 
         int RunesCount ()
@@ -1187,6 +1195,7 @@ At 0,0
         Assert.True (accepted);
 
         return;
+
         void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; }
     }
 
@@ -1198,11 +1207,12 @@ At 0,0
 
         view.Accept += ViewOnAccept;
 
-        var ret = view.InvokeCommand (Command.Accept);
+        bool? ret = view.InvokeCommand (Command.Accept);
         Assert.True (ret);
         Assert.True (acceptInvoked);
 
         return;
+
         void ViewOnAccept (object sender, CancelEventArgs e)
         {
             acceptInvoked = true;
@@ -1222,6 +1232,7 @@ At 0,0
         Assert.True (accepted);
 
         return;
+
         void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; }
     }
 

+ 9 - 4
UnitTests/Views/AppendAutocompleteTests.cs

@@ -2,11 +2,8 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.TextTests;
 
-public class AppendAutocompleteTests
+public class AppendAutocompleteTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper output;
-    public AppendAutocompleteTests (ITestOutputHelper output) { this.output = output; }
-
     [Fact]
     [AutoInitShutdown]
     public void TestAutoAppend_AfterCloseKey_NoAutocomplete ()
@@ -34,6 +31,7 @@ public class AppendAutocompleteTests
         // But can tab away
         Application.Driver.SendKeys ('\t', ConsoleKey.Tab, false, false, false);
         Assert.NotSame (tf, Application.Top.Focused);
+        Application.Top.Dispose ();
     }
 
     [Fact]
@@ -63,6 +61,7 @@ public class AppendAutocompleteTests
         tf.PositionCursor ();
         TestHelpers.AssertDriverContentsAre ("fish", output);
         Assert.Equal ("fi", tf.Text);
+        Application.Top.Dispose ();
     }
 
     [Theory]
@@ -94,6 +93,7 @@ public class AppendAutocompleteTests
         tf.PositionCursor ();
         TestHelpers.AssertDriverContentsAre ("fish", output);
         Assert.Equal ("f", tf.Text);
+        Application.Top.Dispose ();
     }
 
     [Fact]
@@ -116,6 +116,7 @@ public class AppendAutocompleteTests
         tf.Draw ();
         TestHelpers.AssertDriverContentsAre ("f", output);
         Assert.Equal ("f ", tf.Text);
+        Application.Top.Dispose ();
     }
 
     [Fact]
@@ -136,6 +137,7 @@ public class AppendAutocompleteTests
         tf.Draw ();
         TestHelpers.AssertDriverContentsAre ("fx", output);
         Assert.Equal ("fx", tf.Text);
+        Application.Top.Dispose ();
     }
 
     [Fact]
@@ -168,6 +170,7 @@ public class AppendAutocompleteTests
         tf.Draw ();
         TestHelpers.AssertDriverContentsAre ("my FISH", output);
         Assert.Equal ("my FISH", tf.Text);
+        Application.Top.Dispose ();
     }
 
     [Fact]
@@ -203,6 +206,7 @@ public class AppendAutocompleteTests
         // Second tab should move focus (nothing to autocomplete)
         Application.Driver.SendKeys ('\t', ConsoleKey.Tab, false, false, false);
         Assert.NotSame (tf, Application.Top.Focused);
+        Application.Top.Dispose ();
     }
 
     [Theory]
@@ -220,6 +224,7 @@ public class AppendAutocompleteTests
         tf.PositionCursor ();
         TestHelpers.AssertDriverContentsAre (expectRender, output);
         Assert.Equal ("f", tf.Text);
+        Application.Top.Dispose ();
     }
 
     private TextField GetTextFieldsInView ()

+ 5 - 12
UnitTests/Views/ButtonTests.cs

@@ -50,7 +50,6 @@ public class ButtonTests (ITestOutputHelper output)
     [InlineData ("0_12你", 0, 1, 0, 1)]
     [InlineData ("0_12你", 1, 1, 1, 1)]
     [InlineData ("0_12你", 10, 1, 10, 1)]
-    [InlineData ("0_12你", 10, 3, 10, 3)]
     public void Button_AbsoluteSize_Text (string text, int width, int height, int expectedWidth, int expectedHeight)
     {
         var btn1 = new Button
@@ -91,7 +90,6 @@ public class ButtonTests (ITestOutputHelper output)
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void Button_HotKeyChanged_EventFires ()
     {
         var btn = new Button { Text = "_Yar" };
@@ -240,15 +238,11 @@ public class ButtonTests (ITestOutputHelper output)
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void HotKeyChange_Works ()
     {
         var clicked = false;
         var btn = new Button { Text = "_Test" };
         btn.Accept += (s, e) => clicked = true;
-        var top = new Toplevel ();
-        top.Add (btn);
-        Application.Begin (top);
 
         Assert.Equal (KeyCode.T, btn.HotKey);
         Assert.True (btn.NewKeyDownEvent (Key.T));
@@ -262,7 +256,6 @@ public class ButtonTests (ITestOutputHelper output)
         btn.HotKey = KeyCode.E;
         Assert.True (btn.NewKeyDownEvent (Key.E.WithAlt));
         Assert.True (clicked);
-        top.Dispose ();
     }
 
     /// <summary>
@@ -573,11 +566,11 @@ public class ButtonTests (ITestOutputHelper output)
     }
 
     [Theory]
-    [InlineData (MouseFlags.Button1Pressed, MouseFlags.Button1Released, MouseFlags.Button1Clicked)]
-    [InlineData (MouseFlags.Button2Pressed, MouseFlags.Button2Released, MouseFlags.Button2Clicked)]
-    [InlineData (MouseFlags.Button3Pressed, MouseFlags.Button3Released, MouseFlags.Button3Clicked)]
-    [InlineData (MouseFlags.Button4Pressed, MouseFlags.Button4Released, MouseFlags.Button4Clicked)]
-    public void WantContinuousButtonPressed_True_ButtonPressRelease_Accepts (MouseFlags pressed, MouseFlags released, MouseFlags clicked)
+    [InlineData (MouseFlags.Button1Pressed, MouseFlags.Button1Released)]
+    [InlineData (MouseFlags.Button2Pressed, MouseFlags.Button2Released)]
+    [InlineData (MouseFlags.Button3Pressed, MouseFlags.Button3Released)]
+    [InlineData (MouseFlags.Button4Pressed, MouseFlags.Button4Released)]
+    public void WantContinuousButtonPressed_True_ButtonPressRelease_Accepts (MouseFlags pressed, MouseFlags released)
     {
         var me = new MouseEvent ();
 

+ 43 - 42
UnitTests/Views/CheckBoxTests.cs

@@ -3,12 +3,9 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
 
-public class CheckBoxTests
+public class CheckBoxTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
     private static readonly Size _size25x1 = new (25, 1);
-    public CheckBoxTests (ITestOutputHelper output) { _output = output; }
-
 
     [Theory]
     [InlineData ("01234", 0, 0, 0, 0)]
@@ -39,9 +36,9 @@ public class CheckBoxTests
             Text = text
         };
 
-        Assert.Equal (new Size (expectedWidth, expectedHeight), checkBox.Frame.Size);
-        Assert.Equal (new Size (expectedWidth, expectedHeight), checkBox.Viewport.Size);
-        Assert.Equal (new Size (expectedWidth, expectedHeight), checkBox.TextFormatter.Size);
+        Assert.Equal (new (expectedWidth, expectedHeight), checkBox.Frame.Size);
+        Assert.Equal (new (expectedWidth, expectedHeight), checkBox.Viewport.Size);
+        Assert.Equal (new (expectedWidth, expectedHeight), checkBox.TextFormatter.Size);
 
         checkBox.Dispose ();
     }
@@ -60,12 +57,12 @@ public class CheckBoxTests
             X = 0,
             Y = 0,
             Width = width,
-            Height = height,
+            Height = height
         };
 
-        Assert.Equal (new Size (expectedWidth, expectedHeight), checkBox.Frame.Size);
-        Assert.Equal (new Size (expectedWidth, expectedHeight), checkBox.Viewport.Size);
-        Assert.Equal (new Size (expectedWidth, expectedHeight), checkBox.TextFormatter.Size);
+        Assert.Equal (new (expectedWidth, expectedHeight), checkBox.Frame.Size);
+        Assert.Equal (new (expectedWidth, expectedHeight), checkBox.Viewport.Size);
+        Assert.Equal (new (expectedWidth, expectedHeight), checkBox.TextFormatter.Size);
 
         checkBox.Dispose ();
     }
@@ -77,7 +74,7 @@ public class CheckBoxTests
         var view = new CheckBox ();
         view.Title = "Hello";
         Assert.Equal ("Hello", view.Title);
-        Assert.Equal ($"Hello", view.TitleTextFormatter.Text);
+        Assert.Equal ("Hello", view.TitleTextFormatter.Text);
 
         Assert.Equal ("Hello", view.Text);
         Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text);
@@ -92,39 +89,36 @@ public class CheckBoxTests
         Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text);
 
         Assert.Equal ("Hello", view.Title);
-        Assert.Equal ($"Hello", view.TitleTextFormatter.Text);
+        Assert.Equal ("Hello", view.TitleTextFormatter.Text);
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void AllowNullChecked_Get_Set ()
     {
         var checkBox = new CheckBox { Text = "Check this out 你" };
-        Toplevel top = new ();
-        top.Add (checkBox);
-        Application.Begin (top);
 
         Assert.False (checkBox.Checked);
         Assert.True (checkBox.NewKeyDownEvent (Key.Space));
         Assert.True (checkBox.Checked);
-        Assert.True (checkBox.NewMouseEvent (new MouseEvent { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
+        Assert.True (checkBox.NewMouseEvent (new() { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
         Assert.False (checkBox.Checked);
 
         checkBox.AllowNullChecked = true;
         Assert.True (checkBox.NewKeyDownEvent (Key.Space));
         Assert.Null (checkBox.Checked);
-        Application.Refresh ();
+        checkBox.Draw();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @$"
 {CM.Glyphs.NullChecked} Check this out 你",
-                                                      _output
+                                                      output
                                                      );
-        Assert.True (checkBox.NewMouseEvent (new MouseEvent { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
+        Assert.True (checkBox.NewMouseEvent (new() { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
         Assert.True (checkBox.Checked);
         Assert.True (checkBox.NewKeyDownEvent (Key.Space));
         Assert.False (checkBox.Checked);
-        Assert.True (checkBox.NewMouseEvent (new MouseEvent { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
+        Assert.True (checkBox.NewMouseEvent (new() { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
         Assert.Null (checkBox.Checked);
 
         checkBox.AllowNullChecked = false;
@@ -142,9 +136,9 @@ public class CheckBoxTests
         Assert.Equal (string.Empty, ckb.Text);
         Assert.Equal ($"{CM.Glyphs.UnChecked} ", ckb.TextFormatter.Text);
         Assert.True (ckb.CanFocus);
-        Assert.Equal (new Rectangle (0, 0, 2, 1), ckb.Frame);
+        Assert.Equal (new (0, 0, 2, 1), ckb.Frame);
 
-        ckb = new CheckBox { Text = "Test", Checked = true };
+        ckb = new() { Text = "Test", Checked = true };
         Assert.True (ckb.Width is DimAuto);
         Assert.True (ckb.Height is DimAuto);
         Assert.True (ckb.Checked);
@@ -152,9 +146,9 @@ public class CheckBoxTests
         Assert.Equal ("Test", ckb.Text);
         Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
         Assert.True (ckb.CanFocus);
-        Assert.Equal (new Rectangle (0, 0, 6, 1), ckb.Frame);
+        Assert.Equal (new (0, 0, 6, 1), ckb.Frame);
 
-        ckb = new CheckBox { Text = "Test", X = 1, Y = 2 };
+        ckb = new() { Text = "Test", X = 1, Y = 2 };
         Assert.True (ckb.Width is DimAuto);
         Assert.True (ckb.Height is DimAuto);
         Assert.False (ckb.Checked);
@@ -162,9 +156,9 @@ public class CheckBoxTests
         Assert.Equal ("Test", ckb.Text);
         Assert.Equal ($"{CM.Glyphs.UnChecked} Test", ckb.TextFormatter.Text);
         Assert.True (ckb.CanFocus);
-        Assert.Equal (new Rectangle (1, 2, 6, 1), ckb.Frame);
+        Assert.Equal (new (1, 2, 6, 1), ckb.Frame);
 
-        ckb = new CheckBox { Text = "Test", X = 3, Y = 4, Checked = true };
+        ckb = new() { Text = "Test", X = 3, Y = 4, Checked = true };
         Assert.True (ckb.Width is DimAuto);
         Assert.True (ckb.Height is DimAuto);
         Assert.True (ckb.Checked);
@@ -172,7 +166,7 @@ public class CheckBoxTests
         Assert.Equal ("Test", ckb.Text);
         Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
         Assert.True (ckb.CanFocus);
-        Assert.Equal (new Rectangle (3, 4, 6, 1), ckb.Frame);
+        Assert.Equal (new (3, 4, 6, 1), ckb.Frame);
     }
 
     [Fact]
@@ -229,11 +223,12 @@ public class CheckBoxTests
 
         ckb.Accept += ViewOnAccept;
 
-        var ret = ckb.InvokeCommand (Command.Accept);
+        bool? ret = ckb.InvokeCommand (Command.Accept);
         Assert.True (ret);
         Assert.True (acceptInvoked);
 
         return;
+
         void ViewOnAccept (object sender, CancelEventArgs e)
         {
             acceptInvoked = true;
@@ -273,7 +268,7 @@ public class CheckBoxTests
 └────────────────────────────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 30, 5), pos);
 
         checkBox.Checked = true;
@@ -287,8 +282,9 @@ public class CheckBoxTests
 └────────────────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 30, 5), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -324,7 +320,7 @@ public class CheckBoxTests
         Assert.Equal (new (1, 1, 25, 1), checkBox1.Frame);
         Assert.Equal (Alignment.Fill, checkBox2.TextAlignment);
         Assert.Equal (new (1, 2, 25, 1), checkBox2.Frame);
- 
+
         var expected = @$"
 ┌┤Test Demo 你├──────────────┐
 │                            │
@@ -334,7 +330,7 @@ public class CheckBoxTests
 └────────────────────────────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 30, 6), pos);
 
         checkBox1.Checked = true;
@@ -354,8 +350,9 @@ public class CheckBoxTests
 └────────────────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 30, 6), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -389,7 +386,7 @@ public class CheckBoxTests
 └────────────────────────────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 30, 5), pos);
 
         checkBox.Checked = true;
@@ -403,8 +400,9 @@ public class CheckBoxTests
 └────────────────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 30, 5), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -439,7 +437,7 @@ public class CheckBoxTests
 └────────────────────────────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 30, 5), pos);
 
         checkBox.Checked = true;
@@ -453,8 +451,9 @@ public class CheckBoxTests
 └────────────────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 30, 5), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -469,6 +468,7 @@ public class CheckBoxTests
         Assert.True (accepted);
 
         return;
+
         void CheckBoxOnAccept (object sender, CancelEventArgs e) { accepted = true; }
     }
 
@@ -478,19 +478,20 @@ public class CheckBoxTests
     [InlineData (null)]
     public void Toggled_Cancel_Event_Prevents_Toggle (bool? initialState)
     {
-        var ckb = new CheckBox () { AllowNullChecked = true };
+        var ckb = new CheckBox { AllowNullChecked = true };
         var checkedInvoked = false;
 
         ckb.Toggled += CheckBoxToggled;
 
         ckb.Checked = initialState;
-        Assert.Equal(initialState, ckb.Checked);
-        var ret = ckb.OnToggled ();
+        Assert.Equal (initialState, ckb.Checked);
+        bool? ret = ckb.OnToggled ();
         Assert.True (ret);
         Assert.True (checkedInvoked);
         Assert.Equal (initialState, ckb.Checked);
 
         return;
+
         void CheckBoxToggled (object sender, CancelEventArgs e)
         {
             checkedInvoked = true;

+ 5 - 6
UnitTests/Views/ColorPickerTests.cs

@@ -13,11 +13,10 @@ public class ColorPickerTests
         colorPicker.BeginInit ();
         colorPicker.EndInit ();
         colorPicker.LayoutSubviews ();
-        Assert.Equal (new Rectangle (0, 0, 32, 4), colorPicker.Frame);
+        Assert.Equal (new (0, 0, 32, 4), colorPicker.Frame);
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void KeyBindings_Command ()
     {
         var colorPicker = new ColorPicker ();
@@ -52,14 +51,14 @@ public class ColorPickerTests
         top.Add (colorPicker);
         Application.Begin (top);
 
-        Assert.False (colorPicker.NewMouseEvent (new MouseEvent ()));
+        Assert.False (colorPicker.NewMouseEvent (new ()));
 
-        Assert.True (colorPicker.NewMouseEvent (new MouseEvent { Position = new (4, 1), Flags = MouseFlags.Button1Clicked }));
+        Assert.True (colorPicker.NewMouseEvent (new() { Position = new (4, 1), Flags = MouseFlags.Button1Clicked }));
         Assert.Equal (ColorName.Blue, colorPicker.SelectedColor);
+        top.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void SelectedColorAndCursor ()
     {
         var colorPicker = new ColorPicker ();
@@ -71,7 +70,7 @@ public class ColorPickerTests
         Assert.Equal (0, colorPicker.Cursor.X);
         Assert.Equal (0, colorPicker.Cursor.Y);
 
-        colorPicker.Cursor = new Point (7, 1);
+        colorPicker.Cursor = new (7, 1);
         Assert.Equal (ColorName.White, colorPicker.SelectedColor);
 
         colorPicker.Cursor = Point.Empty;

+ 16 - 11
UnitTests/Views/ComboBoxTests.cs

@@ -2,13 +2,9 @@
 
 namespace Terminal.Gui.ViewsTests;
 
-public class ComboBoxTests
+public class ComboBoxTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public ComboBoxTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
-    [AutoInitShutdown]
     public void Constructor_With_Source_Initialize_With_The_Passed_SelectedItem ()
     {
         var cb = new ComboBox
@@ -73,7 +69,6 @@ public class ComboBoxTests
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void EnsureKeyEventsDoNotCauseExceptions ()
     {
         var comboBox = new ComboBox { Text = "0" };
@@ -120,6 +115,7 @@ public class ComboBoxTests
         Assert.False (cb.IsShow);
         Assert.Equal (-1, cb.SelectedItem);
         Assert.Equal ("", cb.Text);
+        top.Dispose ();
     }
 
     [Fact]
@@ -174,6 +170,7 @@ public class ComboBoxTests
         Assert.False (cb.IsShow);
         Assert.Equal (1, cb.SelectedItem);
         Assert.Equal ("", cb.Text);
+        top.Dispose ();
     }
 
     [Fact]
@@ -209,6 +206,7 @@ public class ComboBoxTests
         Assert.False (cb.IsShow);
         Assert.Equal (1, cb.SelectedItem);
         Assert.Equal ("Two", cb.Text);
+        top.Dispose ();
     }
 
     [Fact]
@@ -268,6 +266,7 @@ public class ComboBoxTests
         Assert.False (cb.IsShow);
         Assert.Equal (1, cb.SelectedItem);
         Assert.Equal ("Two", cb.Text);
+        top.Dispose ();
     }
 
     [Fact]
@@ -369,6 +368,7 @@ public class ComboBoxTests
         Assert.False (cb.IsShow);
         Assert.Equal (0, cb.SelectedItem);
         Assert.Equal ("One", cb.Text);
+        top.Dispose ();
     }
 
     [Fact]
@@ -487,6 +487,7 @@ public class ComboBoxTests
         Assert.False (cb.IsShow);
         Assert.Equal (-1, cb.SelectedItem);
         Assert.Equal ("", cb.Text);
+        top.Dispose ();
     }
 
     [Fact]
@@ -523,7 +524,7 @@ public class ComboBoxTests
 One   
 Two   
 Three ",
-                                                      _output
+                                                      output
                                                      );
 
         Attribute [] attributes =
@@ -644,6 +645,7 @@ Three ",
         Assert.False (cb.IsShow);
         Assert.Equal (2, cb.SelectedItem);
         Assert.Equal ("Three", cb.Text);
+        top.Dispose ();
     }
 
     [Fact]
@@ -706,6 +708,7 @@ Three ",
         Assert.False (cb.IsShow);
         Assert.Equal (-1, cb.SelectedItem);
         Assert.Equal ("", cb.Text);
+        top.Dispose ();
     }
 
     [Fact]
@@ -763,6 +766,7 @@ Three ",
         Assert.False (cb.IsShow);
         Assert.Equal (1, cb.SelectedItem);
         Assert.Equal ("Two", cb.Text);
+        top.Dispose ();
     }
 
     [Fact]
@@ -798,6 +802,7 @@ Three ",
         Assert.False (cb.IsShow);
         Assert.Equal (-1, cb.SelectedItem);
         Assert.Equal ("", cb.Text);
+        top.Dispose ();
     }
 
     [Fact]
@@ -876,7 +881,7 @@ Three ",
 One      ▼
 One       
 ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (cb.NewKeyDownEvent (Key.PageDown));
@@ -890,7 +895,7 @@ One
 Two      ▼
 Two       
 ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (cb.NewKeyDownEvent (Key.PageDown));
@@ -904,7 +909,7 @@ Two
 Three    ▼
 Three     
 ",
-                                                      _output
+                                                      output
                                                      );
         Assert.True (cb.NewKeyDownEvent (Key.PageUp));
         Assert.True (cb.IsShow);
@@ -958,10 +963,10 @@ Three
         Assert.Equal (-1, cb.SelectedItem);
         Assert.Equal ("", cb.Text);
         Assert.Equal (3, cb.Source.Count);
+        top.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void Source_Equal_Null_Or_Count_Equal_Zero_Sets_SelectedItem_Equal_To_Minus_One ()
     {
         var cb = new ComboBox ();

+ 86 - 63
UnitTests/Views/ContextMenuTests.cs

@@ -1,15 +1,10 @@
 using System.Globalization;
 using Xunit.Abstractions;
 
-//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
-
 namespace Terminal.Gui.ViewsTests;
 
-public class ContextMenuTests
+public class ContextMenuTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public ContextMenuTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     [AutoInitShutdown]
     public void ContextMenu_Constructors ()
@@ -107,14 +102,15 @@ public class ContextMenuTests
         Assert.True (ContextMenu.IsShow);
         Assert.Equal (cm.MenuBar, Application.MouseGrabView);
         Assert.False (menu.IsMenuOpen);
-        Assert.False (menu.NewMouseEvent(new MouseEvent { Position = new (1, 0), Flags = MouseFlags.ReportMousePosition, View = menu }));
+        Assert.False (menu.NewMouseEvent (new MouseEvent { Position = new (1, 0), Flags = MouseFlags.ReportMousePosition, View = menu }));
         Assert.True (ContextMenu.IsShow);
         Assert.Equal (cm.MenuBar, Application.MouseGrabView);
         Assert.False (menu.IsMenuOpen);
-        Assert.True (menu.NewMouseEvent(new MouseEvent { Position = new (1, 0), Flags = MouseFlags.Button1Clicked, View = menu }));
+        Assert.True (menu.NewMouseEvent (new MouseEvent { Position = new (1, 0), Flags = MouseFlags.Button1Clicked, View = menu }));
         Assert.False (ContextMenu.IsShow);
         Assert.Equal (menu, Application.MouseGrabView);
         Assert.True (menu.IsMenuOpen);
+        top.Dispose ();
     }
 
     [Fact]
@@ -176,8 +172,9 @@ public class ContextMenuTests
  F1 Help │ ^Q Quit              
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new Rectangle (1, 0, 32, 17), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -243,8 +240,9 @@ public class ContextMenuTests
  F1 Help │ ^Q Quit                          
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new Rectangle (1, 0, 44, 17), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -254,7 +252,7 @@ public class ContextMenuTests
         ((FakeDriver)Application.Driver).SetBufferSize (20, 15);
 
         Assert.Equal (new Rectangle (0, 0, 20, 15), Application.Driver.Clip);
-        TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
+        TestHelpers.AssertDriverContentsWithFrameAre ("", output);
 
         var top = new Toplevel { X = 2, Y = 2, Width = 15, Height = 4 };
         top.Add (new TextField { X = Pos.Center (), Width = 10, Text = "Test" });
@@ -266,7 +264,7 @@ public class ContextMenuTests
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
     Test",
-                                                      _output
+                                                      output
                                                      );
 
         Application.OnMouseEvent (new MouseEvent { Position = new (8, 2), Flags = MouseFlags.Button3Clicked });
@@ -286,10 +284,11 @@ public class ContextMenuTests
 │ Undo         Ctrl+
 │ Redo         Ctrl+
 └───────────────────",
-                                                      _output
+                                                      output
                                                      );
 
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
@@ -321,7 +320,7 @@ public class ContextMenuTests
 │                  │
 │                  │
 └──────────────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         // Don't use Dialog here as it has more layout logic. Use Window instead.
@@ -348,7 +347,7 @@ public class ContextMenuTests
 │                  │
 │                  │
 └──────────────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Application.OnMouseEvent (new MouseEvent { Position = new (9, 3), Flags = MouseFlags.Button3Clicked });
@@ -373,11 +372,12 @@ public class ContextMenuTests
 └───────────────────
 │                  │
 └──────────────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Application.End (rsDialog);
         Application.End (rsTop);
+        top.Dispose ();
     }
 
     [Fact]
@@ -387,7 +387,7 @@ public class ContextMenuTests
         ((FakeDriver)Application.Driver).SetBufferSize (20, 15);
 
         Assert.Equal (new Rectangle (0, 0, 20, 15), Application.Driver.Clip);
-        TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
+        TestHelpers.AssertDriverContentsWithFrameAre ("", output);
 
         // Don't use Dialog here as it has more layout logic. Use Window instead.
         var dialog = new Window { X = 2, Y = 2, Width = 15, Height = 4 };
@@ -403,7 +403,7 @@ public class ContextMenuTests
   │ Test        │
   │             │
   └─────────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Application.OnMouseEvent (new MouseEvent { Position = new (9, 3), Flags = MouseFlags.Button3Clicked });
@@ -424,10 +424,11 @@ public class ContextMenuTests
 │ Undo         Ctrl+
 │ Redo         Ctrl+
 └───────────────────",
-                                                      _output
+                                                      output
                                                      );
 
         Application.End (rs);
+        dialog.Dispose ();
     }
 
     [Fact]
@@ -446,8 +447,9 @@ public class ContextMenuTests
         };
 
         Assert.Equal (new Point (-1, -2), cm.Position);
-
-        Application.Begin (new ());
+        
+        Toplevel top = new ();
+        Application.Begin (top);
 
         cm.Show ();
         Assert.Equal (new Point (-1, -2), cm.Position);
@@ -460,7 +462,7 @@ public class ContextMenuTests
 └──────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new Rectangle (0, 1, 8, 4), pos);
 
         cm.ForceMinimumPosToZero = false;
@@ -474,8 +476,9 @@ public class ContextMenuTests
 ──────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new Rectangle (1, 0, 7, 3), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -504,6 +507,7 @@ public class ContextMenuTests
 
         top.RequestStop ();
         Assert.False (ContextMenu.IsShow);
+        top.Dispose ();
     }
 
     [Fact]
@@ -519,6 +523,7 @@ public class ContextMenuTests
         Assert.True (tf.ContextMenu.MenuBar.IsMenuOpen);
         Assert.True (Application.OnKeyDown (ContextMenu.DefaultKey));
         Assert.Null (tf.ContextMenu.MenuBar);
+        top.Dispose ();
     }
 
     [Fact]
@@ -550,7 +555,8 @@ public class ContextMenuTests
                                         )
         };
 
-        Application.Begin (new ());
+        Toplevel top = new ();
+        Application.Begin (top);
         cm.Show ();
         Application.Refresh ();
 
@@ -561,7 +567,7 @@ public class ContextMenuTests
           └──────┘
 ";
 
-        TestHelpers.AssertDriverContentsAre (expected, _output);
+        TestHelpers.AssertDriverContentsAre (expected, output);
 
         cm.MenuItems = new MenuBarItem (
                                         [
@@ -582,7 +588,8 @@ public class ContextMenuTests
           └─────────┘
 ";
 
-        TestHelpers.AssertDriverContentsAre (expected, _output);
+        TestHelpers.AssertDriverContentsAre (expected, output);
+        top.Dispose ();
     }
 
     [Fact]
@@ -636,7 +643,7 @@ public class ContextMenuTests
 │ Six    │
 └────────┘
 ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (
@@ -664,7 +671,7 @@ public class ContextMenuTests
           │ SubMenu7  │
           └───────────┘
 ",
-                                                      _output
+                                                      output
                                                      );
 
         ((FakeDriver)Application.Driver).SetBufferSize (40, 20);
@@ -684,7 +691,7 @@ public class ContextMenuTests
                               │ Six    │
                               └────────┘
 ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (
@@ -712,7 +719,7 @@ public class ContextMenuTests
                  │ SubMenu7  │          
                  └───────────┘          
 ",
-                                                      _output
+                                                      output
                                                      );
 
         cm.Position = new Point (41, 9);
@@ -731,7 +738,7 @@ public class ContextMenuTests
                               │ Six    │
                               └────────┘
 ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (
@@ -756,7 +763,7 @@ public class ContextMenuTests
                  │ SubMenu7  │          
                  └───────────┘          
 ",
-                                                      _output
+                                                      output
                                                      );
 
         cm.Position = new Point (41, 22);
@@ -775,7 +782,7 @@ public class ContextMenuTests
                               │ Six    │
                               └────────┘
 ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (
@@ -799,7 +806,7 @@ public class ContextMenuTests
                  │ SubMenu7  ││ Six    │
                  └───────────┘└────────┘
 ",
-                                                      _output
+                                                      output
                                                      );
 
         ((FakeDriver)Application.Driver).SetBufferSize (18, 8);
@@ -819,7 +826,7 @@ public class ContextMenuTests
         │ Six    │
         └────────┘
 ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (
@@ -842,8 +849,9 @@ public class ContextMenuTests
 │ SubMenu6  │    │
 │ SubMenu7  │────┘
 ",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -874,10 +882,10 @@ public class ContextMenuTests
         cm.MouseFlags = MouseFlags.Button2Clicked;
         Assert.True (lbl.NewMouseEvent (new MouseEvent { Flags = cm.MouseFlags }));
         Assert.Equal ("Replaced", lbl.Text);
+        top.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void MouseFlagsChanged_Event ()
     {
         var oldMouseFlags = new MouseFlags ();
@@ -905,7 +913,8 @@ public class ContextMenuTests
                                         )
         };
 
-        Application.Begin (new ());
+        Toplevel top = new ();
+        Application.Begin (top);
         cm.Show ();
         Application.Refresh ();
 
@@ -916,7 +925,7 @@ public class ContextMenuTests
           └──────┘
 ";
 
-        TestHelpers.AssertDriverContentsAre (expected, _output);
+        TestHelpers.AssertDriverContentsAre (expected, output);
 
         cm.Position = new Point (5, 10);
 
@@ -930,7 +939,8 @@ public class ContextMenuTests
      └──────┘
 ";
 
-        TestHelpers.AssertDriverContentsAre (expected, _output);
+        TestHelpers.AssertDriverContentsAre (expected, output);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1006,6 +1016,7 @@ public class ContextMenuTests
         Assert.True (isTopClosed);
         Assert.False (ContextMenu.IsShow);
         Assert.True (isMenuAllClosed);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1027,7 +1038,8 @@ public class ContextMenuTests
 
         Assert.Equal (Point.Empty, cm.Position);
 
-        Application.Begin (new ());
+        Toplevel top = new ();
+        Application.Begin (top);
         cm.Show ();
         Assert.Equal (Point.Empty, cm.Position);
         Application.Refresh ();
@@ -1037,11 +1049,12 @@ public class ContextMenuTests
 │ One  │
 │ Two  │";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new Rectangle (0, 0, 8, 3), pos);
 
         cm.Hide ();
         Assert.Equal (Point.Empty, cm.Position);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1063,7 +1076,8 @@ public class ContextMenuTests
 
         Assert.Equal (Point.Empty, cm.Position);
 
-        Application.Begin (new ());
+        Toplevel top = new ();
+        Application.Begin (top);
         cm.Show ();
         Assert.Equal (Point.Empty, cm.Position);
         Application.Refresh ();
@@ -1074,11 +1088,12 @@ public class ContextMenuTests
 │ Two
 └────";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new Rectangle (0, 1, 5, 4), pos);
 
         cm.Hide ();
         Assert.Equal (Point.Empty, cm.Position);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1124,7 +1139,7 @@ public class ContextMenuTests
           └──────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new Rectangle (10, 5, 18, 5), pos);
 
         cm.Hide ();
@@ -1147,11 +1162,12 @@ public class ContextMenuTests
      └──────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new Rectangle (5, 10, 13, 7), pos);
 
         cm.Hide ();
         Assert.Equal (new Point (5, 12), cm.Position);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1171,7 +1187,8 @@ public class ContextMenuTests
 
         Assert.Equal (new Point (80, 25), cm.Position);
 
-        Application.Begin (new ());
+        Toplevel top = new ();
+        Application.Begin (top);
         cm.Show ();
         Assert.Equal (new Point (80, 25), cm.Position);
         Application.Refresh ();
@@ -1183,11 +1200,12 @@ public class ContextMenuTests
                                                                         └──────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new Rectangle (72, 21, 80, 4), pos);
 
         cm.Hide ();
         Assert.Equal (new Point (80, 25), cm.Position);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1233,11 +1251,12 @@ public class ContextMenuTests
                                                                       View    
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new Rectangle (70, 20, 78, 5), pos);
 
         cm.Hide ();
         Assert.Equal (new Point (70, 24), cm.Position);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1246,7 +1265,8 @@ public class ContextMenuTests
     {
         ContextMenu cm = Create_ContextMenu_With_Two_MenuItem (10, 5);
 
-        Application.Begin (new ());
+        Toplevel top = new ();
+        Application.Begin (top);
         cm.Show ();
         Assert.True (ContextMenu.IsShow);
         Application.Refresh ();
@@ -1258,7 +1278,7 @@ public class ContextMenuTests
           └──────┘
 ";
 
-        TestHelpers.AssertDriverContentsAre (expected, _output);
+        TestHelpers.AssertDriverContentsAre (expected, output);
 
         cm.Hide ();
         Assert.False (ContextMenu.IsShow);
@@ -1267,7 +1287,8 @@ public class ContextMenuTests
 
         expected = "";
 
-        TestHelpers.AssertDriverContentsAre (expected, _output);
+        TestHelpers.AssertDriverContentsAre (expected, output);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1297,8 +1318,8 @@ public class ContextMenuTests
                                         ),
             UseSubMenusSingleFrame = true
         };
-
-        RunState rs = Application.Begin (new ());
+        Toplevel top = new ();
+        RunState rs = Application.Begin (top);
         cm.Show ();
         Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.Subviews [0].Frame);
         Application.Refresh ();
@@ -1310,7 +1331,7 @@ public class ContextMenuTests
      │ Two   ►│
      │ Three  │
      └────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         // X=5 is the border and so need to use at least one more
@@ -1329,7 +1350,7 @@ public class ContextMenuTests
      │ Sub-Menu 1  │
      │ Sub-Menu 2  │
      └─────────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Application.OnMouseEvent (new MouseEvent { Position = new (6, 12), Flags = MouseFlags.Button1Clicked });
@@ -1345,10 +1366,11 @@ public class ContextMenuTests
      │ Two   ►│
      │ Three  │
      └────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1386,8 +1408,8 @@ public class ContextMenuTests
                                          ]
                                         )
         };
-
-        RunState rs = Application.Begin (new ());
+        Toplevel top = new ();
+        RunState rs = Application.Begin (top);
         cm.Show ();
 
         Assert.Equal (new Rectangle (5, 11, 10, 5), Application.Top.Subviews [0].Frame);
@@ -1400,7 +1422,7 @@ public class ContextMenuTests
      │ Two   ►│
      │ Three ►│
      └────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Application.OnMouseEvent (new MouseEvent { Position = new (6, 13), Flags = MouseFlags.ReportMousePosition });
@@ -1417,7 +1439,7 @@ public class ContextMenuTests
      │ Three ►││ Two-Menu 1  │
      └────────┘│ Two-Menu 2  │
                └─────────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Application.OnMouseEvent (new MouseEvent { Position = new (6, 14), Flags = MouseFlags.ReportMousePosition });
@@ -1435,7 +1457,7 @@ public class ContextMenuTests
      └────────┘│ Three-Menu 1  │
                │ Three-Menu 2  │
                └───────────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Application.OnMouseEvent (new MouseEvent { Position = new (6, 13), Flags = MouseFlags.ReportMousePosition });
@@ -1452,10 +1474,11 @@ public class ContextMenuTests
      │ Three ►││ Two-Menu 1  │
      └────────┘│ Two-Menu 2  │
                └─────────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Application.End (rs);
+        top.Dispose ();
     }
 
     private ContextMenu Create_ContextMenu_With_Two_MenuItem (int x, int y)

+ 1 - 1
UnitTests/Views/DateFieldTests.cs

@@ -30,7 +30,7 @@ public class DateFieldTests
 
     [Fact]
     [TestDate]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void Copy_Paste ()
     {
         var df1 = new DateField (DateTime.Parse ("12/12/1971"));

+ 3 - 1
UnitTests/Views/DatePickerTests.cs

@@ -50,7 +50,7 @@ public class DatePickerTests
         var datePicker = new DatePicker (date);
 
         var top = new Toplevel ();
-       top.Add (datePicker);
+        top.Add (datePicker);
         Application.Begin (top);
 
         // Set focus to next month button
@@ -65,6 +65,7 @@ public class DatePickerTests
         // Date should not change as next month button is disabled
         Assert.False (datePicker.NewKeyDownEvent (Key.Enter));
         Assert.Equal (12, datePicker.Date.Month);
+        top.Dispose ();
     }
 
     [Fact]
@@ -90,5 +91,6 @@ public class DatePickerTests
         // Date should not change as previous month button is disabled
         Assert.False (datePicker.NewKeyDownEvent (Key.Enter));
         Assert.Equal (1, datePicker.Date.Month);
+        top.Dispose ();
     }
 }

+ 15 - 17
UnitTests/Views/FrameViewTests.cs

@@ -2,11 +2,8 @@
 
 namespace Terminal.Gui.ViewsTests;
 
-public class FrameViewTests
+public class FrameViewTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public FrameViewTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     public void Constructors_Defaults ()
     {
@@ -15,12 +12,12 @@ public class FrameViewTests
         Assert.Equal (string.Empty, fv.Text);
         Assert.Equal (LineStyle.Single, fv.BorderStyle);
 
-        fv = new FrameView { Title = "Test" };
+        fv = new() { Title = "Test" };
         Assert.Equal ("Test", fv.Title);
         Assert.Equal (string.Empty, fv.Text);
         Assert.Equal (LineStyle.Single, fv.BorderStyle);
 
-        fv = new FrameView
+        fv = new()
         {
             X = 1,
             Y = 2,
@@ -33,7 +30,7 @@ public class FrameViewTests
         fv.BeginInit ();
         fv.EndInit ();
         Assert.Equal (LineStyle.Single, fv.BorderStyle);
-        Assert.Equal (new Rectangle (1, 2, 10, 20), fv.Frame);
+        Assert.Equal (new (1, 2, 10, 20), fv.Frame);
     }
 
     [Fact]
@@ -47,12 +44,12 @@ public class FrameViewTests
         var top = new Toplevel ();
         top.Add (fv);
         Application.Begin (top);
-        Assert.Equal (new Rectangle (0, 0, 0, 0), fv.Frame);
-        TestHelpers.AssertDriverContentsWithFrameAre (@"", _output);
+        Assert.Equal (new (0, 0, 0, 0), fv.Frame);
+        TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
 
         fv.Height = 5;
         fv.Width = 5;
-        Assert.Equal (new Rectangle (0, 0, 5, 5), fv.Frame);
+        Assert.Equal (new (0, 0, 5, 5), fv.Frame);
         Application.Refresh ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -62,12 +59,12 @@ public class FrameViewTests
 │   │
 │   │
 └───┘",
-                                                      _output
+                                                      output
                                                      );
 
         fv.X = 1;
         fv.Y = 2;
-        Assert.Equal (new Rectangle (1, 2, 5, 5), fv.Frame);
+        Assert.Equal (new (1, 2, 5, 5), fv.Frame);
         Application.Refresh ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -77,12 +74,12 @@ public class FrameViewTests
  │   │
  │   │
  └───┘",
-                                                      _output
+                                                      output
                                                      );
 
         fv.X = -1;
         fv.Y = -2;
-        Assert.Equal (new Rectangle (-1, -2, 5, 5), fv.Frame);
+        Assert.Equal (new (-1, -2, 5, 5), fv.Frame);
         Application.Refresh ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -90,19 +87,20 @@ public class FrameViewTests
 ───┘",
-                                                      _output
+                                                      output
                                                      );
 
         fv.X = 7;
         fv.Y = 8;
-        Assert.Equal (new Rectangle (7, 8, 5, 5), fv.Frame);
+        Assert.Equal (new (7, 8, 5, 5), fv.Frame);
         Application.Refresh ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
        ┌──
        │  ",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 }

+ 15 - 10
UnitTests/Views/HexViewTests.cs

@@ -86,7 +86,7 @@ public class HexViewTests
         Assert.True (hv.CanFocus);
         Assert.True (hv.AllowEdits);
 
-        hv = new HexView (new MemoryStream ());
+        hv = new (new MemoryStream ());
         Assert.NotNull (hv.Source);
         Assert.IsAssignableFrom<Stream> (hv.Source);
         Assert.True (hv.CanFocus);
@@ -102,7 +102,7 @@ public class HexViewTests
         top.Add (hv);
         Application.Begin (top);
 
-        Assert.Equal (new Point (1, 1), hv.CursorPosition);
+        Assert.Equal (new (1, 1), hv.CursorPosition);
 
         Assert.True (hv.NewKeyDownEvent (Key.Enter));
         Assert.True (hv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
@@ -110,16 +110,17 @@ public class HexViewTests
         Assert.True (hv.NewKeyDownEvent (Key.Home));
 
         Assert.True (hv.NewKeyDownEvent (Key.CursorRight));
-        Assert.Equal (new Point (2, 1), hv.CursorPosition);
+        Assert.Equal (new (2, 1), hv.CursorPosition);
 
         Assert.True (hv.NewKeyDownEvent (Key.CursorDown));
-        Assert.Equal (new Point (2, 2), hv.CursorPosition);
+        Assert.Equal (new (2, 2), hv.CursorPosition);
 
         Assert.True (hv.NewKeyDownEvent (Key.End));
         int col = hv.CursorPosition.X;
         int line = hv.CursorPosition.Y;
         int offset = (line - 1) * (hv.BytesPerLine - col);
         Assert.Equal (hv.Position, col * line + offset);
+        top.Dispose ();
     }
 
     [Fact]
@@ -131,7 +132,7 @@ public class HexViewTests
         top.Add (hv);
         Application.Begin (top);
 
-        Assert.Equal (new Point (1, 1), hv.CursorPosition);
+        Assert.Equal (new (1, 1), hv.CursorPosition);
 
         Assert.True (hv.NewKeyDownEvent (Key.Enter));
         Assert.True (hv.NewKeyDownEvent (Key.CursorRight.WithCtrl));
@@ -139,16 +140,17 @@ public class HexViewTests
         Assert.True (hv.NewKeyDownEvent (Key.Home));
 
         Assert.True (hv.NewKeyDownEvent (Key.CursorRight));
-        Assert.Equal (new Point (2, 1), hv.CursorPosition);
+        Assert.Equal (new (2, 1), hv.CursorPosition);
 
         Assert.True (hv.NewKeyDownEvent (Key.CursorDown));
-        Assert.Equal (new Point (2, 2), hv.CursorPosition);
+        Assert.Equal (new (2, 2), hv.CursorPosition);
 
         Assert.True (hv.NewKeyDownEvent (Key.End));
         int col = hv.CursorPosition.X;
         int line = hv.CursorPosition.Y;
         int offset = (line - 1) * (hv.BytesPerLine - col);
         Assert.Equal (hv.Position, col * line + offset);
+        top.Dispose ();
     }
 
     [Fact]
@@ -200,7 +202,7 @@ public class HexViewTests
         hv.LayoutSubviews ();
 
         KeyValuePair<long, byte> keyValuePair = default;
-        hv.Edited += (s, e) => keyValuePair = new KeyValuePair<long, byte> (e.Position, e.NewValue);
+        hv.Edited += (s, e) => keyValuePair = new (e.Position, e.NewValue);
 
         Assert.True (hv.NewKeyDownEvent (Key.D4));
         Assert.True (hv.NewKeyDownEvent (Key.D6));
@@ -248,7 +250,7 @@ public class HexViewTests
         Assert.True (hv.NewKeyDownEvent (Key.V.WithCtrl));
         Assert.Equal (41, hv.Position);
 
-        Assert.True (hv.NewKeyDownEvent (new Key (Key.V.WithAlt)));
+        Assert.True (hv.NewKeyDownEvent (new (Key.V.WithAlt)));
         Assert.Equal (1, hv.Position);
 
         Assert.True (hv.NewKeyDownEvent (Key.PageDown));
@@ -274,6 +276,7 @@ public class HexViewTests
 
         Assert.True (hv.NewKeyDownEvent (Key.CursorUp.WithCtrl));
         Assert.Equal (1, hv.Position);
+        top.Dispose ();
     }
 
     [Fact]
@@ -360,8 +363,9 @@ public class HexViewTests
         Assert.True (hv.NewKeyDownEvent (Key.CursorDown));
 
         Assert.Equal (12, hexViewEventArgs.BytesPerLine);
-        Assert.Equal (new Point (2, 2), hexViewEventArgs.CursorPosition);
+        Assert.Equal (new (2, 2), hexViewEventArgs.CursorPosition);
         Assert.Equal (14, hexViewEventArgs.Position);
+        top.Dispose ();
     }
 
     [Fact]
@@ -395,6 +399,7 @@ public class HexViewTests
         hv.Source = new MemoryStream ();
         Assert.Equal (0, hv.DisplayStart);
         Assert.Equal (0, hv.Position - 1);
+        top.Dispose ();
     }
 
     private Stream LoadStream (bool unicode = false)

+ 185 - 184
UnitTests/Views/LabelTests.cs

@@ -1,14 +1,10 @@
 using System.ComponentModel;
-using Microsoft.VisualStudio.TestPlatform.Utilities;
 using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
 
-public class LabelTests
+public class LabelTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public LabelTests (ITestOutputHelper output) { _output = output; }
-
     // Test that Title and Text are the same
     [Fact]
     public void Text_Mirrors_Title ()
@@ -37,9 +33,9 @@ public class LabelTests
     [Fact]
     public void HotKey_Command_SetsFocus_OnNextSubview ()
     {
-        var superView = new View () { CanFocus = true };
+        var superView = new View { CanFocus = true };
         var label = new Label ();
-        var nextSubview = new View () { CanFocus = true };
+        var nextSubview = new View { CanFocus = true };
         superView.Add (label, nextSubview);
         superView.BeginInit ();
         superView.EndInit ();
@@ -52,14 +48,13 @@ public class LabelTests
         Assert.True (nextSubview.HasFocus);
     }
 
-
     [Fact]
     public void MouseClick_SetsFocus_OnNextSubview ()
     {
-        var superView = new View () { CanFocus = true, Height = 1, Width = 15 };
-        var focusedView = new View () { CanFocus = true, Width = 1, Height = 1 };
-        var label = new Label () { X = 2, Title = "_x" };
-        var nextSubview = new View () { CanFocus = true, X = 4, Width = 4, Height = 1 };
+        var superView = new View { CanFocus = true, Height = 1, Width = 15 };
+        var focusedView = new View { CanFocus = true, Width = 1, Height = 1 };
+        var label = new Label { X = 2, Title = "_x" };
+        var nextSubview = new View { CanFocus = true, X = 4, Width = 4, Height = 1 };
         superView.Add (focusedView, label, nextSubview);
         superView.BeginInit ();
         superView.EndInit ();
@@ -68,7 +63,7 @@ public class LabelTests
         Assert.False (label.HasFocus);
         Assert.False (nextSubview.HasFocus);
 
-        label.NewMouseEvent (new MouseEvent () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked });
+        label.NewMouseEvent (new() { Position = new (0, 0), Flags = MouseFlags.Button1Clicked });
         Assert.False (label.HasFocus);
         Assert.True (nextSubview.HasFocus);
     }
@@ -85,6 +80,7 @@ public class LabelTests
         Assert.False (accepted);
 
         return;
+
         void LabelOnAccept (object sender, CancelEventArgs e) { accepted = true; }
     }
 
@@ -100,8 +96,6 @@ public class LabelTests
         var top = new Toplevel ();
         top.Add (win);
 
-       
-
         Application.Begin (top);
         ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
 
@@ -113,11 +107,10 @@ public class LabelTests
 └────────────────────────────┘
 ";
 
-        TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
 
-       
         label.Text = "Say Hello 你 changed";
-       
+
         Application.Refresh ();
 
         expected = @"
@@ -128,7 +121,8 @@ public class LabelTests
 └────────────────────────────┘
 ";
 
-        TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        top.Dispose ();
     }
 
     [Fact]
@@ -153,11 +147,10 @@ public class LabelTests
 └────────────────────────────┘
 ";
 
-        TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
 
-       
         label.Text = "Say Hello 你 changed";
-       
+
         Application.Refresh ();
 
         expected = @"
@@ -168,7 +161,8 @@ public class LabelTests
 └────────────────────────────┘
 ";
 
-        TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        top.Dispose ();
     }
 
     [Fact]
@@ -182,12 +176,8 @@ public class LabelTests
         var top = new Toplevel ();
         top.Add (win);
 
-       
-
         label.Text = "Say Hello 你";
 
-       
-
         Application.Begin (top);
         ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
 
@@ -199,7 +189,8 @@ public class LabelTests
 └────────────────────────────┘
 ";
 
-        TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        top.Dispose ();
     }
 
     [Fact]
@@ -209,7 +200,7 @@ public class LabelTests
         Assert.Equal (string.Empty, label.Text);
         Assert.Equal (Alignment.Start, label.TextAlignment);
         Assert.False (label.CanFocus);
-        Assert.Equal (new Rectangle (0, 0, 0, 0), label.Frame);
+        Assert.Equal (new (0, 0, 0, 0), label.Frame);
         Assert.Equal (KeyCode.Null, label.HotKey);
     }
 
@@ -217,7 +208,7 @@ public class LabelTests
     [AutoInitShutdown]
     public void Label_Draw_Fill_Remaining_AutoSize_False ()
     {
-        Size tfSize = new Size (80, 1);
+        var tfSize = new Size (80, 1);
 
         var label = new Label { Text = "This label needs to be cleared before rewritten.", Width = tfSize.Width, Height = tfSize.Height };
 
@@ -238,16 +229,16 @@ public class LabelTests
         Assert.False (tf1.FillRemaining);
         Assert.True (tf2.FillRemaining);
 
-        tf1.Draw (new Rectangle (new Point (0, 1), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal);
+        tf1.Draw (new (new (0, 1), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal);
 
-        tf2.Draw (new Rectangle (new Point (0, 2), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal);
+        tf2.Draw (new (new (0, 2), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal);
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 This label needs to be cleared before rewritten.                       
 This TextFormatter (tf1) without fill will not be cleared on rewritten.
 This TextFormatter (tf2) with fill will be cleared on rewritten.       ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.False (label.NeedsDisplay);
@@ -260,18 +251,19 @@ This TextFormatter (tf2) with fill will be cleared on rewritten.       ",
         label.Draw ();
 
         tf1.Text = "This TextFormatter (tf1) is rewritten.";
-        tf1.Draw (new Rectangle (new Point (0, 1), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal);
+        tf1.Draw (new (new (0, 1), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal);
 
         tf2.Text = "This TextFormatter (tf2) is rewritten.";
-        tf2.Draw (new Rectangle (new Point (0, 2), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal);
+        tf2.Draw (new (new (0, 2), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal);
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 This label is rewritten.                                               
 This TextFormatter (tf1) is rewritten.will not be cleared on rewritten.
 This TextFormatter (tf2) is rewritten.                                 ",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -283,15 +275,15 @@ This TextFormatter (tf2) is rewritten.                                 ",
         top.Add (label);
         Application.Begin (top);
 
-       
-        Assert.Equal (new Rectangle (0, 0, 16, 1), label.Frame);
+        Assert.Equal (new (0, 0, 16, 1), label.Frame);
 
         var expected = @"
 Demo Simple Rune
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (0, 0, 16, 1), pos);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (0, 0, 16, 1), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -325,8 +317,9 @@ n
 e
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (0, 0, 1, 16), pos);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (0, 0, 1, 16), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -348,12 +341,12 @@ e
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (0, 0, 2, 7), pos);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (0, 0, 2, 7), pos);
+        top.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void Label_HotKeyChanged_EventFires ()
     {
         var label = new Label { Text = "Yar" };
@@ -375,7 +368,6 @@ e
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void Label_HotKeyChanged_EventFires_WithNone ()
     {
         var label = new Label ();
@@ -427,7 +419,7 @@ e
         Assert.True (label.IsInitialized);
         Assert.Equal ("Say Hello 你", label.Text);
         Assert.Equal ("Say Hello 你", label.TextFormatter.Text);
-        Assert.Equal (new Rectangle (0, 0, 12, 1), label.Viewport);
+        Assert.Equal (new (0, 0, 12, 1), label.Viewport);
 
         var expected = @"
 ┌────────────────────────────┐
@@ -436,8 +428,9 @@ e
 │                            │
 └────────────────────────────┘
 ";
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (0, 0, 30, 5), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -458,7 +451,7 @@ e
         Assert.True (label.IsInitialized);
         Assert.Equal ("Say Hello 你", label.Text);
         Assert.Equal ("Say Hello 你", label.TextFormatter.Text);
-        Assert.Equal (new Rectangle (0, 0, 12, 1), label.Viewport);
+        Assert.Equal (new (0, 0, 12, 1), label.Viewport);
 
         var expected = @"
 ┌────────────────────────────┐
@@ -468,18 +461,18 @@ e
 └────────────────────────────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (0, 0, 30, 5), pos);
+        top.Dispose ();
     }
 
-
     [Fact]
     [SetupFakeDriver]
     public void Full_Border ()
     {
-        var label = new Label { BorderStyle = LineStyle.Single , Text = "Test",} ;
-        label.BeginInit();
-        label.EndInit();
+        var label = new Label { BorderStyle = LineStyle.Single, Text = "Test" };
+        label.BeginInit ();
+        label.EndInit ();
         label.SetRelativeLayout (Application.Driver.Screen.Size);
 
         Assert.Equal (new (0, 0, 4, 1), label.Viewport);
@@ -492,7 +485,7 @@ e
 ┌┤Te├┐
 │Test│
 └────┘",
-                                                      _output
+                                                      output
                                                      );
         label.Dispose ();
     }
@@ -502,8 +495,8 @@ e
     public void With_Top_Margin_Without_Top_Border ()
     {
         var label = new Label { Text = "Test", /*Width = 6, Height = 3,*/ BorderStyle = LineStyle.Single };
-        label.Margin.Thickness = new Thickness (0, 1, 0, 0);
-        label.Border.Thickness = new Thickness (1, 0, 1, 1);
+        label.Margin.Thickness = new (0, 1, 0, 0);
+        label.Border.Thickness = new (1, 0, 1, 1);
         var top = new Toplevel ();
         top.Add (label);
         Application.Begin (top);
@@ -516,8 +509,9 @@ e
                                                       @"
 │Test│
 └────┘",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -525,7 +519,7 @@ e
     public void Without_Top_Border ()
     {
         var label = new Label { Text = "Test", /* Width = 6, Height = 3, */BorderStyle = LineStyle.Single };
-        label.Border.Thickness = new Thickness (1, 0, 1, 1);
+        label.Border.Thickness = new (1, 0, 1, 1);
         var top = new Toplevel ();
         top.Add (label);
         Application.Begin (top);
@@ -538,13 +532,14 @@ e
                                                       @"
 │Test│
 └────┘",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 
     // These tests were formally in AutoSizetrue.cs. They are (poor) Label tests.
     private readonly string [] expecteds = new string [21]
-  {
+    {
         @"
 ┌────────────────────┐
 │View with long text │
@@ -860,7 +855,7 @@ e
 │Label 19            │
 │Label 19            │
 └────────────────────┘"
-  };
+    };
 
     private static readonly Size _size1x1 = new (1, 1);
 
@@ -889,9 +884,9 @@ e
         ((FakeDriver)Application.Driver).SetBufferSize (40, 10);
 
         Assert.Equal (29, label.Text.Length);
-        Assert.Equal (new Rectangle (0, 0, 40, 10), top.Frame);
-        Assert.Equal (new Rectangle (0, 0, 40, 10), win.Frame);
-        Assert.Equal (new Rectangle (0, 7, 29, 1), label.Frame);
+        Assert.Equal (new (0, 0, 40, 10), top.Frame);
+        Assert.Equal (new (0, 0, 40, 10), win.Frame);
+        Assert.Equal (new (0, 7, 29, 1), label.Frame);
 
         var expected = @"
 ┌──────────────────────────────────────┐
@@ -905,10 +900,11 @@ e
 │This should be the last line.         │
 └──────────────────────────────────────┘
 "
-        ;
+            ;
 
-        TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
@@ -935,11 +931,11 @@ e
         top.Add (win, menu, status);
         RunState rs = Application.Begin (top);
 
-        Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame);
-        Assert.Equal (new Rectangle (0, 0, 80, 1), menu.Frame);
-        Assert.Equal (new Rectangle (0, 24, 80, 1), status.Frame);
-        Assert.Equal (new Rectangle (0, 1, 80, 23), win.Frame);
-        Assert.Equal (new Rectangle (0, 20, 29, 1), label.Frame);
+        Assert.Equal (new (0, 0, 80, 25), top.Frame);
+        Assert.Equal (new (0, 0, 80, 1), menu.Frame);
+        Assert.Equal (new (0, 24, 80, 1), status.Frame);
+        Assert.Equal (new (0, 1, 80, 23), win.Frame);
+        Assert.Equal (new (0, 20, 29, 1), label.Frame);
 
         var expected = @"
  Menu                                                                           
@@ -969,8 +965,9 @@ e
  F1 Help                                                                        
 ";
 
-        TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        top.Dispose ();
     }
 
     // TODO: This is a Label test. Move to label tests if there's not already a test for this.
@@ -999,9 +996,9 @@ e
         RunState rs = Application.Begin (top);
         ((FakeDriver)Application.Driver).SetBufferSize (40, 10);
 
-        Assert.Equal (new Rectangle (0, 0, 40, 10), top.Frame);
-        Assert.Equal (new Rectangle (0, 0, 40, 10), win.Frame);
-        Assert.Equal (new Rectangle (0, 7, 29, 1), label.Frame);
+        Assert.Equal (new (0, 0, 40, 10), top.Frame);
+        Assert.Equal (new (0, 0, 40, 10), win.Frame);
+        Assert.Equal (new (0, 7, 29, 1), label.Frame);
 
         var expected = @"
 ┌──────────────────────────────────────┐
@@ -1016,8 +1013,9 @@ e
 └──────────────────────────────────────┘
 ";
 
-        TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        top.Dispose ();
     }
 
     // TODO: This is a Label test. Move to label tests if there's not already a test for this.
@@ -1047,11 +1045,11 @@ e
         top.Add (win, menu, status);
         RunState rs = Application.Begin (top);
 
-        Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame);
-        Assert.Equal (new Rectangle (0, 0, 80, 1), menu.Frame);
-        Assert.Equal (new Rectangle (0, 24, 80, 1), status.Frame);
-        Assert.Equal (new Rectangle (0, 1, 80, 23), win.Frame);
-        Assert.Equal (new Rectangle (0, 20, 29, 1), label.Frame);
+        Assert.Equal (new (0, 0, 80, 25), top.Frame);
+        Assert.Equal (new (0, 0, 80, 1), menu.Frame);
+        Assert.Equal (new (0, 24, 80, 1), status.Frame);
+        Assert.Equal (new (0, 1, 80, 23), win.Frame);
+        Assert.Equal (new (0, 20, 29, 1), label.Frame);
 
         var expected = @"
  Menu                                                                           
@@ -1081,11 +1079,11 @@ e
  F1 Help                                                                        
 ";
 
-        TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Application.End (rs);
+        top.Dispose ();
     }
 
-
     // TODO: This is a Dim test. Move to Dim tests.
 
     [Fact]
@@ -1132,53 +1130,53 @@ e
         }
 
         field.KeyDown += (s, k) =>
-        {
-            if (k.KeyCode == KeyCode.Enter)
-            {
-                ((FakeDriver)Application.Driver).SetBufferSize (22, count + 4);
-                Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expecteds [count], _output);
-                Assert.Equal (new Rectangle (0, 0, 22, count + 4), pos);
-
-                if (count > 0)
-                {
-                    Assert.Equal ($"Label {count - 1}", listLabels [count - 1].Text);
-                    view.Remove (listLabels [count - 1]);
-                    listLabels [count - 1].Dispose ();
-                    listLabels.RemoveAt (count - 1);
-                    Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
-                    view.Height -= 1;
-                    count--;
-
-                    if (listLabels.Count > 0)
-                    {
-                        field.Text = listLabels [count - 1].Text;
-                    }
-                    else
-                    {
-                        field.Text = string.Empty;
-                    }
-                }
-
-                Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
-            }
-        };
+                         {
+                             if (k.KeyCode == KeyCode.Enter)
+                             {
+                                 ((FakeDriver)Application.Driver).SetBufferSize (22, count + 4);
+                                 Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expecteds [count], output);
+                                 Assert.Equal (new (0, 0, 22, count + 4), pos);
+
+                                 if (count > 0)
+                                 {
+                                     Assert.Equal ($"Label {count - 1}", listLabels [count - 1].Text);
+                                     view.Remove (listLabels [count - 1]);
+                                     listLabels [count - 1].Dispose ();
+                                     listLabels.RemoveAt (count - 1);
+                                     Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
+                                     view.Height -= 1;
+                                     count--;
+
+                                     if (listLabels.Count > 0)
+                                     {
+                                         field.Text = listLabels [count - 1].Text;
+                                     }
+                                     else
+                                     {
+                                         field.Text = string.Empty;
+                                     }
+                                 }
+
+                                 Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
+                             }
+                         };
 
         Application.Iteration += (s, a) =>
-        {
-            while (count > -1)
-            {
-                field.NewKeyDownEvent (Key.Enter);
+                                 {
+                                     while (count > -1)
+                                     {
+                                         field.NewKeyDownEvent (Key.Enter);
 
-                if (count == 0)
-                {
-                    field.NewKeyDownEvent (Key.Enter);
+                                         if (count == 0)
+                                         {
+                                             field.NewKeyDownEvent (Key.Enter);
 
-                    break;
-                }
-            }
+                                             break;
+                                         }
+                                     }
 
-            Application.RequestStop ();
-        };
+                                     Application.RequestStop ();
+                                 };
 
         var win = new Window ();
         win.Add (view);
@@ -1190,6 +1188,7 @@ e
 
         Assert.Equal (0, count);
         Assert.Equal (count, listLabels.Count);
+        top.Dispose ();
     }
 
     // TODO: This is a Label test. Move to Label tests.
@@ -1200,9 +1199,10 @@ e
     {
         ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
         var text = "Label";
+
         var label = new Label
         {
-            Text = text,
+            Text = text
         };
         label.Width = Dim.Fill () - text.Length;
         label.Height = 0;
@@ -1216,6 +1216,7 @@ e
 
         Assert.Equal (5, text.Length);
         Assert.Equal (new (0, 0, 3, 0), label.Frame);
+
         //Assert.Equal (new (5, 1), label.TextFormatter.Size);
         Assert.Single (label.TextFormatter.GetLines ());
         Assert.Equal (new (0, 0, 10, 4), win.Frame);
@@ -1227,7 +1228,7 @@ e
 └────────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 10, 4), pos);
 
         text = "0123456789";
@@ -1238,6 +1239,7 @@ e
         win.Draw ();
 
         Assert.Equal (Rectangle.Empty, label.Frame);
+
         //        Assert.Equal (new (5, 1), label.TextFormatter.Size);
 
         //Exception exception = Record.Exception (
@@ -1255,7 +1257,7 @@ e
 └────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 10, 4), pos);
     }
 
@@ -1280,55 +1282,55 @@ e
         List<Label> listLabels = new ();
 
         field.KeyDown += (s, k) =>
-        {
-            if (k.KeyCode == KeyCode.Enter)
-            {
-                ((FakeDriver)Application.Driver).SetBufferSize (22, count + 4);
-                Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expecteds [count], _output);
-                Assert.Equal (new Rectangle (0, 0, 22, count + 4), pos);
-
-                if (count < 20)
-                {
-                    field.Text = $"Label {count}";
-
-                    // Label is AutoSize = true
-                    var label = new Label { Text = field.Text, X = 0, Y = view.Viewport.Height /*, Width = 10*/ };
-                    view.Add (label);
-                    Assert.Equal ($"Label {count}", label.Text);
-                    Assert.Equal ($"Absolute({count + 1})", label.Y.ToString ());
-                    listLabels.Add (label);
-
-                    //if (count == 0) {
-                    //	Assert.Equal ($"Absolute({count})", view.Height.ToString ());
-                    //	view.Height += 2;
-                    //} else {
-                    Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
-                    view.Height += 1;
-
-                    //}
-                    count++;
-                }
-
-                Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
-            }
-        };
+                         {
+                             if (k.KeyCode == KeyCode.Enter)
+                             {
+                                 ((FakeDriver)Application.Driver).SetBufferSize (22, count + 4);
+                                 Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expecteds [count], output);
+                                 Assert.Equal (new (0, 0, 22, count + 4), pos);
+
+                                 if (count < 20)
+                                 {
+                                     field.Text = $"Label {count}";
+
+                                     // Label is AutoSize = true
+                                     var label = new Label { Text = field.Text, X = 0, Y = view.Viewport.Height /*, Width = 10*/ };
+                                     view.Add (label);
+                                     Assert.Equal ($"Label {count}", label.Text);
+                                     Assert.Equal ($"Absolute({count + 1})", label.Y.ToString ());
+                                     listLabels.Add (label);
+
+                                     //if (count == 0) {
+                                     //	Assert.Equal ($"Absolute({count})", view.Height.ToString ());
+                                     //	view.Height += 2;
+                                     //} else {
+                                     Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
+                                     view.Height += 1;
+
+                                     //}
+                                     count++;
+                                 }
+
+                                 Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
+                             }
+                         };
 
         Application.Iteration += (s, a) =>
-        {
-            while (count < 21)
-            {
-                field.NewKeyDownEvent (Key.Enter);
+                                 {
+                                     while (count < 21)
+                                     {
+                                         field.NewKeyDownEvent (Key.Enter);
 
-                if (count == 20)
-                {
-                    field.NewKeyDownEvent (Key.Enter);
+                                         if (count == 20)
+                                         {
+                                             field.NewKeyDownEvent (Key.Enter);
 
-                    break;
-                }
-            }
+                                             break;
+                                         }
+                                     }
 
-            Application.RequestStop ();
-        };
+                                     Application.RequestStop ();
+                                 };
 
         var win = new Window ();
         win.Add (view);
@@ -1340,10 +1342,9 @@ e
 
         Assert.Equal (20, count);
         Assert.Equal (count, listLabels.Count);
+        top.Dispose ();
     }
 
-
-
     [Fact]
     [AutoInitShutdown]
     public void Label_IsEmpty_False_Minimum_Height ()
@@ -1376,7 +1377,7 @@ e
 └────────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 10, 4), pos);
 
         text = "0123456789";
@@ -1397,8 +1398,9 @@ e
 └────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 10, 4), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1434,7 +1436,7 @@ e
 └────────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 10, 4), pos);
 
         text = "0123456789";
@@ -1443,7 +1445,6 @@ e
         //label.Width = Dim.Fill () - text.Length;
         Application.Refresh ();
 
-
         Assert.Equal (new (0, 0, 5, 1), label.Frame);
         Assert.Equal (new (5, 1), label.TextFormatter.Size);
         Assert.Single (label.TextFormatter.GetLines ());
@@ -1455,14 +1456,15 @@ e
 └────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, 10, 4), pos);
+        top.Dispose ();
     }
 
     [Fact]
     public void Label_ResizeView_With_Dim_Absolute ()
     {
-        var super = new View ()
+        var super = new View
         {
             Width = Dim.Fill (),
             Height = Dim.Fill ()
@@ -1477,5 +1479,4 @@ e
         Assert.Equal (expectedLabelBounds, label.Viewport);
         super.Dispose ();
     }
-
 }

+ 80 - 59
UnitTests/Views/ListViewTests.cs

@@ -4,11 +4,8 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
 
-public class ListViewTests
+public class ListViewTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public ListViewTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     public void Constructors_Defaults ()
     {
@@ -17,26 +14,26 @@ public class ListViewTests
         Assert.True (lv.CanFocus);
         Assert.Equal (-1, lv.SelectedItem);
 
-        lv = new ListView { Source = new ListWrapper (new List<string> { "One", "Two", "Three" }) };
+        lv = new() { Source = new ListWrapper (new List<string> { "One", "Two", "Three" }) };
         Assert.NotNull (lv.Source);
         Assert.Equal (-1, lv.SelectedItem);
 
-        lv = new ListView { Source = new NewListDataSource () };
+        lv = new() { Source = new NewListDataSource () };
         Assert.NotNull (lv.Source);
         Assert.Equal (-1, lv.SelectedItem);
 
-        lv = new ListView
+        lv = new()
         {
             Y = 1, Width = 10, Height = 20, Source = new ListWrapper (new List<string> { "One", "Two", "Three" })
         };
         Assert.NotNull (lv.Source);
         Assert.Equal (-1, lv.SelectedItem);
-        Assert.Equal (new Rectangle (0, 1, 10, 20), lv.Frame);
+        Assert.Equal (new (0, 1, 10, 20), lv.Frame);
 
-        lv = new ListView { Y = 1, Width = 10, Height = 20, Source = new NewListDataSource () };
+        lv = new() { Y = 1, Width = 10, Height = 20, Source = new NewListDataSource () };
         Assert.NotNull (lv.Source);
         Assert.Equal (-1, lv.SelectedItem);
-        Assert.Equal (new Rectangle (0, 1, 10, 20), lv.Frame);
+        Assert.Equal (new (0, 1, 10, 20), lv.Frame);
     }
 
     [Fact]
@@ -75,10 +72,10 @@ public class ListViewTests
 │Line8     │
 │Line9     │
 └──────────┘",
-                                                      _output
+                                                      output
                                                      );
 
-        Assert.True (lv.ScrollVertical(10));
+        Assert.True (lv.ScrollVertical (10));
         lv.Draw ();
         Assert.Equal (-1, lv.SelectedItem);
 
@@ -96,7 +93,7 @@ public class ListViewTests
 │Line18    │
 │Line19    │
 └──────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (lv.MoveDown ());
@@ -117,7 +114,7 @@ public class ListViewTests
 │Line8     │
 │Line9     │
 └──────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (lv.MoveEnd ());
@@ -138,7 +135,7 @@ public class ListViewTests
 │          │
 │          │
 └──────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (lv.ScrollVertical (-20));
@@ -159,7 +156,7 @@ public class ListViewTests
 │Line8     │
 │Line9     │
 └──────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (lv.MoveDown ());
@@ -180,7 +177,7 @@ public class ListViewTests
 │Line18    │
 │Line19    │
 └──────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (lv.ScrollVertical (-20));
@@ -201,7 +198,7 @@ public class ListViewTests
 │Line8     │
 │Line9     │
 └──────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (lv.MoveDown ());
@@ -222,7 +219,7 @@ public class ListViewTests
 │Line18    │
 │Line19    │
 └──────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (lv.MoveHome ());
@@ -243,7 +240,7 @@ public class ListViewTests
 │Line8     │
 │Line9     │
 └──────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (lv.ScrollVertical (20));
@@ -264,7 +261,7 @@ public class ListViewTests
 │          │
 │          │
 └──────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.True (lv.MoveUp ());
@@ -285,8 +282,9 @@ public class ListViewTests
 │Line8     │
 │Line9     │
 └──────────┘",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -312,7 +310,7 @@ Item 1
 Item 2
 Item 3
 Item 4",
-                                                      _output
+                                                      output
                                                      );
 
         // EnsureSelectedItemVisible is auto enabled on the OnSelectedChanged
@@ -326,8 +324,9 @@ Item 3
 Item 4
 Item 5
 Item 6",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -342,13 +341,13 @@ Item 6",
         Application.Begin (top);
 
         Assert.Equal ("Second ", GetContents (0));
-        Assert.Equal (new string (' ', 7), GetContents (1));
+        Assert.Equal (new (' ', 7), GetContents (1));
 
         lv.MoveUp ();
         lv.Draw ();
 
         Assert.Equal ("First  ", GetContents (0));
-        Assert.Equal (new string (' ', 7), GetContents (1));
+        Assert.Equal (new (' ', 7), GetContents (1));
 
         string GetContents (int line)
         {
@@ -361,6 +360,7 @@ Item 6",
 
             return item;
         }
+        top.Dispose ();
     }
 
     [Fact]
@@ -417,10 +417,10 @@ Item 6",
         Assert.False (accepted);
 
         return;
+
         void OnAccept (object sender, CancelEventArgs e) { accepted = true; }
     }
 
-
     [Fact]
     public void Accept_Command_Accepts_and_Opens_Selected_Item ()
     {
@@ -430,7 +430,7 @@ Item 6",
 
         var accepted = false;
         var opened = false;
-        string selectedValue = string.Empty;
+        var selectedValue = string.Empty;
 
         listView.Accept += Accept;
         listView.OpenSelectedItem += OpenSelectedItem;
@@ -448,6 +448,7 @@ Item 6",
             opened = true;
             selectedValue = e.Value.ToString ();
         }
+
         void Accept (object sender, CancelEventArgs e) { accepted = true; }
     }
 
@@ -460,7 +461,7 @@ Item 6",
 
         var accepted = false;
         var opened = false;
-        string selectedValue = string.Empty;
+        var selectedValue = string.Empty;
 
         listView.Accept += Accept;
         listView.OpenSelectedItem += OpenSelectedItem;
@@ -503,7 +504,7 @@ Item 6",
         // bind shift down to move down twice in control
         lv.KeyBindings.Add (Key.CursorDown.WithShift, Command.LineDown, Command.LineDown);
 
-        var ev = Key.CursorDown.WithShift;
+        Key ev = Key.CursorDown.WithShift;
 
         Assert.True (lv.NewKeyDownEvent (ev), "The first time we move down 2 it should be possible");
 
@@ -535,7 +536,7 @@ Item 6",
 
         lv.KeyBindings.Add (Key.Space.WithShift, Command.Select, Command.LineDown);
 
-        var ev = Key.Space.WithShift;
+        Key ev = Key.Space.WithShift;
 
         // view should indicate that it has accepted and consumed the event
         Assert.True (lv.NewKeyDownEvent (ev));
@@ -593,7 +594,7 @@ Item 6",
         Assert.Equal (1, lw.StartsWith ("TW"));
         Assert.Equal (2, lw.StartsWith ("TH"));
 
-        lw = new ListWrapper (new List<string> { "One", "Two", "Three" });
+        lw = new (new List<string> { "One", "Two", "Three" });
 
         Assert.Equal (1, lw.StartsWith ("t"));
         Assert.Equal (1, lw.StartsWith ("tw"));
@@ -629,6 +630,7 @@ Item 6",
         lv.SetSource (source);
         lv.Draw ();
         Assert.True (rendered);
+        top.Dispose ();
     }
 
     [Fact]
@@ -654,7 +656,7 @@ Item 6",
         lv.Source = null;
         Assert.Null (lv.Source);
 
-        lv = new ListView { Source = new ListWrapper (new List<string> { "One", "Two" }) };
+        lv = new() { Source = new ListWrapper (new List<string> { "One", "Two" }) };
         Assert.NotNull (lv.Source);
 
         lv.SetSourceAsync (null);
@@ -697,6 +699,7 @@ Item 6",
     public void Clicking_On_Border_Is_Ignored ()
     {
         var selected = "";
+
         var lv = new ListView
         {
             Height = 5,
@@ -709,58 +712,70 @@ Item 6",
         top.Add (lv);
         Application.Begin (top);
 
-        Assert.Equal (new Thickness (1), lv.Border.Thickness);
+        Assert.Equal (new (1), lv.Border.Thickness);
         Assert.Equal (-1, lv.SelectedItem);
         Assert.Equal ("", lv.Text);
-        TestHelpers.AssertDriverContentsWithFrameAre (@"
+
+        TestHelpers.AssertDriverContentsWithFrameAre (
+                                                      @"
 ┌─────┐
 │One  │
 │Two  │
 │Three│
-└─────┘", _output);
+└─────┘",
+                                                      output);
 
         Application.OnMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked });
         Assert.Equal ("", selected);
         Assert.Equal (-1, lv.SelectedItem);
 
-        Application.OnMouseEvent (new ()
-        {
-            Position = new (1, 1), Flags = MouseFlags.Button1Clicked
-        });
+        Application.OnMouseEvent (
+                                  new ()
+                                  {
+                                      Position = new (1, 1), Flags = MouseFlags.Button1Clicked
+                                  });
         Assert.Equal ("One", selected);
         Assert.Equal (0, lv.SelectedItem);
 
-        Application.OnMouseEvent (new ()
-        {
-            Position = new (1, 2), Flags = MouseFlags.Button1Clicked
-        });
+        Application.OnMouseEvent (
+                                  new ()
+                                  {
+                                      Position = new (1, 2), Flags = MouseFlags.Button1Clicked
+                                  });
         Assert.Equal ("Two", selected);
         Assert.Equal (1, lv.SelectedItem);
 
-        Application.OnMouseEvent (new ()
-        {
-            Position = new (1, 3), Flags = MouseFlags.Button1Clicked
-        });
+        Application.OnMouseEvent (
+                                  new ()
+                                  {
+                                      Position = new (1, 3), Flags = MouseFlags.Button1Clicked
+                                  });
         Assert.Equal ("Three", selected);
         Assert.Equal (2, lv.SelectedItem);
 
-        Application.OnMouseEvent (new ()
-        {
-            Position = new (1, 4), Flags = MouseFlags.Button1Clicked
-        });
+        Application.OnMouseEvent (
+                                  new ()
+                                  {
+                                      Position = new (1, 4), Flags = MouseFlags.Button1Clicked
+                                  });
         Assert.Equal ("Three", selected);
         Assert.Equal (2, lv.SelectedItem);
+        top.Dispose ();
     }
 
     [Fact]
     [AutoInitShutdown]
     public void LeftItem_TopItem_Tests ()
     {
-        var source = new List<string> ();
-        for (int i = 0; i < 5; i++) {
+        List<string> source = new List<string> ();
+
+        for (var i = 0; i < 5; i++)
+        {
             source.Add ($"Item {i}");
         }
-        var lv = new ListView () {
+
+        var lv = new ListView
+        {
             X = 1,
             Width = 10,
             Height = 5,
@@ -770,20 +785,26 @@ Item 6",
         top.Add (lv);
         Application.Begin (top);
 
-        TestHelpers.AssertDriverContentsWithFrameAre (@"
+        TestHelpers.AssertDriverContentsWithFrameAre (
+                                                      @"
  Item 0
  Item 1
  Item 2
  Item 3
- Item 4", _output);
+ Item 4",
+                                                      output);
 
         lv.LeftItem = 1;
         lv.TopItem = 1;
         Application.Refresh ();
-        TestHelpers.AssertDriverContentsWithFrameAre (@"
+
+        TestHelpers.AssertDriverContentsWithFrameAre (
+                                                      @"
  tem 1
  tem 2
  tem 3
- tem 4", _output);
+ tem 4",
+                                                      output);
+        top.Dispose ();
     }
 }

File diff suppressed because it is too large
+ 229 - 211
UnitTests/Views/MenuBarTests.cs


+ 13 - 1
UnitTests/Views/OverlappedTests.cs

@@ -1,4 +1,5 @@
-using Xunit.Abstractions;
+using System.Threading;
+using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
 
@@ -100,6 +101,7 @@ public class OverlappedTests
         Assert.Empty (Application.OverlappedChildren);
         Assert.NotNull (Application.OverlappedTop);
         Assert.NotNull (Application.Top);
+        overlapped.Dispose ();
     }
 
     [Fact]
@@ -182,6 +184,7 @@ public class OverlappedTests
         Application.Run (top1);
 
         Assert.Null (Application.OverlappedChildren);
+        top1.Dispose ();
     }
 
     [Fact]
@@ -237,6 +240,7 @@ public class OverlappedTests
                                  };
 
         Application.Run (overlapped);
+        overlapped.Dispose ();
     }
 
     [Fact]
@@ -338,6 +342,7 @@ public class OverlappedTests
         Assert.Empty (Application.OverlappedChildren);
         Assert.NotNull (Application.OverlappedTop);
         Assert.NotNull (Application.Top);
+        overlapped.Dispose ();
     }
 
     [Fact]
@@ -429,6 +434,7 @@ public class OverlappedTests
         Assert.Empty (Application.OverlappedChildren);
         Assert.NotNull (Application.OverlappedTop);
         Assert.NotNull (Application.Top);
+        overlapped.Dispose ();
     }
 
     [Fact]
@@ -514,6 +520,7 @@ public class OverlappedTests
         Assert.Empty (Application.OverlappedChildren);
         Assert.NotNull (Application.OverlappedTop);
         Assert.NotNull (Application.Top);
+        overlapped.Dispose ();
     }
 
     [Fact]
@@ -609,6 +616,7 @@ public class OverlappedTests
         Assert.Empty (Application.OverlappedChildren);
         Assert.NotNull (Application.OverlappedTop);
         Assert.NotNull (Application.Top);
+        overlapped.Dispose ();
     }
 
     [Fact]
@@ -625,6 +633,7 @@ public class OverlappedTests
                             };
 
         Application.Run (overlapped);
+        overlapped.Dispose ();
     }
 
     [Fact]
@@ -703,6 +712,7 @@ public class OverlappedTests
         Assert.Empty (Application.OverlappedChildren);
         Assert.NotNull (Application.OverlappedTop);
         Assert.NotNull (Application.Top);
+        overlapped.Dispose ();
     }
 
     [Fact]
@@ -782,6 +792,7 @@ public class OverlappedTests
         Assert.Empty (Application.OverlappedChildren);
         Assert.NotNull (Application.OverlappedTop);
         Assert.NotNull (Application.Top);
+        overlapped.Dispose ();
     }
 
     [Fact]
@@ -860,6 +871,7 @@ public class OverlappedTests
         Assert.Empty (Application.OverlappedChildren);
         Assert.NotNull (Application.OverlappedTop);
         Assert.NotNull (Application.Top);
+        overlapped.Dispose ();
     }
 
     [Fact]

+ 15 - 15
UnitTests/Views/RadioGroupTests.cs

@@ -3,11 +3,8 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
 
-public class RadioGroupTests
+public class RadioGroupTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public RadioGroupTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     public void Constructors_Defaults ()
     {
@@ -17,12 +14,12 @@ public class RadioGroupTests
         Assert.Equal (Rectangle.Empty, rg.Frame);
         Assert.Equal (0, rg.SelectedItem);
 
-        rg = new RadioGroup { RadioLabels = new [] { "Test" } };
+        rg = new() { RadioLabels = new [] { "Test" } };
         Assert.True (rg.CanFocus);
         Assert.Single (rg.RadioLabels);
         Assert.Equal (0, rg.SelectedItem);
 
-        rg = new RadioGroup
+        rg = new()
         {
             X = 1,
             Y = 2,
@@ -32,10 +29,10 @@ public class RadioGroupTests
         };
         Assert.True (rg.CanFocus);
         Assert.Single (rg.RadioLabels);
-        Assert.Equal (new Rectangle (1, 2, 20, 5), rg.Frame);
+        Assert.Equal (new (1, 2, 20, 5), rg.Frame);
         Assert.Equal (0, rg.SelectedItem);
 
-        rg = new RadioGroup { X = 1, Y = 2, RadioLabels = new [] { "Test" } };
+        rg = new() { X = 1, Y = 2, RadioLabels = new [] { "Test" } };
 
         var view = new View { Width = 30, Height = 40 };
         view.Add (rg);
@@ -45,7 +42,7 @@ public class RadioGroupTests
 
         Assert.True (rg.CanFocus);
         Assert.Single (rg.RadioLabels);
-        Assert.Equal (new Rectangle (1, 2, 6, 1), rg.Frame);
+        Assert.Equal (new (1, 2, 6, 1), rg.Frame);
         Assert.Equal (0, rg.SelectedItem);
     }
 
@@ -145,6 +142,7 @@ public class RadioGroupTests
         Assert.False (accepted);
 
         return;
+
         void OnAccept (object sender, CancelEventArgs e) { accepted = true; }
     }
 
@@ -160,6 +158,7 @@ public class RadioGroupTests
         Assert.True (accepted);
 
         return;
+
         void OnAccept (object sender, CancelEventArgs e) { accepted = true; }
     }
 
@@ -195,8 +194,8 @@ public class RadioGroupTests
 └────────────────────────────┘
 ";
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (0, 0, 30, 5), pos);
 
         rg.Orientation = Orientation.Horizontal;
         Application.Refresh ();
@@ -220,8 +219,8 @@ public class RadioGroupTests
 └────────────────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (0, 0, 30, 5), pos);
 
         rg.HorizontalSpace = 4;
         Application.Refresh ();
@@ -245,8 +244,9 @@ public class RadioGroupTests
 └────────────────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (0, 0, 30, 5), pos);
+        top.Dispose ();
     }
 
     [Fact]

+ 28 - 30
UnitTests/Views/RuneCellTests.cs

@@ -3,11 +3,8 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
 
-public class RuneCellTests
+public class RuneCellTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public RuneCellTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     public void Constructor_Defaults ()
     {
@@ -24,13 +21,13 @@ public class RuneCellTests
 
         var rc2 = new RuneCell
         {
-            Rune = new Rune ('a'), ColorScheme = new ColorScheme { Normal = new Attribute (Color.Red) }
+            Rune = new ('a'), ColorScheme = new() { Normal = new (Color.Red) }
         };
         Assert.False (rc1.Equals (rc2));
         Assert.False (rc2.Equals (rc1));
 
-        rc1.Rune = new Rune ('a');
-        rc1.ColorScheme = new ColorScheme ();
+        rc1.Rune = new ('a');
+        rc1.ColorScheme = new ();
         Assert.Equal (rc1.Rune, rc2.Rune);
         Assert.False (rc1.Equals (rc2));
         Assert.False (rc2.Equals (rc1));
@@ -44,10 +41,10 @@ public class RuneCellTests
         Assert.True (rc1.Equals (rc2));
         Assert.True (rc2.Equals (rc1));
 
-        rc1.Rune = new Rune ('a');
-        rc1.ColorScheme = new ColorScheme ();
-        rc2.Rune = new Rune ('a');
-        rc2.ColorScheme = new ColorScheme ();
+        rc1.Rune = new ('a');
+        rc1.ColorScheme = new ();
+        rc2.Rune = new ('a');
+        rc2.ColorScheme = new ();
         Assert.True (rc1.Equals (rc2));
         Assert.True (rc2.Equals (rc1));
     }
@@ -64,10 +61,10 @@ public class RuneCellTests
 
             foreach (Rune rune in csName.EnumerateRunes ())
             {
-                runeCells.Add (new RuneCell { Rune = rune, ColorScheme = color.Value });
+                runeCells.Add (new() { Rune = rune, ColorScheme = color.Value });
             }
 
-            runeCells.Add (new RuneCell { Rune = (Rune)'\n', ColorScheme = color.Value });
+            runeCells.Add (new() { Rune = (Rune)'\n', ColorScheme = color.Value });
         }
 
         TextView tv = CreateTextView ();
@@ -83,7 +80,7 @@ Base
 Dialog  
 Menu    
 Error   ";
-        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, output);
 
         Attribute [] attributes =
         {
@@ -113,16 +110,16 @@ Error   ";
 
         tv.WordWrap = true;
         Application.Refresh ();
-        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, output);
         TestHelpers.AssertDriverAttributesAre (expectedColor, Application.Driver, attributes);
 
-        tv.CursorPosition = new Point (6, 2);
+        tv.CursorPosition = new (6, 2);
         tv.SelectionStartColumn = 0;
         tv.SelectionStartRow = 0;
         Assert.Equal ($"TopLevel{Environment.NewLine}Base{Environment.NewLine}Dialog", tv.SelectedText);
         tv.Copy ();
         tv.Selecting = false;
-        tv.CursorPosition = new Point (2, 4);
+        tv.CursorPosition = new (2, 4);
         tv.Paste ();
         Application.Refresh ();
 
@@ -134,7 +131,7 @@ Menu
 ErTopLevel
 Base      
 Dialogror ";
-        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, output);
 
         expectedColor = @"
 0000000000
@@ -147,7 +144,7 @@ Dialogror ";
         TestHelpers.AssertDriverAttributesAre (expectedColor, Application.Driver, attributes);
 
         tv.Undo ();
-        tv.CursorPosition = new Point (0, 3);
+        tv.CursorPosition = new (0, 3);
         tv.SelectionStartColumn = 0;
         tv.SelectionStartRow = 0;
 
@@ -157,7 +154,7 @@ Dialogror ";
                      );
         tv.Copy ();
         tv.Selecting = false;
-        tv.CursorPosition = new Point (2, 4);
+        tv.CursorPosition = new (2, 4);
         tv.Paste ();
         Application.Refresh ();
 
@@ -170,7 +167,7 @@ ErTopLevel
 Base      
 Dialog    
 ror       ";
-        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, output);
 
         expectedColor = @"
 0000000000
@@ -184,18 +181,18 @@ ror       ";
         TestHelpers.AssertDriverAttributesAre (expectedColor, Application.Driver, attributes);
 
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void RuneCell_LoadRuneCells_Without_ColorScheme_Is_Never_Null ()
     {
         List<RuneCell> cells = new ()
         {
-            new RuneCell { Rune = new Rune ('T') },
-            new RuneCell { Rune = new Rune ('e') },
-            new RuneCell { Rune = new Rune ('s') },
-            new RuneCell { Rune = new Rune ('t') }
+            new() { Rune = new ('T') },
+            new() { Rune = new ('e') },
+            new() { Rune = new ('s') },
+            new() { Rune = new ('t') }
         };
         TextView tv = CreateTextView ();
         var top = new Toplevel ();
@@ -250,7 +247,7 @@ ror       ";
                                                       @"
 This is the first line. 
 This is the second line.",
-                                                      _output
+                                                      output
                                                      );
 
         tv.Width = 10;
@@ -268,10 +265,11 @@ This is
 the    
 second 
 line.  ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.Equal (eventCount, (text [0].Count + text [1].Count) * 2);
+        top.Dispose ();
     }
 
     [Fact]
@@ -281,7 +279,7 @@ line.  ",
 
         var rc2 = new RuneCell
         {
-            Rune = new Rune ('a'), ColorScheme = new ColorScheme { Normal = new Attribute (Color.Red) }
+            Rune = new ('a'), ColorScheme = new() { Normal = new (Color.Red) }
         };
         Assert.Equal ("U+0000 '\0'; null", rc1.ToString ());
 
@@ -292,5 +290,5 @@ line.  ",
     }
 
     // TODO: Move the tests below to View or Color - they test ColorScheme, not RuneCell primitives.
-    private TextView CreateTextView () { return new TextView { Width = 30, Height = 10 }; }
+    private TextView CreateTextView () { return new() { Width = 30, Height = 10 }; }
 }

+ 49 - 11
UnitTests/Views/ScrollBarViewTests.cs

@@ -15,7 +15,8 @@ public class ScrollBarViewTests
     [ScrollBarAutoInitShutdown]
     public void AutoHideScrollBars_Check ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
 
@@ -132,6 +133,7 @@ public class ScrollBarViewTests
         Assert.Equal (79, _scrollBar.OtherScrollBarView.Viewport.Width);
         Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ());
         Assert.Equal (1, _scrollBar.OtherScrollBarView.Viewport.Height);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
@@ -214,13 +216,15 @@ public class ScrollBarViewTests
 │▼│
 └─┘";
         _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        top.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void ChangedPosition_Negative_Value ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
 
@@ -231,13 +235,16 @@ public class ScrollBarViewTests
         _scrollBar.OtherScrollBarView.Position = -50;
         Assert.Equal (0, _scrollBar.OtherScrollBarView.Position);
         Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
+
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void ChangedPosition_Scrolling ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
 
@@ -264,13 +271,15 @@ public class ScrollBarViewTests
             _scrollBar.OtherScrollBarView.Position -= 1;
             Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
         }
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void ChangedPosition_Update_The_Hosted_View ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
 
@@ -279,6 +288,7 @@ public class ScrollBarViewTests
 
         _scrollBar.OtherScrollBarView.Position = 5;
         Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
@@ -355,6 +365,7 @@ This is a tes
 ",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -605,6 +616,7 @@ This is a tes▼
 ",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -654,13 +666,15 @@ This is a test
 ",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void DrawContent_Update_The_ScrollBarView_Position ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
 
@@ -671,6 +685,7 @@ This is a test
         _hostView.Left = 6;
         _hostView.Draw ();
         Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
@@ -694,6 +709,7 @@ This is a test
 │◄├────────────────┤░░░░░░░░░░░░░░░░░░►│
 └──────────────────────────────────────┘";
         _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        top.Dispose ();
     }
 
     [Fact]
@@ -733,7 +749,6 @@ This is a test
         RemoveHandlers ();
 
         _scrollBar = new ScrollBarView (_hostView, true);
-
         Application.Begin (_hostView.SuperView as Toplevel);
 
         Assert.True (_scrollBar.IsVertical);
@@ -752,6 +767,7 @@ This is a test
         Assert.Equal (_scrollBar.Size, _hostView.Lines);
         Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
         Assert.Equal (_scrollBar.OtherScrollBarView.Size, _hostView.Cols);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
@@ -914,6 +930,7 @@ This is a test
 
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
         Assert.Equal (new Rectangle (0, 0, 10, 10), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -928,6 +945,8 @@ This is a test
 
         Assert.Throws<ArgumentException> (() => v.OtherScrollBarView = h);
         Assert.Throws<ArgumentException> (() => h.OtherScrollBarView = v);
+        top.Dispose ();
+
     }
 
     [Fact]
@@ -942,6 +961,7 @@ This is a test
 
         Assert.Throws<ArgumentException> (() => v.OtherScrollBarView = h);
         Assert.Throws<ArgumentException> (() => h.OtherScrollBarView = v);
+        top.Dispose ();
     }
 
     [Fact]
@@ -994,15 +1014,19 @@ This is a test
         Assert.Equal (99, max);
         Assert.True (sbv.Visible);
         Assert.True (sbv.OtherScrollBarView.Visible);
+        top.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void KeepContentAlwaysInViewport_False ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
+        _hostView.SuperView.LayoutSubviews ();
+        _hostView.Draw ();
 
         _scrollBar.KeepContentAlwaysInViewport = false;
         _scrollBar.Position = 50;
@@ -1016,16 +1040,20 @@ This is a test
         Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
         Assert.Equal (99, _scrollBar.OtherScrollBarView.Position);
         Assert.Equal (99, _hostView.Left);
+        _hostView.SuperView.Dispose ();
+
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void KeepContentAlwaysInViewport_True ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
-
+        _hostView.SuperView.LayoutSubviews ();
+        _hostView.Draw ();
         Assert.Equal (80, _hostView.Viewport.Width);
         Assert.Equal (25, _hostView.Viewport.Height);
         Assert.Equal (79, _scrollBar.OtherScrollBarView.Viewport.Width);
@@ -1060,19 +1088,22 @@ This is a test
         Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
         Assert.True (_scrollBar.Visible);
         Assert.True (_scrollBar.OtherScrollBarView.Visible);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void OtherScrollBarView_Not_Null ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
 
         Assert.NotNull (_scrollBar.OtherScrollBarView);
         Assert.NotEqual (_scrollBar, _scrollBar.OtherScrollBarView);
         Assert.Equal (_scrollBar.OtherScrollBarView.OtherScrollBarView, _scrollBar);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
@@ -1082,18 +1113,23 @@ This is a test
         var sbv = new ScrollBarView { Position = 1 };
         Assert.Equal (1, sbv.Position);
         Assert.NotEqual (0, sbv.Position);
+        sbv.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void ShowScrollIndicator_Check ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
+        _hostView.SuperView.LayoutSubviews ();
+        _hostView.Draw ();
 
         Assert.True (_scrollBar.ShowScrollIndicator);
         Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
@@ -1165,6 +1201,7 @@ This is a test             ",
         Assert.Equal (5, sbv.Size);
         Assert.False (sbv.ShowScrollIndicator);
         Assert.False (sbv.Visible);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1235,6 +1272,7 @@ This is a test             ",
 │▼│
 └─┘";
         _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        top.Dispose ();
     }
 
     private void _hostView_DrawContent (object sender, DrawEventArgs e)

+ 71 - 65
UnitTests/Views/ScrollViewTests.cs

@@ -3,11 +3,8 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
 
-public class ScrollViewTests
+public class ScrollViewTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public ScrollViewTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     public void Adding_Views ()
     {
@@ -36,7 +33,7 @@ public class ScrollViewTests
         top.Add (sv);
         Application.Begin (top);
 
-        Assert.Equal (new Rectangle (0, 0, 10, 10), sv.Viewport);
+        Assert.Equal (new (0, 0, 10, 10), sv.Viewport);
 
         Assert.False (sv.AutoHideScrollBars);
         Assert.True (sv.ShowHorizontalScrollIndicator);
@@ -56,13 +53,13 @@ public class ScrollViewTests
 ◄├─────┤► 
 ",
-                                             _output
+                                             output
                                             );
 
         sv.ShowHorizontalScrollIndicator = false;
-        Assert.Equal (new Rectangle (0, 0, 10, 10), sv.Viewport);
+        Assert.Equal (new (0, 0, 10, 10), sv.Viewport);
         sv.ShowVerticalScrollIndicator = true;
-        Assert.Equal (new Rectangle (0, 0, 10, 10), sv.Viewport);
+        Assert.Equal (new (0, 0, 10, 10), sv.Viewport);
 
         Assert.False (sv.AutoHideScrollBars);
         Assert.False (sv.ShowHorizontalScrollIndicator);
@@ -82,7 +79,7 @@ public class ScrollViewTests
 ",
-                                             _output
+                                             output
                                             );
 
         sv.ShowHorizontalScrollIndicator = true;
@@ -106,7 +103,7 @@ public class ScrollViewTests
          
 ◄├──────┤► 
 ",
-                                             _output
+                                             output
                                             );
 
         sv.ShowHorizontalScrollIndicator = false;
@@ -130,8 +127,9 @@ public class ScrollViewTests
          
          
 ",
-                                             _output
+                                             output
                                             );
+        top.Dispose ();
     }
 
     [Fact]
@@ -147,7 +145,7 @@ public class ScrollViewTests
         Assert.True (sv.AutoHideScrollBars);
         Assert.False (sv.ShowHorizontalScrollIndicator);
         Assert.False (sv.ShowVerticalScrollIndicator);
-        TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
+        TestHelpers.AssertDriverContentsWithFrameAre ("", output);
 
         sv.AutoHideScrollBars = false;
         sv.ShowHorizontalScrollIndicator = true;
@@ -168,8 +166,9 @@ public class ScrollViewTests
 ◄├─────┤► 
 ",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 
     // There are still issue with the lower right corner of the scroll view
@@ -211,7 +210,7 @@ public class ScrollViewTests
                        
                        
                At 15,15",
-                                                      _output
+                                                      output
                                                      );
 
         Attribute [] attributes =
@@ -265,7 +264,7 @@ public class ScrollViewTests
                        
                        
                At 15,15",
-                                                      _output
+                                                      output
                                                      );
 
         TestHelpers.AssertDriverAttributesAre (
@@ -290,7 +289,7 @@ public class ScrollViewTests
                                                attributes
                                               );
 
-        sv.ContentOffset = new Point (20, 20);
+        sv.ContentOffset = new (20, 20);
         Application.Refresh ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -311,7 +310,7 @@ public class ScrollViewTests
                        
                        
                At 15,15",
-                                                      _output
+                                                      output
                                                      );
 
         TestHelpers.AssertDriverAttributesAre (
@@ -335,6 +334,7 @@ public class ScrollViewTests
                                                null,
                                                attributes
                                               );
+        top.Dispose ();
     }
 
     [Fact]
@@ -342,16 +342,16 @@ public class ScrollViewTests
     {
         var sv = new ScrollView ();
         Assert.True (sv.CanFocus);
-        Assert.Equal (new Rectangle (0, 0, 0, 0), sv.Frame);
+        Assert.Equal (new (0, 0, 0, 0), sv.Frame);
         Assert.Equal (Rectangle.Empty, sv.Frame);
         Assert.Equal (Point.Empty, sv.ContentOffset);
         Assert.Equal (Size.Empty, sv.GetContentSize ());
         Assert.True (sv.AutoHideScrollBars);
         Assert.True (sv.KeepContentAlwaysInViewport);
 
-        sv = new ScrollView { X = 1, Y = 2, Width = 20, Height = 10 };
+        sv = new() { X = 1, Y = 2, Width = 20, Height = 10 };
         Assert.True (sv.CanFocus);
-        Assert.Equal (new Rectangle (1, 2, 20, 10), sv.Frame);
+        Assert.Equal (new (1, 2, 20, 10), sv.Frame);
         Assert.Equal (Point.Empty, sv.ContentOffset);
         Assert.Equal (sv.Viewport.Size, sv.GetContentSize ());
         Assert.True (sv.AutoHideScrollBars);
@@ -364,7 +364,7 @@ public class ScrollViewTests
     {
         ((FakeDriver)Application.Driver).SetBufferSize (30, 30);
 
-        var top = new View { Width = 30, Height = 30, ColorScheme = new ColorScheme { Normal = Attribute.Default } };
+        var top = new View { Width = 30, Height = 30, ColorScheme = new() { Normal = Attribute.Default } };
 
         Size size = new (20, 10);
 
@@ -374,7 +374,7 @@ public class ScrollViewTests
             Y = 1,
             Width = 10,
             Height = 5,
-            ColorScheme = new ColorScheme { Normal = new Attribute (Color.Red, Color.Green) }
+            ColorScheme = new() { Normal = new (Color.Red, Color.Green) }
         };
         sv.SetContentSize (size);
         string text = null;
@@ -391,7 +391,7 @@ public class ScrollViewTests
 
         var view = new View
         {
-            ColorScheme = new ColorScheme { Normal = new Attribute (Color.Blue, Color.Yellow) },
+            ColorScheme = new() { Normal = new (Color.Blue, Color.Yellow) },
             Width = Dim.Auto (DimAutoStyle.Text),
             Height = Dim.Auto (DimAutoStyle.Text),
             Text = text
@@ -417,7 +417,7 @@ public class ScrollViewTests
  *********┴
  *********▼
  ◄├──┤░░░► ",
-                                                      _output
+                                                      output
                                                      );
 
         Attribute [] attrs = { Attribute.Default, new (Color.Red, Color.Green), new (Color.Blue, Color.Yellow) };
@@ -434,6 +434,7 @@ public class ScrollViewTests
                                                null,
                                                attrs
                                               );
+        top.Dispose ();
     }
 
     [Fact]
@@ -443,7 +444,7 @@ public class ScrollViewTests
     {
         var sv = new ScrollView
         {
-            Width = 10, Height = 10,
+            Width = 10, Height = 10
         };
         sv.SetContentSize (new (50, 50));
         sv.ContentOffset = new (25, 25);
@@ -471,15 +472,16 @@ public class ScrollViewTests
 ◄░░░├─┤░► 
 ",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
     [AutoInitShutdown]
     public void ContentSize_AutoHideScrollBars_ShowHorizontalScrollIndicator_ShowVerticalScrollIndicator ()
     {
-        var sv = new ScrollView { Width = 10, Height = 10, };
+        var sv = new ScrollView { Width = 10, Height = 10 };
         sv.SetContentSize (new (50, 50));
 
         var top = new Toplevel ();
@@ -505,8 +507,9 @@ public class ScrollViewTests
 ◄├┤░░░░░► 
 ",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -570,8 +573,8 @@ public class ScrollViewTests
 "
             ;
 
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.OnKeyDown (Key.CursorRight));
         top.Draw ();
@@ -594,8 +597,8 @@ public class ScrollViewTests
 "
             ;
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.OnKeyDown (Key.CursorRight));
         top.Draw ();
@@ -618,8 +621,8 @@ public class ScrollViewTests
 "
             ;
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.OnKeyDown (Key.CursorRight));
         top.Draw ();
@@ -642,8 +645,8 @@ public class ScrollViewTests
 "
             ;
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.OnKeyDown (Key.CursorRight));
         top.Draw ();
@@ -666,8 +669,8 @@ public class ScrollViewTests
 "
             ;
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.OnKeyDown (Key.CursorRight));
         top.Draw ();
@@ -690,8 +693,8 @@ public class ScrollViewTests
 "
             ;
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.OnKeyDown (Key.CursorRight));
         top.Draw ();
@@ -714,8 +717,8 @@ public class ScrollViewTests
 "
             ;
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.OnKeyDown (Key.CursorRight));
         top.Draw ();
@@ -737,8 +740,8 @@ public class ScrollViewTests
  └──────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.OnKeyDown (Key.End.WithCtrl));
         top.Draw ();
@@ -760,8 +763,8 @@ public class ScrollViewTests
  └──────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.OnKeyDown (Key.Home.WithCtrl));
         Assert.True (scrollView.OnKeyDown (Key.CursorDown));
@@ -784,8 +787,8 @@ public class ScrollViewTests
  └──────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.OnKeyDown (Key.CursorDown));
         top.Draw ();
@@ -807,8 +810,8 @@ public class ScrollViewTests
  └──────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.OnKeyDown (Key.CursorDown));
         top.Draw ();
@@ -830,8 +833,8 @@ public class ScrollViewTests
  └──────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
 
         Assert.True (scrollView.OnKeyDown (Key.End));
         top.Draw ();
@@ -853,8 +856,9 @@ public class ScrollViewTests
  └──────────────────┘
 ";
 
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Assert.Equal (new Rectangle (1, 1, 21, 14), pos);
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Assert.Equal (new (1, 1, 21, 14), pos);
+        top.Dispose ();
     }
 
     // There still have an issue with lower right corner of the scroll view
@@ -867,7 +871,7 @@ public class ScrollViewTests
             X = 3,
             Y = 3,
             Width = 10,
-            Height = 10,
+            Height = 10
         };
         sv.SetContentSize (new (50, 50));
 
@@ -892,10 +896,10 @@ public class ScrollViewTests
    │     But░
    └────────▼
    ◄├┤░░░░░► ",
-                                                      _output
+                                                      output
                                                      );
 
-        sv.ContentOffset = new Point (5, 5);
+        sv.ContentOffset = new (5, 5);
         sv.LayoutSubviews ();
         Application.Refresh ();
 
@@ -911,14 +915,15 @@ public class ScrollViewTests
    ─────────░
     Button 4▼
    ◄├─┤░░░░► ",
-                                                      _output
+                                                      output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
     public void KeyBindings_Command ()
     {
-        var sv = new ScrollView { Width = 20, Height = 10, };
+        var sv = new ScrollView { Width = 20, Height = 10 };
         sv.SetContentSize (new (40, 20));
 
         sv.Add (
@@ -1029,7 +1034,7 @@ public class ScrollViewTests
         Assert.False (sv.OnKeyDown (Key.CursorRight));
         Assert.Equal (pointMinus39xMinus19, sv.ContentOffset);
         Assert.True (sv.OnKeyDown (Key.PageUp.WithCtrl));
-        Point pointMinus19xMinus19 = new Point (-19, -19);
+        var pointMinus19xMinus19 = new Point (-19, -19);
         Assert.Equal (pointMinus19xMinus19, sv.ContentOffset);
         Assert.True (sv.OnKeyDown (Key.Home));
         Assert.Equal (new (-19, 0), sv.ContentOffset);
@@ -1053,7 +1058,7 @@ public class ScrollViewTests
     [AutoInitShutdown]
     public void Remove_Added_View_Is_Allowed ()
     {
-        var sv = new ScrollView { Width = 20, Height = 20, };
+        var sv = new ScrollView { Width = 20, Height = 20 };
         sv.SetContentSize (new (100, 100));
 
         sv.Add (
@@ -1072,6 +1077,7 @@ public class ScrollViewTests
         Assert.Equal (4, sv.Subviews.Count);
         Assert.Single (sv.Subviews [0].Subviews);
         Assert.Equal ("View1", sv.Subviews [0].Subviews [0].Id);
+        top.Dispose ();
     }
 
     private class CustomButton : FrameView
@@ -1084,7 +1090,7 @@ public class ScrollViewTests
             Width = width;
             Height = height;
 
-            labelFill = new Label { Width = Dim.Fill (), Height = Dim.Fill (), Visible = false };
+            labelFill = new() { Width = Dim.Fill (), Height = Dim.Fill (), Visible = false };
 
             labelFill.LayoutComplete += (s, e) =>
                                         {
@@ -1106,7 +1112,7 @@ public class ScrollViewTests
                                             labelFill.Text = fillText.ToString ();
                                         };
 
-            labelText = new Label { X = Pos.Center (), Y = Pos.Center (), Text = text };
+            labelText = new() { X = Pos.Center (), Y = Pos.Center (), Text = text };
             Add (labelFill, labelText);
             CanFocus = true;
         }
@@ -1114,7 +1120,7 @@ public class ScrollViewTests
         public override bool OnEnter (View view)
         {
             Border.LineStyle = LineStyle.None;
-            Border.Thickness = new Thickness (0);
+            Border.Thickness = new (0);
             labelFill.Visible = true;
             view = this;
 
@@ -1124,7 +1130,7 @@ public class ScrollViewTests
         public override bool OnLeave (View view)
         {
             Border.LineStyle = LineStyle.Single;
-            Border.Thickness = new Thickness (1);
+            Border.Thickness = new (1);
             labelFill.Visible = false;
 
             if (view == null)

+ 3 - 0
UnitTests/Views/SpinnerViewTests.cs

@@ -42,6 +42,7 @@ public class SpinnerViewTests
         // Dispose clears timeout
         view.Dispose ();
         Assert.Empty (Application.MainLoop._timeouts);
+        Application.Top.Dispose ();
     }
 
     [Fact]
@@ -62,6 +63,7 @@ public class SpinnerViewTests
 
         expected = "/";
         TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Application.Top.Dispose ();
     }
 
     [Fact]
@@ -94,6 +96,7 @@ public class SpinnerViewTests
 
         //expected = "|";
         //TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+        Application.Top.Dispose ();
     }
 
     private SpinnerView GetSpinnerView ()

+ 9 - 9
UnitTests/Views/StatusBarTests.cs

@@ -2,11 +2,8 @@
 
 namespace Terminal.Gui.ViewsTests;
 
-public class StatusBarTests
+public class StatusBarTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper output;
-    public StatusBarTests (ITestOutputHelper output) { this.output = output; }
-
     [Fact]
     public void AddItemAt_RemoveItem_Replacing ()
     {
@@ -19,7 +16,7 @@ public class StatusBarTests
                                 }
                                );
 
-        sb.AddItemAt (2, new StatusItem (KeyCode.CtrlMask | KeyCode.Q, "~^C~ Close", null));
+        sb.AddItemAt (2, new (KeyCode.CtrlMask | KeyCode.Q, "~^C~ Close", null));
 
         Assert.Equal ("~^O~ Open", sb.Items [0].Title);
         Assert.Equal ("~^S~ Save", sb.Items [1].Title);
@@ -32,7 +29,7 @@ public class StatusBarTests
         Assert.Equal ("~^C~ Close", sb.Items [1].Title);
         Assert.Equal ("~^Q~ Quit", sb.Items [^1].Title);
 
-        sb.Items [1] = new StatusItem (KeyCode.CtrlMask | KeyCode.A, "~^A~ Save As", null);
+        sb.Items [1] = new (KeyCode.CtrlMask | KeyCode.A, "~^A~ Save As", null);
 
         Assert.Equal ("~^O~ Open", sb.Items [0].Title);
         Assert.Equal ("~^A~ Save As", sb.Items [1].Title);
@@ -67,7 +64,7 @@ public class StatusBarTests
 
         bool CanExecuteNew () { return win == null; }
 
-        void New () { win = new Window (); }
+        void New () { win = new (); }
 
         bool CanExecuteClose () { return win != null; }
 
@@ -84,6 +81,7 @@ public class StatusBarTests
         Assert.NotNull (win);
         Assert.False (CanExecuteNew ());
         Assert.True (CanExecuteClose ());
+        top.Dispose ();
     }
 
     [Fact]
@@ -108,6 +106,7 @@ public class StatusBarTests
 } Ctrl+Q to Quit!
 ";
         TestHelpers.AssertDriverContentsAre (expected, output);
+        top.Dispose ();
     }
 
     [Fact]
@@ -132,6 +131,7 @@ CTRL-O Open {
 ";
 
         TestHelpers.AssertDriverContentsAre (expected, output);
+        top.Dispose ();
     }
 
     [Fact]
@@ -163,7 +163,7 @@ CTRL-O Open {
                                      {
                                          Assert.Equal ("Quiting...", msg);
                                          msg = "";
-                                         sb.NewMouseEvent (new MouseEvent { Position = new (1, 24), Flags = MouseFlags.Button1Clicked });
+                                         sb.NewMouseEvent (new() { Position = new (1, 24), Flags = MouseFlags.Button1Clicked });
                                      }
                                      else
                                      {
@@ -200,7 +200,7 @@ CTRL-O Open {
         Assert.Equal (KeyCode.CtrlMask | KeyCode.Q, si.Shortcut);
         Assert.Equal ($"{Application.QuitKey} to Quit", si.Title);
         Assert.Null (si.Action);
-        si = new StatusItem (Application.QuitKey, $"{Application.QuitKey} to Quit", () => { });
+        si = new (Application.QuitKey, $"{Application.QuitKey} to Quit", () => { });
         Assert.NotNull (si.Action);
         Application.Shutdown ();
     }

+ 93 - 91
UnitTests/Views/TabViewTests.cs

@@ -3,11 +3,8 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
 
-public class TabViewTests
+public class TabViewTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public TabViewTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     public void AddTab_SameTabMoreThanOnce ()
     {
@@ -35,8 +32,8 @@ public class TabViewTests
         var tv = new TabView ();
         Tab tab1;
         Tab tab2;
-        tv.AddTab (tab1 = new Tab { DisplayText = "Tab1", View = new TextField { Text = "hi" } }, false);
-        tv.AddTab (tab2 = new Tab { DisplayText = "Tab1", View = new Label { Text = "hi2" } }, true);
+        tv.AddTab (tab1 = new() { DisplayText = "Tab1", View = new TextField { Text = "hi" } }, false);
+        tv.AddTab (tab2 = new() { DisplayText = "Tab1", View = new Label { Text = "hi2" } }, true);
 
         Assert.Equal (2, tv.Tabs.Count);
         Assert.Equal (tab2, tv.SelectedTab);
@@ -130,7 +127,7 @@ public class TabViewTests
 │hi                │
 └──────────────────┘
 ",
-                                             _output
+                                             output
                                             );
 
         Tab clicked = null;
@@ -146,21 +143,21 @@ public class TabViewTests
         // Waving mouse around does not trigger click
         for (var i = 0; i < 100; i++)
         {
-            args = new MouseEvent { Position = new (i, 1), Flags = MouseFlags.ReportMousePosition };
+            args = new() { Position = new (i, 1), Flags = MouseFlags.ReportMousePosition };
             Application.OnMouseEvent (args);
             Application.Refresh ();
             Assert.Null (clicked);
             Assert.Equal (tab1, tv.SelectedTab);
         }
 
-        args = new MouseEvent { Position = new (3, 1), Flags = MouseFlags.Button1Clicked };
+        args = new() { Position = new (3, 1), Flags = MouseFlags.Button1Clicked };
         Application.OnMouseEvent (args);
         Application.Refresh ();
         Assert.Equal (tab1, clicked);
         Assert.Equal (tab1, tv.SelectedTab);
 
         // Click to tab2
-        args = new MouseEvent { Position = new (6, 1), Flags = MouseFlags.Button1Clicked };
+        args = new() { Position = new (6, 1), Flags = MouseFlags.Button1Clicked };
         Application.OnMouseEvent (args);
         Application.Refresh ();
         Assert.Equal (tab2, clicked);
@@ -173,7 +170,7 @@ public class TabViewTests
                              e.MouseEvent.Handled = true;
                          };
 
-        args = new MouseEvent { Position = new (3, 1), Flags = MouseFlags.Button1Clicked };
+        args = new() { Position = new (3, 1), Flags = MouseFlags.Button1Clicked };
         Application.OnMouseEvent (args);
         Application.Refresh ();
 
@@ -181,13 +178,14 @@ public class TabViewTests
         Assert.Equal (tab1, clicked);
         Assert.Equal (tab2, tv.SelectedTab);
 
-        args = new MouseEvent { Position = new (12, 1), Flags = MouseFlags.Button1Clicked };
+        args = new() { Position = new (12, 1), Flags = MouseFlags.Button1Clicked };
         Application.OnMouseEvent (args);
         Application.Refresh ();
 
         // Clicking beyond last tab should raise event with null Tab
         Assert.Null (clicked);
         Assert.Equal (tab2, tv.SelectedTab);
+        top.Dispose ();
     }
 
     [Fact]
@@ -214,7 +212,7 @@ public class TabViewTests
 │hi   │
 └─────┘
 ",
-                                             _output
+                                             output
                                             );
 
         Tab clicked = null;
@@ -251,11 +249,11 @@ public class TabViewTests
 │hi2  │
 └─────┘
 ",
-                                             _output
+                                             output
                                             );
 
         // Click the left arrow
-        args = new MouseEvent { Position = new (0, 2), Flags = MouseFlags.Button1Clicked };
+        args = new() { Position = new (0, 2), Flags = MouseFlags.Button1Clicked };
         Application.OnMouseEvent (args);
         Application.Refresh ();
         Assert.Null (clicked);
@@ -271,8 +269,9 @@ public class TabViewTests
 │hi   │
 └─────┘
 ",
-                                             _output
+                                             output
                                             );
+        top.Dispose ();
     }
 
     [Fact]
@@ -304,7 +303,7 @@ public class TabViewTests
 │└─────┘│
 └───────┘
 ",
-                                             _output
+                                             output
                                             );
 
         Tab clicked = null;
@@ -343,11 +342,11 @@ public class TabViewTests
 │└─────┘│
 └───────┘
 ",
-                                             _output
+                                             output
                                             );
 
         // Click the left arrow
-        args = new MouseEvent { Position = new (1, 3), Flags = MouseFlags.Button1Clicked };
+        args = new() { Position = new (1, 3), Flags = MouseFlags.Button1Clicked };
         Application.OnMouseEvent (args);
         Application.Refresh ();
         Assert.Null (clicked);
@@ -365,8 +364,9 @@ public class TabViewTests
 │└─────┘│
 └───────┘
 ",
-                                             _output
+                                             output
                                             );
+        top.Dispose ();
     }
 
     [Fact]
@@ -416,7 +416,7 @@ public class TabViewTests
                                  };
 
         // Press the cursor right key to select the next tab
-        args = new Key (Key.CursorRight);
+        args = new (Key.CursorRight);
         Application.OnKeyDown (args);
         Application.Refresh ();
         Assert.Equal (tab1, oldChanged);
@@ -426,7 +426,7 @@ public class TabViewTests
         Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
 
         // Press the cursor down key to focus the selected tab view hosting
-        args = new Key (Key.CursorDown);
+        args = new (Key.CursorDown);
         Application.OnKeyDown (args);
         Application.Refresh ();
         Assert.Equal (tab2, tv.SelectedTab);
@@ -446,7 +446,7 @@ public class TabViewTests
         Assert.Null (top.Focused.MostFocused);
 
         // Press the cursor up key to focus the selected tab view hosting again
-        args = new Key (Key.CursorUp);
+        args = new (Key.CursorUp);
         Application.OnKeyDown (args);
         Application.Refresh ();
         Assert.Equal (tab2, tv.SelectedTab);
@@ -454,7 +454,7 @@ public class TabViewTests
         Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
 
         // Press the cursor up key to focus the selected tab
-        args = new Key (Key.CursorUp);
+        args = new (Key.CursorUp);
         Application.OnKeyDown (args);
         Application.Refresh ();
 
@@ -464,7 +464,7 @@ public class TabViewTests
         Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
 
         // Press the cursor left key to select the previous tab
-        args = new Key (Key.CursorLeft);
+        args = new (Key.CursorLeft);
         Application.OnKeyDown (args);
         Application.Refresh ();
         Assert.Equal (tab2, oldChanged);
@@ -474,7 +474,7 @@ public class TabViewTests
         Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
 
         // Press the end key to select the last tab
-        args = new Key (Key.End);
+        args = new (Key.End);
         Application.OnKeyDown (args);
         Application.Refresh ();
         Assert.Equal (tab1, oldChanged);
@@ -484,7 +484,7 @@ public class TabViewTests
         Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
 
         // Press the home key to select the first tab
-        args = new Key (Key.Home);
+        args = new (Key.Home);
         Application.OnKeyDown (args);
         Application.Refresh ();
         Assert.Equal (tab2, oldChanged);
@@ -494,7 +494,7 @@ public class TabViewTests
         Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
 
         // Press the page down key to select the next set of tabs
-        args = new Key (Key.PageDown);
+        args = new (Key.PageDown);
         Application.OnKeyDown (args);
         Application.Refresh ();
         Assert.Equal (tab1, oldChanged);
@@ -504,7 +504,7 @@ public class TabViewTests
         Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
 
         // Press the page up key to select the previous set of tabs
-        args = new Key (Key.PageUp);
+        args = new (Key.PageUp);
         Application.OnKeyDown (args);
         Application.Refresh ();
         Assert.Equal (tab2, oldChanged);
@@ -512,6 +512,7 @@ public class TabViewTests
         Assert.Equal (tab1, tv.SelectedTab);
         Assert.Equal (tv, top.Focused);
         Assert.Equal (tv.MostFocused, top.Focused.MostFocused);
+        top.Dispose ();
     }
 
     [Fact]
@@ -592,13 +593,13 @@ public class TabViewTests
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_False_TabsOnBottom_False_TestTabView_Width3 ()
     {
         TabView tv = GetTabView (out _, out _, false);
         tv.Width = 3;
         tv.Height = 5;
-        tv.Style = new TabStyle { ShowTopLine = false };
+        tv.Style = new() { ShowTopLine = false };
         tv.ApplyStyleChanges ();
         tv.LayoutSubviews ();
 
@@ -611,18 +612,18 @@ public class TabViewTests
 │h│
 │ │
 └─┘",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_False_TabsOnBottom_False_TestTabView_Width4 ()
     {
         TabView tv = GetTabView (out _, out _, false);
         tv.Width = 4;
         tv.Height = 5;
-        tv.Style = new TabStyle { ShowTopLine = false };
+        tv.Style = new() { ShowTopLine = false };
         tv.ApplyStyleChanges ();
         tv.LayoutSubviews ();
 
@@ -635,18 +636,18 @@ public class TabViewTests
 │hi│
 │  │
 └──┘",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_False_TabsOnBottom_False_TestThinTabView_WithLongNames ()
     {
         TabView tv = GetTabView (out Tab tab1, out Tab tab2, false);
         tv.Width = 10;
         tv.Height = 5;
-        tv.Style = new TabStyle { ShowTopLine = false };
+        tv.Style = new() { ShowTopLine = false };
         tv.ApplyStyleChanges ();
 
         // Ensures that the tab bar subview gets the bounds of the parent TabView
@@ -665,7 +666,7 @@ public class TabViewTests
 │hi      │
 │        │
 └────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         tv.SelectedTab = tab2;
@@ -679,7 +680,7 @@ public class TabViewTests
 │hi2     │
 │        │
 └────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         tv.SelectedTab = tab1;
@@ -697,7 +698,7 @@ public class TabViewTests
 │hi      │
 │        │
 └────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         //switch to tab2
@@ -711,7 +712,7 @@ public class TabViewTests
 │hi2     │
 │        │
 └────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         // now make both tabs too long
@@ -727,18 +728,18 @@ public class TabViewTests
 │hi2     │
 │        │
 └────────┘",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_False_TabsOnBottom_True_TestTabView_Width3 ()
     {
         TabView tv = GetTabView (out _, out _, false);
         tv.Width = 3;
         tv.Height = 5;
-        tv.Style = new TabStyle { ShowTopLine = false, TabsOnBottom = true };
+        tv.Style = new() { ShowTopLine = false, TabsOnBottom = true };
         tv.ApplyStyleChanges ();
         tv.LayoutSubviews ();
 
@@ -751,18 +752,18 @@ public class TabViewTests
 │ │
 │╭►
 ││ ",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_False_TabsOnBottom_True_TestTabView_Width4 ()
     {
         TabView tv = GetTabView (out _, out _, false);
         tv.Width = 4;
         tv.Height = 5;
-        tv.Style = new TabStyle { ShowTopLine = false, TabsOnBottom = true };
+        tv.Style = new() { ShowTopLine = false, TabsOnBottom = true };
         tv.ApplyStyleChanges ();
         tv.LayoutSubviews ();
 
@@ -775,18 +776,18 @@ public class TabViewTests
 │  │
 │ ╭►
 │T│ ",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_False_TabsOnBottom_True_TestThinTabView_WithLongNames ()
     {
         TabView tv = GetTabView (out Tab tab1, out Tab tab2, false);
         tv.Width = 10;
         tv.Height = 5;
-        tv.Style = new TabStyle { ShowTopLine = false, TabsOnBottom = true };
+        tv.Style = new() { ShowTopLine = false, TabsOnBottom = true };
         tv.ApplyStyleChanges ();
 
         // Ensures that the tab bar subview gets the bounds of the parent TabView
@@ -805,7 +806,7 @@ public class TabViewTests
 │        │
 │  ╭──┬──╯
 │12│13│   ",
-                                                      _output
+                                                      output
                                                      );
 
         tv.SelectedTab = tab2;
@@ -819,7 +820,7 @@ public class TabViewTests
 │        │
 ├──╮  ╭──╯
 │12│13│   ",
-                                                      _output
+                                                      output
                                                      );
 
         tv.SelectedTab = tab1;
@@ -837,7 +838,7 @@ public class TabViewTests
 │        │
 │       ╭►
 │1234567│ ",
-                                                      _output
+                                                      output
                                                      );
 
         //switch to tab2
@@ -851,7 +852,7 @@ public class TabViewTests
 │        │
 ◄  ╭─────╯
 │13│      ",
-                                                      _output
+                                                      output
                                                      );
 
         // now make both tabs too long
@@ -867,12 +868,12 @@ public class TabViewTests
 │        │
 ◄       ╭╯
 │abcdefg│ ",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_True_TabsOnBottom_False_TestTabView_Width3 ()
     {
         TabView tv = GetTabView (out _, out _, false);
@@ -889,12 +890,12 @@ public class TabViewTests
 │╰►
 │h│
 └─┘",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_True_TabsOnBottom_False_TestTabView_Width4 ()
     {
         TabView tv = GetTabView (out _, out _, false);
@@ -911,12 +912,12 @@ public class TabViewTests
 │ ╰►
 │hi│
 └──┘",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_True_TabsOnBottom_False_TestThinTabView_WithLongNames ()
     {
         TabView tv = GetTabView (out Tab tab1, out Tab tab2, false);
@@ -939,7 +940,7 @@ public class TabViewTests
 │  ╰──┴──╮
 │hi      │
 └────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         tv.SelectedTab = tab2;
@@ -953,7 +954,7 @@ public class TabViewTests
 ├──╯  ╰──╮
 │hi2     │
 └────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         tv.SelectedTab = tab1;
@@ -971,7 +972,7 @@ public class TabViewTests
 │       ╰►
 │hi      │
 └────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         //switch to tab2
@@ -985,7 +986,7 @@ public class TabViewTests
 ◄  ╰─────╮
 │hi2     │
 └────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         // now make both tabs too long
@@ -1001,12 +1002,12 @@ public class TabViewTests
 ◄       ╰╮
 │hi2     │
 └────────┘",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_True_TabsOnBottom_False_With_Unicode ()
     {
         TabView tv = GetTabView (out Tab tab1, out Tab tab2, false);
@@ -1028,7 +1029,7 @@ public class TabViewTests
 │    ╰─────────────►
 │hi                │
 └──────────────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         tv.SelectedTab = tab2;
@@ -1042,18 +1043,18 @@ public class TabViewTests
 ◄              ╰───╮
 │hi2               │
 └──────────────────┘",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_True_TabsOnBottom_True_TestTabView_Width3 ()
     {
         TabView tv = GetTabView (out _, out _, false);
         tv.Width = 3;
         tv.Height = 5;
-        tv.Style = new TabStyle { TabsOnBottom = true };
+        tv.Style = new() { TabsOnBottom = true };
         tv.ApplyStyleChanges ();
         tv.LayoutSubviews ();
 
@@ -1066,18 +1067,18 @@ public class TabViewTests
 │╭►
 ││ 
 ╰╯ ",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_True_TabsOnBottom_True_TestTabView_Width4 ()
     {
         TabView tv = GetTabView (out _, out _, false);
         tv.Width = 4;
         tv.Height = 5;
-        tv.Style = new TabStyle { TabsOnBottom = true };
+        tv.Style = new() { TabsOnBottom = true };
         tv.ApplyStyleChanges ();
         tv.LayoutSubviews ();
 
@@ -1090,18 +1091,18 @@ public class TabViewTests
 │ ╭►
 │T│ 
 ╰─╯ ",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_True_TabsOnBottom_True_TestThinTabView_WithLongNames ()
     {
         TabView tv = GetTabView (out Tab tab1, out Tab tab2, false);
         tv.Width = 10;
         tv.Height = 5;
-        tv.Style = new TabStyle { TabsOnBottom = true };
+        tv.Style = new() { TabsOnBottom = true };
         tv.ApplyStyleChanges ();
 
         // Ensures that the tab bar subview gets the bounds of the parent TabView
@@ -1120,7 +1121,7 @@ public class TabViewTests
 │  ╭──┬──╯
 │12│13│   
 ╰──┴──╯   ",
-                                                      _output
+                                                      output
                                                      );
 
         // Test first tab name too long
@@ -1136,7 +1137,7 @@ public class TabViewTests
 │       ╭►
 │1234567│ 
 ╰───────╯ ",
-                                                      _output
+                                                      output
                                                      );
 
         //switch to tab2
@@ -1150,7 +1151,7 @@ public class TabViewTests
 ◄  ╭─────╯
 │13│      
 ╰──╯      ",
-                                                      _output
+                                                      output
                                                      );
 
         // now make both tabs too long
@@ -1166,18 +1167,18 @@ public class TabViewTests
 ◄       ╭╯
 │abcdefg│ 
 ╰───────╯ ",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void ShowTopLine_True_TabsOnBottom_True_With_Unicode ()
     {
         TabView tv = GetTabView (out Tab tab1, out Tab tab2, false);
         tv.Width = 20;
         tv.Height = 5;
-        tv.Style = new TabStyle { TabsOnBottom = true };
+        tv.Style = new() { TabsOnBottom = true };
         tv.ApplyStyleChanges ();
 
         tv.LayoutSubviews ();
@@ -1195,7 +1196,7 @@ public class TabViewTests
 │    ╭─────────────►
 │Tab0│              
 ╰────╯              ",
-                                                      _output
+                                                      output
                                                      );
 
         tv.SelectedTab = tab2;
@@ -1209,7 +1210,7 @@ public class TabViewTests
 ◄              ╭───╯
 │Les Misérables│    
 ╰──────────────╯    ",
-                                                      _output
+                                                      output
                                                      );
     }
 
@@ -1222,9 +1223,9 @@ public class TabViewTests
         Tab tab4;
         Tab tab5;
 
-        tv.AddTab (tab3 = new Tab (), false);
-        tv.AddTab (tab4 = new Tab (), false);
-        tv.AddTab (tab5 = new Tab (), false);
+        tv.AddTab (tab3 = new (), false);
+        tv.AddTab (tab4 = new (), false);
+        tv.AddTab (tab5 = new (), false);
 
         tv.SelectedTab = tab1;
 
@@ -1277,7 +1278,8 @@ public class TabViewTests
         tab2.HasFocus = true;
 
         Assert.Equal (2, tv.Tabs.Count);
-        foreach (var t in tv.Tabs.ToArray ())
+
+        foreach (Tab t in tv.Tabs.ToArray ())
         {
             tv.RemoveTab (t);
         }
@@ -1300,13 +1302,13 @@ public class TabViewTests
         var tv = new TabView ();
         tv.BeginInit ();
         tv.EndInit ();
-        tv.ColorScheme = new ColorScheme ();
+        tv.ColorScheme = new ();
 
         tv.AddTab (
-                   tab1 = new Tab { DisplayText = "Tab1", View = new TextField { Width = 2, Text = "hi" } },
+                   tab1 = new() { DisplayText = "Tab1", View = new TextField { Width = 2, Text = "hi" } },
                    false
                   );
-        tv.AddTab (tab2 = new Tab { DisplayText = "Tab2", View = new Label { Text = "hi2" } }, false);
+        tv.AddTab (tab2 = new() { DisplayText = "Tab2", View = new Label { Text = "hi2" } }, false);
 
         return tv;
     }

File diff suppressed because it is too large
+ 133 - 160
UnitTests/Views/TableViewTests.cs


+ 63 - 68
UnitTests/Views/TextFieldTests.cs

@@ -2,68 +2,62 @@
 using System.Globalization;
 using System.Reflection;
 using System.Text;
-using CsvHelper;
 using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
 
-public class TextFieldTests
+public class TextFieldTests (ITestOutputHelper output)
 {
     private static TextField _textField;
-    private readonly ITestOutputHelper _output;
-    public TextFieldTests (ITestOutputHelper output) { _output = output; }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void Accented_Letter_With_Three_Combining_Unicode_Chars ()
     {
         var tf = new TextField { Width = 3, Text = "ắ" };
-        Toplevel top = new ();
-        top.Add (tf);
-        Application.Begin (top);
+        tf.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 ắ",
-                                                      _output
+                                                      output
                                                      );
 
         tf.Text = "\u1eaf";
-        Application.Refresh ();
+        tf.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 ắ",
-                                                      _output
+                                                      output
                                                      );
 
         tf.Text = "\u0103\u0301";
-        Application.Refresh ();
+        tf.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 ắ",
-                                                      _output
+                                                      output
                                                      );
 
         tf.Text = "\u0061\u0306\u0301";
-        Application.Refresh ();
+        tf.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 ắ",
-                                                      _output
+                                                      output
                                                      );
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void Adjust_First ()
     {
         var tf = new TextField { Width = Dim.Fill (), Text = "This is a test." };
-        var top = new Toplevel ();
-        top.Add (tf);
-        Application.Begin (top);
+        tf.SetRelativeLayout (new (20, 20));
+        tf.Draw ();
 
         Assert.Equal ("This is a test. ", GetContents ());
 
@@ -123,8 +117,8 @@ public class TextFieldTests
         Assert.False (fv.HasFocus);
 
         tf.NewMouseEvent (
-                       new MouseEvent { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }
-                      );
+                          new () { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }
+                         );
 
         Assert.Null (tf.SelectedText);
         Assert.False (tf.CanFocus);
@@ -137,8 +131,8 @@ public class TextFieldTests
         tf.CanFocus = true;
 
         tf.NewMouseEvent (
-                       new MouseEvent { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }
-                      );
+                          new () { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }
+                         );
 
         Assert.Equal ("some ", tf.SelectedText);
         Assert.True (tf.CanFocus);
@@ -149,14 +143,15 @@ public class TextFieldTests
         fv.CanFocus = false;
 
         tf.NewMouseEvent (
-                       new MouseEvent { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }
-                      );
+                          new () { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked }
+                         );
 
         Assert.Equal ("some ", tf.SelectedText); // Setting CanFocus to false don't change the SelectedText
         Assert.False (tf.CanFocus);
         Assert.False (tf.HasFocus);
         Assert.False (fv.CanFocus);
         Assert.False (fv.HasFocus);
+        top.Dispose ();
     }
 
     [Theory]
@@ -173,7 +168,8 @@ public class TextFieldTests
         Assert.False (tf.HasFocus);
 
         tf.Draw ();
-        TestHelpers.AssertDriverContentsAre (expectedRender, _output);
+        TestHelpers.AssertDriverContentsAre (expectedRender, output);
+        Application.Top.Dispose ();
     }
 
     [Fact]
@@ -192,7 +188,9 @@ public class TextFieldTests
         Assert.False (tf.HasFocus);
 
         tf.Draw ();
-        TestHelpers.AssertDriverContentsAre ("Misérables", _output);
+        TestHelpers.AssertDriverContentsAre ("Misérables", output);
+        Application.Top.Dispose ();
+
     }
 
     [Theory]
@@ -204,7 +202,7 @@ public class TextFieldTests
         TextField tf = GetTextFieldsInView ();
 
         tf.Draw ();
-        TestHelpers.AssertDriverContentsAre ("", _output);
+        TestHelpers.AssertDriverContentsAre ("", output);
 
         tf.Caption = "Enter txt";
         Application.Driver.SendKeys ('\t', ConsoleKey.Tab, false, false, false);
@@ -212,12 +210,13 @@ public class TextFieldTests
         // Caption should appear when not focused and no text
         Assert.False (tf.HasFocus);
         tf.Draw ();
-        TestHelpers.AssertDriverContentsAre ("Enter txt", _output);
+        TestHelpers.AssertDriverContentsAre ("Enter txt", output);
 
         // but disapear when text is added
         tf.Text = content;
         tf.Draw ();
-        TestHelpers.AssertDriverContentsAre (content, _output);
+        TestHelpers.AssertDriverContentsAre (content, output);
+        Application.Top.Dispose ();
     }
 
     [Fact]
@@ -227,19 +226,20 @@ public class TextFieldTests
         TextField tf = GetTextFieldsInView ();
 
         tf.Draw ();
-        TestHelpers.AssertDriverContentsAre ("", _output);
+        TestHelpers.AssertDriverContentsAre ("", output);
 
         // Caption has no effect when focused
         tf.Caption = "Enter txt";
         Assert.True (tf.HasFocus);
         tf.Draw ();
-        TestHelpers.AssertDriverContentsAre ("", _output);
+        TestHelpers.AssertDriverContentsAre ("", output);
 
         Application.Driver.SendKeys ('\t', ConsoleKey.Tab, false, false, false);
 
         Assert.False (tf.HasFocus);
         tf.Draw ();
-        TestHelpers.AssertDriverContentsAre ("Enter txt", _output);
+        TestHelpers.AssertDriverContentsAre ("Enter txt", output);
+        Application.Top.Dispose ();
     }
 
     [Fact]
@@ -485,8 +485,8 @@ public class TextFieldTests
 
         Assert.True (
                      tf.NewMouseEvent (
-                                    new MouseEvent { Position = new (7, 1), Flags = MouseFlags.Button1DoubleClicked, View = tf }
-                                   )
+                                       new () { Position = new (7, 1), Flags = MouseFlags.Button1DoubleClicked, View = tf }
+                                      )
                     );
         Assert.Equal ("Misérables ", tf.SelectedText);
         Assert.Equal (11, tf.SelectedLength);
@@ -494,6 +494,7 @@ public class TextFieldTests
         Assert.Equal ("Les movie.", newText);
         Assert.Equal ("Les Misérables movie.", oldText);
         Assert.Equal ("Les movie.", tf.Text);
+        top.Dispose ();
     }
 
     [Fact]
@@ -747,7 +748,6 @@ public class TextFieldTests
         Assert.Equal ("", tf.Text);
     }
 
-
     [Fact]
     public void HotKey_Command_SetsFocus ()
     {
@@ -770,6 +770,7 @@ public class TextFieldTests
         Assert.False (accepted);
 
         return;
+
         void OnAccept (object sender, CancelEventArgs e) { accepted = true; }
     }
 
@@ -793,6 +794,7 @@ public class TextFieldTests
     {
         //var super = new View ();
         var view = new TextField ();
+
         //super.Add (view);
 
         //var superAcceptedInvoked = false;
@@ -904,13 +906,6 @@ public class TextFieldTests
 
         Assert.Equal (0, tf.ScrollOffset);
         Assert.Equal (16, tf.CursorPosition);
-
-        var top = new Toplevel ();
-        top.Add (tf);
-        Application.Begin (top);
-
-        Assert.Equal (0, tf.ScrollOffset);
-        Assert.Equal (16, tf.CursorPosition);
     }
 
     [Fact]
@@ -947,6 +942,7 @@ public class TextFieldTests
 
         //                                             TAB to jump between text fields.
         TestHelpers.AssertDriverAttributesAre ("1111000", Application.Driver, attributes);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1044,7 +1040,7 @@ public class TextFieldTests
 
         // Get a fresh instance that represents a right click.
         // Should be ignored because of SuppressRightClick callback
-        mouseEvent = new MouseEvent { Flags = MouseFlags.Button3Clicked, View = tf };
+        mouseEvent = new () { Flags = MouseFlags.Button3Clicked, View = tf };
         Application.OnMouseEvent (mouseEvent);
         Assert.Equal (1, clickCounter);
 
@@ -1052,7 +1048,7 @@ public class TextFieldTests
 
         // Get a fresh instance that represents a right click.
         // Should no longer be ignored as the callback was removed
-        mouseEvent = new MouseEvent { Flags = MouseFlags.Button3Clicked, View = tf };
+        mouseEvent = new () { Flags = MouseFlags.Button3Clicked, View = tf };
 
         // In #3183 OnMouseClicked is no longer called before MouseEvent().
         // This call causes the context menu to pop, and MouseEvent() returns true.
@@ -1060,6 +1056,7 @@ public class TextFieldTests
         // Which is correct, because the user did NOT click with the left mouse button.
         Application.OnMouseEvent (mouseEvent);
         Assert.Equal (1, clickCounter);
+        top.Dispose ();
 
         return;
 
@@ -1145,7 +1142,6 @@ public class TextFieldTests
     }
 
     [Fact]
-    [TextFieldTestsAutoInitShutdown]
     public void SpaceHandling ()
     {
         var tf = new TextField { Width = 10, Text = " " };
@@ -1155,7 +1151,7 @@ public class TextFieldTests
         tf.NewMouseEvent (ev);
         Assert.Equal (1, tf.SelectedLength);
 
-        ev = new MouseEvent { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked };
+        ev = new () { Position = new (1, 0), Flags = MouseFlags.Button1DoubleClicked };
 
         tf.NewMouseEvent (ev);
         Assert.Equal (1, tf.SelectedLength);
@@ -1372,9 +1368,9 @@ public class TextFieldTests
         while (_textField.CursorPosition > 0)
         {
             _textField.NewKeyDownEvent (
-                                        new Key (
-                                                 KeyCode.CursorLeft | KeyCode.CtrlMask | KeyCode.ShiftMask
-                                                )
+                                        new (
+                                             KeyCode.CursorLeft | KeyCode.CtrlMask | KeyCode.ShiftMask
+                                            )
                                        );
 
             switch (iteration)
@@ -1446,9 +1442,9 @@ public class TextFieldTests
         while (_textField.CursorPosition > 0)
         {
             _textField.NewKeyDownEvent (
-                                        new Key (
-                                                 KeyCode.CursorLeft | KeyCode.CtrlMask | KeyCode.ShiftMask
-                                                )
+                                        new (
+                                             KeyCode.CursorLeft | KeyCode.CtrlMask | KeyCode.ShiftMask
+                                            )
                                        );
 
             switch (iteration)
@@ -1538,15 +1534,15 @@ public class TextFieldTests
 
         Assert.True (
                      tf.NewMouseEvent (
-                                    new MouseEvent { Position = new (idx, 1), Flags = MouseFlags.Button1DoubleClicked, View = tf }
-                                   )
+                                       new () { Position = new (idx, 1), Flags = MouseFlags.Button1DoubleClicked, View = tf }
+                                      )
                     );
         Assert.Equal ("movie.", tf.SelectedText);
 
         Assert.True (
                      tf.NewMouseEvent (
-                                    new MouseEvent { Position = new (idx + 1, 1), Flags = MouseFlags.Button1DoubleClicked, View = tf }
-                                   )
+                                       new () { Position = new (idx + 1, 1), Flags = MouseFlags.Button1DoubleClicked, View = tf }
+                                      )
                     );
         Assert.Equal ("movie.", tf.SelectedText);
     }
@@ -1823,37 +1819,36 @@ public class TextFieldTests
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void Words_With_Accents_Incorrect_Order_Will_Result_With_Wrong_Accent_Place ()
     {
         var tf = new TextField { Width = 30, Text = "Les Misérables" };
-        Toplevel top = new ();
-        top.Add (tf);
-        Application.Begin (top);
+        tf.SetRelativeLayout(new Size(100,100));
+        tf.Draw();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 Les Misérables",
-                                                      _output
+                                                      output
                                                      );
 
         tf.Text = "Les Mise" + char.ConvertFromUtf32 (int.Parse ("0301", NumberStyles.HexNumber)) + "rables";
-        Application.Refresh ();
+        tf.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 Les Misérables",
-                                                      _output
+                                                      output
                                                      );
 
         // incorrect order will result with a wrong accent place
         tf.Text = "Les Mis" + char.ConvertFromUtf32 (int.Parse ("0301", NumberStyles.HexNumber)) + "erables";
-        Application.Refresh ();
+        tf.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 Les Miśerables",
-                                                      _output
+                                                      output
                                                      );
     }
 
@@ -1893,9 +1888,9 @@ Les Miśerables",
             base.Before (methodUnderTest);
 
             //Application.Top.ColorScheme = Colors.ColorSchemes ["Base"];
-            _textField = new TextField
+            _textField = new ()
             {
-                ColorScheme = new ColorScheme (Colors.ColorSchemes ["Base"]),
+                ColorScheme = new (Colors.ColorSchemes ["Base"]),
 
                 //                1         2         3 
                 //      01234567890123456789012345678901=32 (Length)

File diff suppressed because it is too large
+ 137 - 238
UnitTests/Views/TextViewTests.cs


+ 0 - 3
UnitTests/Views/TileViewTests.cs

@@ -793,7 +793,6 @@ public class TileViewTests
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringInsertTile ()
     {
         TileView tv = GetTileView (20, 10);
@@ -822,7 +821,6 @@ public class TileViewTests
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRebuildForTileCount ()
     {
         TileView tv = GetTileView (20, 10);
@@ -850,7 +848,6 @@ public class TileViewTests
     }
 
     [Theory]
-    [AutoInitShutdown]
     [InlineData (0)]
     [InlineData (1)]
     public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRemoveTile (int idx)

+ 1 - 1
UnitTests/Views/TimeFieldTests.cs

@@ -36,7 +36,7 @@ public class TimeFieldTests
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [AutoInitShutdown (useFakeClipboard:true)]
     public void Copy_Paste ()
     {
         var tf1 = new TimeField { Time = TimeSpan.Parse ("12:12:19") };

+ 192 - 155
UnitTests/Views/ToplevelTests.cs

@@ -1,15 +1,10 @@
 using Xunit.Abstractions;
-using static System.Net.Mime.MediaTypeNames;
 
 namespace Terminal.Gui.ViewsTests;
 
-public class ToplevelTests
+public class ToplevelTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public ToplevelTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
-    [AutoInitShutdown]
     public void Constructor_Default ()
     {
         var top = new Toplevel ();
@@ -227,7 +222,7 @@ public class ToplevelTests
         top.OnClosed (top);
         Assert.Equal ("Closed", eventInvoked);
         top.Closing += (s, e) => eventInvoked = "Closing";
-        top.OnClosing (new ToplevelClosingEventArgs (top));
+        top.OnClosing (new (top));
         Assert.Equal ("Closing", eventInvoked);
         top.AllChildClosed += (s, e) => eventInvoked = "AllChildClosed";
         top.OnAllChildClosed ();
@@ -351,7 +346,7 @@ public class ToplevelTests
 
         top.Remove (win);
 
-        win = new Window { Width = 60, Height = 15 };
+        win = new () { Width = 60, Height = 15 };
         top.Add (win);
 
         // Application.Top without menu and status bar.
@@ -379,16 +374,20 @@ public class ToplevelTests
         Assert.NotNull (sb);
 
         top.PositionToplevels ();
-        Assert.Equal (new Rectangle (0, 1, 60, 15), win.Frame);
+        Assert.Equal (new (0, 1, 60, 15), win.Frame);
 
         //Assert.Null (Toplevel._dragPosition);
-        win.NewMouseEvent (new MouseEvent { Position = new (6, 0), Flags = MouseFlags.Button1Pressed });
+        win.NewMouseEvent (new () { Position = new (6, 0), Flags = MouseFlags.Button1Pressed });
+
         // Assert.Equal (new Point (6, 0), Toplevel._dragPosition);
-        win.NewMouseEvent (new MouseEvent { Position = new (6, 0), Flags = MouseFlags.Button1Released });
+        win.NewMouseEvent (new () { Position = new (6, 0), Flags = MouseFlags.Button1Released });
+
         //Assert.Null (Toplevel._dragPosition);
         win.CanFocus = false;
-        win.NewMouseEvent (new MouseEvent { Position = new (6, 0), Flags = MouseFlags.Button1Pressed });
+        win.NewMouseEvent (new () { Position = new (6, 0), Flags = MouseFlags.Button1Pressed });
+
         //Assert.Null (Toplevel._dragPosition);
+        top.Dispose ();
     }
 
     [Fact]
@@ -465,8 +464,8 @@ public class ToplevelTests
         Application.Begin (top);
         top.Running = true;
 
-        Assert.Equal (new Rectangle (0, 0, 40, 25), win1.Frame);
-        Assert.Equal (new Rectangle (41, 0, 40, 25), win2.Frame);
+        Assert.Equal (new (0, 0, 40, 25), win1.Frame);
+        Assert.Equal (new (41, 0, 40, 25), win2.Frame);
         Assert.Equal (win1, top.Focused);
         Assert.Equal (tf1W1, top.MostFocused);
 
@@ -540,7 +539,7 @@ public class ToplevelTests
         Assert.True (Application.OnKeyDown (Key.End.WithCtrl));
         Assert.Equal (win1, top.Focused);
         Assert.Equal (tvW1, top.MostFocused);
-        Assert.Equal (new Point (16, 1), tvW1.CursorPosition);
+        Assert.Equal (new (16, 1), tvW1.CursorPosition);
 #if UNIX_KEY_BINDINGS
         Assert.True (Application.OnKeyDown (new (Key.F.WithCtrl)));
 #else
@@ -554,6 +553,7 @@ public class ToplevelTests
 #else
         Assert.True (Application.OnKeyDown (Key.F5));
 #endif
+        top.Dispose ();
     }
 
     [Fact]
@@ -600,7 +600,7 @@ public class ToplevelTests
         Assert.True (top.IsCurrentTop);
         Assert.Equal (top, Application.OverlappedTop);
         Application.Begin (win1);
-        Assert.Equal (new Rectangle (0, 0, 40, 25), win1.Frame);
+        Assert.Equal (new (0, 0, 40, 25), win1.Frame);
         Assert.NotEqual (top, Application.Current);
         Assert.False (top.IsCurrentTop);
         Assert.Equal (win1, Application.Current);
@@ -612,7 +612,7 @@ public class ToplevelTests
         Assert.True (win1.IsOverlapped);
         Assert.Single (Application.OverlappedChildren);
         Application.Begin (win2);
-        Assert.Equal (new Rectangle (0, 0, 40, 25), win2.Frame);
+        Assert.Equal (new (0, 0, 40, 25), win2.Frame);
         Assert.NotEqual (top, Application.Current);
         Assert.False (top.IsCurrentTop);
         Assert.Equal (win2, Application.Current);
@@ -728,7 +728,7 @@ public class ToplevelTests
                     );
         Assert.Equal (win1, Application.OverlappedChildren [0]);
         Assert.Equal (tvW1, win1.MostFocused);
-        Assert.Equal (new Point (16, 1), tvW1.CursorPosition);
+        Assert.Equal (new (16, 1), tvW1.CursorPosition);
 #if UNIX_KEY_BINDINGS
         Assert.True (Application.OverlappedChildren [0].ProcessKeyDown (new (Key.F.WithCtrl)));
 #else
@@ -742,6 +742,7 @@ public class ToplevelTests
 #endif
         win2.Dispose ();
         win1.Dispose ();
+        top.Dispose ();
     }
 
     [Fact]
@@ -842,6 +843,7 @@ public class ToplevelTests
         Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.AlternateForwardKey);
         Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.AlternateBackwardKey);
         Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, Application.QuitKey);
+        top.Dispose ();
     }
 
     [Fact]
@@ -863,7 +865,7 @@ public class ToplevelTests
                                          ((FakeDriver)Application.Driver).SetBufferSize (15, 7);
 
                                          // Don't use MessageBox here; it's too complicated for this unit test; just use Window
-                                         testWindow = new Window
+                                         testWindow = new ()
                                          {
                                              Text = "Hello",
                                              X = 2,
@@ -876,7 +878,7 @@ public class ToplevelTests
                                      }
                                      else if (iterations == 1)
                                      {
-                                         Assert.Equal(new Point(2,2), Application.Current.Frame.Location);
+                                         Assert.Equal (new (2, 2), Application.Current.Frame.Location);
                                      }
                                      else if (iterations == 2)
                                      {
@@ -886,27 +888,28 @@ public class ToplevelTests
                                          Application.OnMouseEvent (new () { Position = new (3, 2), Flags = MouseFlags.Button1Pressed });
 
                                          Assert.Equal (Application.Current.Border, Application.MouseGrabView);
-                                         Assert.Equal (new Rectangle (2, 2, 10, 3), Application.Current.Frame);
+                                         Assert.Equal (new (2, 2, 10, 3), Application.Current.Frame);
                                      }
                                      else if (iterations == 3)
                                      {
                                          Assert.Equal (Application.Current.Border, Application.MouseGrabView);
 
                                          // Drag to left
-                                         Application.OnMouseEvent (new ()
-                                         {
-                                             Position = new (2, 2), Flags = MouseFlags.Button1Pressed
-                                                                   | MouseFlags.ReportMousePosition
-                                         });
+                                         Application.OnMouseEvent (
+                                                                   new ()
+                                                                   {
+                                                                       Position = new (2, 2), Flags = MouseFlags.Button1Pressed
+                                                                                                      | MouseFlags.ReportMousePosition
+                                                                   });
                                          Application.Refresh ();
 
                                          Assert.Equal (Application.Current.Border, Application.MouseGrabView);
-                                         Assert.Equal (new Rectangle (1, 2, 10, 3), Application.Current.Frame);
+                                         Assert.Equal (new (1, 2, 10, 3), Application.Current.Frame);
                                      }
                                      else if (iterations == 4)
                                      {
                                          Assert.Equal (Application.Current.Border, Application.MouseGrabView);
-                                         Assert.Equal (new Point (1, 2), Application.Current.Frame.Location);
+                                         Assert.Equal (new (1, 2), Application.Current.Frame.Location);
 
                                          Assert.Equal (Application.Current.Border, Application.MouseGrabView);
                                      }
@@ -915,23 +918,23 @@ public class ToplevelTests
                                          Assert.Equal (Application.Current.Border, Application.MouseGrabView);
 
                                          // Drag up
-                                         Application.OnMouseEvent (new ()
-                                         {
-                                             Position = new (2, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
-                                         });
+                                         Application.OnMouseEvent (
+                                                                   new ()
+                                                                   {
+                                                                       Position = new (2, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
+                                                                   });
                                          Application.Refresh ();
 
                                          Assert.Equal (Application.Current.Border, Application.MouseGrabView);
-                                         Assert.Equal (new Rectangle (1, 1, 10, 3), Application.Current.Frame);
+                                         Assert.Equal (new (1, 1, 10, 3), Application.Current.Frame);
                                      }
                                      else if (iterations == 6)
                                      {
                                          Assert.Equal (Application.Current.Border, Application.MouseGrabView);
-                                         Assert.Equal (new Point (1, 1), Application.Current.Frame.Location);
-
+                                         Assert.Equal (new (1, 1), Application.Current.Frame.Location);
 
                                          Assert.Equal (Application.Current.Border, Application.MouseGrabView);
-                                         Assert.Equal (new Rectangle (1, 1, 10, 3), Application.Current.Frame);
+                                         Assert.Equal (new (1, 1, 10, 3), Application.Current.Frame);
                                      }
                                      else if (iterations == 7)
                                      {
@@ -954,6 +957,7 @@ public class ToplevelTests
                                  };
 
         Application.Run (top);
+        top.Dispose ();
     }
 
     [Fact]
@@ -986,10 +990,11 @@ public class ToplevelTests
                                          Assert.Null (Application.MouseGrabView);
 
                                          // Grab the mouse
-                                         Application.OnMouseEvent (new MouseEvent
-                                         {
-                                             Position = new (win.Frame.X, win.Frame.Y), Flags = MouseFlags.Button1Pressed
-                                         });
+                                         Application.OnMouseEvent (
+                                                                   new ()
+                                                                   {
+                                                                       Position = new (win.Frame.X, win.Frame.Y), Flags = MouseFlags.Button1Pressed
+                                                                   });
 
                                          Assert.Equal (win.Border, Application.MouseGrabView);
                                      }
@@ -1001,11 +1006,13 @@ public class ToplevelTests
                                          movex = 1;
                                          movey = 0;
 
-                                         Application.OnMouseEvent (new MouseEvent
-                                         {
-                                             Position = new (win.Frame.X + movex, win.Frame.Y + movey), Flags = MouseFlags.Button1Pressed
-                                                                                                       | MouseFlags.ReportMousePosition
-                                         });
+                                         Application.OnMouseEvent (
+                                                                   new ()
+                                                                   {
+                                                                       Position = new (win.Frame.X + movex, win.Frame.Y + movey), Flags =
+                                                                           MouseFlags.Button1Pressed
+                                                                           | MouseFlags.ReportMousePosition
+                                                                   });
 
                                          Assert.Equal (win.Border, Application.MouseGrabView);
                                      }
@@ -1024,11 +1031,13 @@ public class ToplevelTests
                                          movex = 0;
                                          movey = -1;
 
-                                         Application.OnMouseEvent (new MouseEvent
-                                         {
-                                             Position = new (win.Frame.X + movex, win.Frame.Y + movey), Flags = MouseFlags.Button1Pressed
-                                                                                                       | MouseFlags.ReportMousePosition
-                                         });
+                                         Application.OnMouseEvent (
+                                                                   new ()
+                                                                   {
+                                                                       Position = new (win.Frame.X + movex, win.Frame.Y + movey), Flags =
+                                                                           MouseFlags.Button1Pressed
+                                                                           | MouseFlags.ReportMousePosition
+                                                                   });
 
                                          Assert.Equal (win.Border, Application.MouseGrabView);
                                      }
@@ -1047,10 +1056,12 @@ public class ToplevelTests
                                          movex = 0;
                                          movey = 0;
 
-                                         Application.OnMouseEvent (new MouseEvent
-                                         {
-                                             Position = new (win.Frame.X + movex, win.Frame.Y + movey), Flags = MouseFlags.Button1Released
-                                         });
+                                         Application.OnMouseEvent (
+                                                                   new ()
+                                                                   {
+                                                                       Position = new (win.Frame.X + movex, win.Frame.Y + movey),
+                                                                       Flags = MouseFlags.Button1Released
+                                                                   });
 
                                          Assert.Null (Application.MouseGrabView);
                                      }
@@ -1061,14 +1072,16 @@ public class ToplevelTests
                                  };
 
         Application.Run (top);
+        top.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void GetLocationThatFits_With_Border_Null_Not_Throws ()
     {
         var top = new Toplevel ();
-        Application.Begin (top);
+        top.BeginInit ();
+        top.EndInit ();
 
         Exception exception = Record.Exception (() => ((FakeDriver)Application.Driver).SetBufferSize (0, 10));
         Assert.Null (exception);
@@ -1100,6 +1113,7 @@ public class ToplevelTests
 
         // From the v view
         Assert.True (isEnter);
+
         // The Leave event is only raised on the End method
         // and the top is still running
         Assert.False (isLeave);
@@ -1120,14 +1134,17 @@ public class ToplevelTests
         isEnter = false;
 
         Application.End (rsDialog);
+        d.Dispose ();
 
         // From the v view
         Assert.True (isEnter);
+
         // From the dv view
         Assert.True (isLeave);
         Assert.True (v.HasFocus);
 
         Application.End (rsTop);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1214,6 +1231,7 @@ public class ToplevelTests
         Assert.True (isEnterDiag);
         Assert.False (isLeaveDiag);
         Assert.False (isEnterTop);
+
         // The Leave event is only raised on the End method
         // and the top is still running
         Assert.False (isLeaveTop);
@@ -1221,10 +1239,12 @@ public class ToplevelTests
         isEnterDiag = false;
         isLeaveTop = false;
         Application.End (rsDiag);
+        diag.Dispose ();
 
         Assert.False (isEnterDiag);
         Assert.True (isLeaveDiag);
         Assert.True (isEnterTop);
+
         // Leave event on top cannot be raised
         // because Current is null on the End method
         Assert.False (isLeaveTop);
@@ -1236,6 +1256,7 @@ public class ToplevelTests
         Assert.Equal (2, steps [1]);
         Assert.Equal (3, steps [2]);
         Assert.Equal (4, steps [^1]);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1259,6 +1280,7 @@ public class ToplevelTests
         Application.PositionCursor (top);
         Application.Driver.GetCursorVisibility (out cursor);
         Assert.Equal (CursorVisibility.Invisible, cursor);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1270,6 +1292,7 @@ public class ToplevelTests
 
         Application.Begin (top);
         Assert.True (top.IsLoaded);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1278,19 +1301,19 @@ public class ToplevelTests
     {
         Toplevel top = new ();
         var subTop = new Toplevel ();
-        var view = new View { Frame = new Rectangle (0, 0, 20, 10) };
+        var view = new View { Frame = new (0, 0, 20, 10) };
         subTop.Add (view);
         top.Add (subTop);
 
         Assert.False (top.IsLoaded);
         Assert.False (subTop.IsLoaded);
-        Assert.Equal (new Rectangle (0, 0, 20, 10), view.Frame);
+        Assert.Equal (new (0, 0, 20, 10), view.Frame);
 
         view.LayoutStarted += view_LayoutStarted;
 
         void view_LayoutStarted (object sender, LayoutEventArgs e)
         {
-            Assert.Equal (new Rectangle (0, 0, 20, 10), view._needsDisplayRect);
+            Assert.Equal (new (0, 0, 20, 10), view._needsDisplayRect);
             view.LayoutStarted -= view_LayoutStarted;
         }
 
@@ -1298,7 +1321,7 @@ public class ToplevelTests
 
         Assert.True (top.IsLoaded);
         Assert.True (subTop.IsLoaded);
-        Assert.Equal (new Rectangle (0, 0, 20, 10), view.Frame);
+        Assert.Equal (new (0, 0, 20, 10), view.Frame);
 
         view.Frame = new (1, 3, 10, 5);
         Assert.Equal (new (1, 3, 10, 5), view.Frame);
@@ -1308,6 +1331,7 @@ public class ToplevelTests
         view.Frame = new (1, 3, 10, 5);
         Assert.Equal (new (1, 3, 10, 5), view.Frame);
         Assert.Equal (new (0, 0, 10, 5), view._needsDisplayRect);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1319,7 +1343,7 @@ public class ToplevelTests
             X = 3,
             Y = 3,
             Width = 40,
-            Height = 16,
+            Height = 16
         };
         scrollView.SetContentSize (new (200, 100));
         var win = new Window { X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3), Arrangement = ViewArrangement.Movable };
@@ -1333,34 +1357,36 @@ public class ToplevelTests
         Assert.Equal (new (0, 0, 200, 100), scrollView.Subviews [0].Frame);
         Assert.Equal (new (3, 3, 194, 94), win.Frame);
 
-
-        Application.OnMouseEvent (new MouseEvent { Position = new (6, 6), Flags = MouseFlags.Button1Pressed });
+        Application.OnMouseEvent (new () { Position = new (6, 6), Flags = MouseFlags.Button1Pressed });
         Assert.Equal (win.Border, Application.MouseGrabView);
         Assert.Equal (new (3, 3, 194, 94), win.Frame);
 
-        Application.OnMouseEvent (new MouseEvent { Position = new (9, 9), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition });
+        Application.OnMouseEvent (new () { Position = new (9, 9), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition });
         Assert.Equal (win.Border, Application.MouseGrabView);
         top.SetNeedsLayout ();
         top.LayoutSubviews ();
-        Assert.Equal (new Rectangle (6, 6, 191, 91), win.Frame);
+        Assert.Equal (new (6, 6, 191, 91), win.Frame);
         Application.Refresh ();
 
-        Application.OnMouseEvent (new MouseEvent
-        {
-            Position = new (5, 5), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
-        });
+        Application.OnMouseEvent (
+                                  new ()
+                                  {
+                                      Position = new (5, 5), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
+                                  });
         Assert.Equal (win.Border, Application.MouseGrabView);
         top.SetNeedsLayout ();
         top.LayoutSubviews ();
-        Assert.Equal (new Rectangle (2, 2, 195, 95), win.Frame);
+        Assert.Equal (new (2, 2, 195, 95), win.Frame);
         Application.Refresh ();
 
-        Application.OnMouseEvent (new MouseEvent { Position = new (5, 5), Flags = MouseFlags.Button1Released });
+        Application.OnMouseEvent (new () { Position = new (5, 5), Flags = MouseFlags.Button1Released });
+
         // ScrollView always grab the mouse when the container's subview OnMouseEnter don't want grab the mouse
         Assert.Equal (scrollView, Application.MouseGrabView);
 
-        Application.OnMouseEvent (new MouseEvent { Position = new (4, 4), Flags = MouseFlags.ReportMousePosition });
+        Application.OnMouseEvent (new () { Position = new (4, 4), Flags = MouseFlags.ReportMousePosition });
         Assert.Equal (scrollView, Application.MouseGrabView);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1368,75 +1394,81 @@ public class ToplevelTests
     public void Window_Viewport_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_Left_Right_And_Bottom ()
     {
         Toplevel top = new ();
-        var window = new Window { Width = 20, Height = 3, Arrangement = ViewArrangement.Movable};
+        var window = new Window { Width = 20, Height = 3, Arrangement = ViewArrangement.Movable };
         RunState rsTop = Application.Begin (top);
         ((FakeDriver)Application.Driver).SetBufferSize (40, 10);
         RunState rsWindow = Application.Begin (window);
         Application.Refresh ();
-        Assert.Equal (new Rectangle (0, 0, 40, 10), top.Frame);
-        Assert.Equal (new Rectangle (0, 0, 20, 3), window.Frame);
+        Assert.Equal (new (0, 0, 40, 10), top.Frame);
+        Assert.Equal (new (0, 0, 20, 3), window.Frame);
 
         Assert.Null (Application.MouseGrabView);
 
-        Application.OnMouseEvent (new MouseEvent { Position = new (0, 0), Flags = MouseFlags.Button1Pressed });
+        Application.OnMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Pressed });
 
         Assert.Equal (window.Border, Application.MouseGrabView);
 
-        Application.OnMouseEvent (new MouseEvent
-        {
-            Position = new (-11, -4), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
-        });
+        Application.OnMouseEvent (
+                                  new ()
+                                  {
+                                      Position = new (-11, -4), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
+                                  });
 
         Application.Refresh ();
-        Assert.Equal (new Rectangle (0, 0, 40, 10), top.Frame);
-        Assert.Equal (new Rectangle (0, 0, 20, 3), window.Frame);
+        Assert.Equal (new (0, 0, 40, 10), top.Frame);
+        Assert.Equal (new (0, 0, 20, 3), window.Frame);
 
         // Changes Top size to same size as Dialog more menu and scroll bar
         ((FakeDriver)Application.Driver).SetBufferSize (20, 3);
 
-        Application.OnMouseEvent (new MouseEvent
-        {
-            Position = new (-1, -1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
-        });
+        Application.OnMouseEvent (
+                                  new ()
+                                  {
+                                      Position = new (-1, -1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
+                                  });
 
         Application.Refresh ();
-        Assert.Equal (new Rectangle (0, 0, 20, 3), top.Frame);
-        Assert.Equal (new Rectangle (0, 0, 20, 3), window.Frame);
+        Assert.Equal (new (0, 0, 20, 3), top.Frame);
+        Assert.Equal (new (0, 0, 20, 3), window.Frame);
 
         // Changes Top size smaller than Dialog size
         ((FakeDriver)Application.Driver).SetBufferSize (19, 2);
 
-        Application.OnMouseEvent (new MouseEvent
-        {
-            Position = new (-1, -1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
-        });
+        Application.OnMouseEvent (
+                                  new ()
+                                  {
+                                      Position = new (-1, -1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
+                                  });
 
         Application.Refresh ();
-        Assert.Equal (new Rectangle (0, 0, 19, 2), top.Frame);
-        Assert.Equal (new Rectangle (-1, 0, 20, 3), window.Frame);
+        Assert.Equal (new (0, 0, 19, 2), top.Frame);
+        Assert.Equal (new (-1, 0, 20, 3), window.Frame);
 
-        Application.OnMouseEvent (new MouseEvent
-        {
-            Position = new (18, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
-        });
+        Application.OnMouseEvent (
+                                  new ()
+                                  {
+                                      Position = new (18, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
+                                  });
 
         Application.Refresh ();
-        Assert.Equal (new Rectangle (0, 0, 19, 2), top.Frame);
-        Assert.Equal (new Rectangle (18, 1, 20, 3), window.Frame);
+        Assert.Equal (new (0, 0, 19, 2), top.Frame);
+        Assert.Equal (new (18, 1, 20, 3), window.Frame);
 
         // On a real app we can't go beyond the SuperView bounds
-        Application.OnMouseEvent (new MouseEvent
-        {
-            Position = new (19, 2), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
-        });
+        Application.OnMouseEvent (
+                                  new ()
+                                  {
+                                      Position = new (19, 2), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
+                                  });
 
         Application.Refresh ();
-        Assert.Equal (new Rectangle (0, 0, 19, 2), top.Frame);
-        Assert.Equal (new Rectangle (19, 2, 20, 3), window.Frame);
-        TestHelpers.AssertDriverContentsWithFrameAre (@"", _output);
+        Assert.Equal (new (0, 0, 19, 2), top.Frame);
+        Assert.Equal (new (19, 2, 20, 3), window.Frame);
+        TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
 
         Application.End (rsWindow);
         Application.End (rsTop);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1462,27 +1494,29 @@ public class ToplevelTests
         RunState rs = Application.Begin (window);
 
         Assert.Null (Application.MouseGrabView);
-        Assert.Equal (new Rectangle (0, 0, 10, 3), window.Frame);
+        Assert.Equal (new (0, 0, 10, 3), window.Frame);
 
-        Application.OnMouseEvent (new MouseEvent { Position = new (0, 0), Flags = MouseFlags.Button1Pressed });
+        Application.OnMouseEvent (new () { Position = new (0, 0), Flags = MouseFlags.Button1Pressed });
 
         var firstIteration = false;
         Application.RunIteration (ref rs, ref firstIteration);
         Assert.Equal (window.Border, Application.MouseGrabView);
 
-        Assert.Equal (new Rectangle (0, 0, 10, 3), window.Frame);
+        Assert.Equal (new (0, 0, 10, 3), window.Frame);
 
-        Application.OnMouseEvent (new MouseEvent
-        {
-            Position = new (1, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
-        });
+        Application.OnMouseEvent (
+                                  new ()
+                                  {
+                                      Position = new (1, 1), Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
+                                  });
 
         firstIteration = false;
         Application.RunIteration (ref rs, ref firstIteration);
         Assert.Equal (window.Border, Application.MouseGrabView);
-        Assert.Equal (new Rectangle (1, 1, 10, 3), window.Frame);
+        Assert.Equal (new (1, 1, 10, 3), window.Frame);
 
         Application.End (rs);
+        window.Dispose ();
     }
 
     [Fact]
@@ -1494,13 +1528,14 @@ public class ToplevelTests
         ((FakeDriver)Application.Driver).SetBufferSize (20, 20);
 
         var testWindow = new Window { X = 2, Y = 1, Width = 15, Height = 10 };
-        Assert.Equal (new Rectangle (2, 1, 15, 10), testWindow.Frame);
+        Assert.Equal (new (2, 1, 15, 10), testWindow.Frame);
 
         RunState rsTestWindow = Application.Begin (testWindow);
-        Assert.Equal (new Rectangle (2, 1, 15, 10), testWindow.Frame);
+        Assert.Equal (new (2, 1, 15, 10), testWindow.Frame);
 
         Application.End (rsTestWindow);
         Application.End (rsTop);
+        top.Dispose ();
     }
 
     // Don't use Dialog as a Top, use a Window instead - dialog has complex layout behavior that is not needed here.
@@ -1514,50 +1549,50 @@ public class ToplevelTests
         RunState rsTop = Application.Begin (top);
         ((FakeDriver)Application.Driver).SetBufferSize (20, 20);
 
-        Assert.Equal (new Rectangle (0, 0, 20, 20), win.Frame);
+        Assert.Equal (new (0, 0, 20, 20), win.Frame);
 
         var btnPopup = new Button { Text = "Popup" };
         var testWindow = new Window { X = 2, Y = 1, Width = 15, Height = 10 };
         testWindow.Add (btnPopup);
 
         btnPopup.Accept += (s, e) =>
-                            {
-                                Rectangle viewToScreen = btnPopup.ViewportToScreen (top.Frame);
-
-                                var viewAddedToTop = new View
-                                {
-                                    Text = "viewAddedToTop",
-                                    X = 1,
-                                    Y = viewToScreen.Y + 1,
-                                    Width = 18,
-                                    Height = 16,
-                                    BorderStyle = LineStyle.Single
-                                };
-                                Assert.Equal (testWindow, Application.Current);
-                                Application.Current.DrawContentComplete += OnDrawContentComplete;
-                                top.Add (viewAddedToTop);
-
-                                void OnDrawContentComplete (object sender, DrawEventArgs e)
-                                {
-                                    Assert.Equal (new Rectangle (1, 3, 18, 16), viewAddedToTop.Frame);
-
-                                    Rectangle savedClip = Application.Driver.Clip;
-                                    Application.Driver.Clip = top.Frame;
-                                    viewAddedToTop.Draw ();
-                                    top.Move (2, 15);
-                                    View.Driver.AddStr ("One");
-                                    top.Move (2, 16);
-                                    View.Driver.AddStr ("Two");
-                                    top.Move (2, 17);
-                                    View.Driver.AddStr ("Three");
-                                    Application.Driver.Clip = savedClip;
-
-                                    Application.Current.DrawContentComplete -= OnDrawContentComplete;
-                                }
-                            };
+                           {
+                               Rectangle viewToScreen = btnPopup.ViewportToScreen (top.Frame);
+
+                               var viewAddedToTop = new View
+                               {
+                                   Text = "viewAddedToTop",
+                                   X = 1,
+                                   Y = viewToScreen.Y + 1,
+                                   Width = 18,
+                                   Height = 16,
+                                   BorderStyle = LineStyle.Single
+                               };
+                               Assert.Equal (testWindow, Application.Current);
+                               Application.Current.DrawContentComplete += OnDrawContentComplete;
+                               top.Add (viewAddedToTop);
+
+                               void OnDrawContentComplete (object sender, DrawEventArgs e)
+                               {
+                                   Assert.Equal (new (1, 3, 18, 16), viewAddedToTop.Frame);
+
+                                   Rectangle savedClip = Application.Driver.Clip;
+                                   Application.Driver.Clip = top.Frame;
+                                   viewAddedToTop.Draw ();
+                                   top.Move (2, 15);
+                                   View.Driver.AddStr ("One");
+                                   top.Move (2, 16);
+                                   View.Driver.AddStr ("Two");
+                                   top.Move (2, 17);
+                                   View.Driver.AddStr ("Three");
+                                   Application.Driver.Clip = savedClip;
+
+                                   Application.Current.DrawContentComplete -= OnDrawContentComplete;
+                               }
+                           };
         RunState rsTestWindow = Application.Begin (testWindow);
 
-        Assert.Equal (new Rectangle (2, 1, 15, 10), testWindow.Frame);
+        Assert.Equal (new (2, 1, 15, 10), testWindow.Frame);
 
         Application.OnMouseEvent (new () { Position = new (5, 2), Flags = MouseFlags.Button1Clicked });
         Application.Top.Draw ();
@@ -1587,11 +1622,12 @@ public class ToplevelTests
 ││Three           ││
 │└────────────────┘│
 └──────────────────┘",
-                                                      _output
+                                                      output
                                                      );
 
         Application.End (rsTestWindow);
         Application.End (rsTop);
+        top.Dispose ();
     }
 
     private void OnDrawContentComplete (object sender, DrawEventArgs e) { throw new NotImplementedException (); }
@@ -1604,7 +1640,7 @@ public class ToplevelTests
         {
             Menus =
             [
-                new MenuBarItem ("Child", new MenuItem [] { new ("_Create Child", "", null) })
+                new ("Child", new MenuItem [] { new ("_Create Child", "", null) })
             ]
         };
         var topChild = new Toplevel ();
@@ -1615,6 +1651,7 @@ public class ToplevelTests
 
         Exception exception = Record.Exception (() => topChild.NewKeyDownEvent (KeyCode.AltMask));
         Assert.Null (exception);
+        top.Dispose ();
     }
 
     [Fact]

+ 6 - 2
UnitTests/Views/TreeTableSourceTests.cs

@@ -26,9 +26,10 @@ public class TreeTableSourceTests : IDisposable
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void TestTreeTableSource_BasicExpanding_WithKeyboard ()
     {
+        ((FakeDriver)Application.Driver).SetBufferSize (100, 100);
         TableView tv = GetTreeTable (out _);
 
         tv.Style.GetOrCreateColumnStyle (1).MinAcceptableWidth = 1;
@@ -84,9 +85,11 @@ public class TreeTableSourceTests : IDisposable
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void TestTreeTableSource_BasicExpanding_WithMouse ()
     {
+        ((FakeDriver)Application.Driver).SetBufferSize (100, 100);
+
         TableView tv = GetTreeTable (out _);
 
         tv.Style.GetOrCreateColumnStyle (1).MinAcceptableWidth = 1;
@@ -223,6 +226,7 @@ public class TreeTableSourceTests : IDisposable
 
         Assert.Equal ("Ford Trans-Am", selected.Name);
         Assert.Equal ("Talking thunderbird car", selected.Description);
+        top.Dispose ();
     }
 
     private TableView GetTreeTable (out TreeView<IDescribedThing> tree)

+ 12 - 42
UnitTests/Views/TreeViewTests.cs

@@ -32,8 +32,6 @@ public class TreeViewTests
 
         tree.Viewport = new Rectangle (0, 0, 10, 10);
 
-        InitFakeDriver ();
-
         //-+Factory
         Assert.Equal (9, tree.GetContentWidth (true));
 
@@ -49,7 +47,6 @@ public class TreeViewTests
         //-+Factory
         Assert.Equal (9, tree.GetContentWidth (true));
 
-        Application.Shutdown ();
     }
 
     [Fact]
@@ -62,8 +59,6 @@ public class TreeViewTests
         // control only allows 1 row to be viewed at once
         tree.Viewport = new Rectangle (0, 0, 20, 1);
 
-        InitFakeDriver ();
-
         //-+Factory
         Assert.Equal (9, tree.GetContentWidth (true));
         Assert.Equal (9, tree.GetContentWidth (false));
@@ -95,8 +90,6 @@ public class TreeViewTests
         tree.ScrollOffsetVertical = 5;
         Assert.Equal (0, tree.GetContentWidth (true));
         Assert.Equal (13, tree.GetContentWidth (false));
-
-        Application.Shutdown ();
     }
 
     [Fact]
@@ -124,6 +117,7 @@ public class TreeViewTests
         Application.Driver.GetCursorVisibility (out CursorVisibility visibility);
         Assert.Equal (CursorVisibility.Default, tv.CursorVisibility);
         Assert.Equal (CursorVisibility.Default, visibility);
+        top.Dispose ();
     }
 
     [Fact]
@@ -290,7 +284,6 @@ public class TreeViewTests
 
         Assert.False (tree.IsExpanded (c));
 
-        Application.Shutdown ();
     }
 
     /// <summary>Tests that <see cref="TreeView.Expand(object)"/> and <see cref="TreeView.IsExpanded(object)"/> are consistent</summary>
@@ -358,8 +351,6 @@ public class TreeViewTests
     {
         TreeView<object> tree = CreateTree (out Factory f, out Car car1, out _);
 
-        InitFakeDriver ();
-
         object activated = null;
         var called = false;
 
@@ -385,17 +376,14 @@ public class TreeViewTests
 
         Assert.True (called);
         Assert.Same (f, activated);
-
-        Application.Shutdown ();
     }
 
     [Fact]
+
     public void ObjectActivated_CustomKey ()
     {
         TreeView<object> tree = CreateTree (out Factory f, out Car car1, out _);
 
-        InitFakeDriver ();
-
         tree.ObjectActivationKey = KeyCode.Delete;
         object activated = null;
         var called = false;
@@ -430,7 +418,6 @@ public class TreeViewTests
         Assert.True (called);
         Assert.Same (f, activated);
 
-        Application.Shutdown ();
     }
 
     [Fact]
@@ -438,8 +425,6 @@ public class TreeViewTests
     {
         TreeView<object> tree = CreateTree (out Factory f, out Car car1, out _);
 
-        InitFakeDriver ();
-
         object activated = null;
         var called = false;
 
@@ -459,7 +444,6 @@ public class TreeViewTests
         Assert.Same (f, activated);
         Assert.Same (f, tree.SelectedObject);
 
-        Application.Shutdown ();
     }
 
     [Fact]
@@ -467,8 +451,6 @@ public class TreeViewTests
     {
         TreeView<object> tree = CreateTree (out Factory f, out Car car1, out _);
 
-        InitFakeDriver ();
-
         tree.ObjectActivationButton = MouseFlags.Button2Clicked;
         tree.ExpandAll ();
 
@@ -495,8 +477,6 @@ public class TreeViewTests
         Assert.True (called);
         Assert.Same (car1, activated);
         Assert.Same (car1, tree.SelectedObject);
-
-        Application.Shutdown ();
     }
 
     [Fact]
@@ -504,7 +484,6 @@ public class TreeViewTests
     {
         TreeView<object> tree = CreateTree (out Factory f, out Car car1, out _);
 
-        InitFakeDriver ();
 
         // disable activation
         tree.ObjectActivationButton = null;
@@ -527,8 +506,6 @@ public class TreeViewTests
         Assert.False (called);
         Assert.Null (activated);
         Assert.Null (tree.SelectedObject);
-
-        Application.Shutdown ();
     }
 
     /// <summary>
@@ -716,7 +693,7 @@ public class TreeViewTests
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void TestBottomlessTreeView_MaxDepth_3 ()
     {
         TreeView<string> tv = new () { Width = 20, Height = 10 };
@@ -754,7 +731,7 @@ public class TreeViewTests
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void TestBottomlessTreeView_MaxDepth_5 ()
     {
         TreeView<string> tv = new () { Width = 20, Height = 10 };
@@ -821,7 +798,7 @@ public class TreeViewTests
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void TestGetObjectOnRow ()
     {
         var tv = new TreeView { Width = 20, Height = 10 };
@@ -876,7 +853,7 @@ public class TreeViewTests
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void TestGetObjectRow ()
     {
         var tv = new TreeView { Width = 20, Height = 10 };
@@ -944,7 +921,7 @@ public class TreeViewTests
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void TestTreeView_DrawLineEvent ()
     {
         var tv = new TreeView { Width = 20, Height = 10 };
@@ -1010,7 +987,7 @@ public class TreeViewTests
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void TestTreeView_DrawLineEvent_Handled ()
     {
         var tv = new TreeView { Width = 20, Height = 10 };
@@ -1056,7 +1033,7 @@ FFFFFFFFFF
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void TestTreeView_DrawLineEvent_WithScrolling ()
     {
         var tv = new TreeView { Width = 20, Height = 10 };
@@ -1119,7 +1096,7 @@ oot two
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void TestTreeView_Filter ()
     {
         var tv = new TreeView { Width = 20, Height = 10 };
@@ -1203,7 +1180,7 @@ oot two
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [SetupFakeDriver]
     public void TestTreeViewColor ()
     {
         var tv = new TreeView { Width = 20, Height = 10 };
@@ -1303,13 +1280,6 @@ oot two
         Assert.Equal (2, tree.GetChildren (root).Count ());
     }
 
-    private void InitFakeDriver ()
-    {
-        var driver = new FakeDriver ();
-        Application.Init (driver);
-        driver.Init ();
-    }
-
     /// <summary>Test object which considers for equality only <see cref="Name"/></summary>
     private class EqualityTestObject
     {
@@ -1424,7 +1394,7 @@ oot two
 
         Assert.True (accepted);
         Assert.False (activated);
-        Assert.Equal (null, selectedObject);
+        Assert.Null (selectedObject);
 
         return;
 

+ 10 - 12
UnitTests/Views/ViewDisposalTest.cs

@@ -3,13 +3,11 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
 
-public class ViewDisposalTest
+public class ViewDisposalTest (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
 #nullable enable
     private readonly Dictionary<Type, object? []?> _special_params = new ();
 #nullable restore
-    public ViewDisposalTest (ITestOutputHelper output) { _output = output; }
 
     [Fact]
     [AutoInitShutdown]
@@ -34,7 +32,7 @@ public class ViewDisposalTest
     private WeakReference DoTest ()
     {
         GetSpecialParams ();
-        var Container = new View ();
+        var container = new View ();
         Toplevel top = new ();
         List<Type> views = GetViews ();
 
@@ -53,11 +51,11 @@ public class ViewDisposalTest
             }
 
             Assert.NotNull (instance);
-            Container.Add (instance);
-            _output.WriteLine ($"Added instance of {view}!");
+            container.Add (instance);
+            output.WriteLine ($"Added instance of {view}!");
         }
 
-        top.Add (Container);
+        top.Add (container);
 
         // make sure the application is doing to the views whatever its supposed to do to the views
         for (var i = 0; i < 100; i++)
@@ -65,9 +63,9 @@ public class ViewDisposalTest
             Application.Refresh ();
         }
 
-        top.Remove (Container);
-        WeakReference reference = new (Container, true);
-        Container.Dispose ();
+        top.Remove (container);
+        WeakReference reference = new (container, true);
+        container.Dispose ();
 
         return reference;
     }
@@ -101,11 +99,11 @@ public class ViewDisposalTest
                                               }
                                              )) //end of body of anonymous check function
         { //body of the foreach loop
-            _output.WriteLine ($"Found Type {type.Name}");
+            output.WriteLine ($"Found Type {type.Name}");
             Assert.DoesNotContain (type, valid);
             Assert.True (type.IsAssignableTo (typeof (IDisposable))); // Just to be safe
             valid.Add (type);
-            _output.WriteLine ("	-Added!");
+            output.WriteLine ("	-Added!");
         } //end body of foreach loop
 
         return valid;

+ 3 - 0
UnitTests/Views/WindowTests.cs

@@ -26,6 +26,7 @@ public class WindowTests
 
         Exception exception = Record.Exception (() => win.NewKeyDownEvent (KeyCode.AltMask));
         Assert.Null (exception);
+        top.Dispose ();
     }
 
     [Fact]
@@ -119,6 +120,7 @@ public class WindowTests
 └──────────────────┘",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -224,5 +226,6 @@ public class WindowTests
         Assert.True (view1.HasFocus);
         Assert.False (win2.HasFocus);
         Assert.False (view2.HasFocus);
+        win1.Dispose ();
     }
 }

+ 6 - 4
docfx/docs/newinv2.md

@@ -19,10 +19,12 @@ Apps built with Terminal.Gui now feel modern thanks to these improvements:
 The entire library has been reviewed and simplified. As a result, the API is more consistent and uses modern .NET API standards (e.g. for events). This refactoring resulted in the removal of thousands of lines of code, better unit tests, and higher performance than v1. See [Simplified API](overview.md#simplified-api) for details.
 
 ## `View` Improvements
-
-* *Life Cycle Management* - 
-  * In v1, `View` was derived from `Responder` which supported `IDisposable`. In v2, `Responder` has been removed and `View` is the base-class supporting `IDisposable`. 
-  * `Application.Init` no longer automatically creates a toplevel or sets `Applicaton.Top`; app developers must explicitly create the toplevel view and pass it to `Appliation.Run` (or use `Application.Run<myTopLevel>`). Developers are responsible for calling `Dispose` on any toplevel they create before exiting. 
+* *View Lifetime Management is Now Deterministic* - In v1 the rules ofr lifetime management of `View` objects was unclear and led to non-dterministic behavior and hard to diagnose bugs. This was particularly acute in the behavior of `Application.Run`. In v2, the rules are clear and the code and unit test infrastructure tries to enforce them. 
+  * `View` and all subclasses support `IDisposable` and must be disposed (by calling `view.Dispose ()`) by whatever code owns the instance when the instance is longer needed. 
+  * To simplify programming, any `View` added as a Subview another `View` will have it's lifecycle owned by the Superview; when a `View` is disposed, it will call `Dispose` on all the items in the `Subviews` property. Note this behavior is the same as it was in v1, just clarified.
+  * In v1, `Application.End` called `Dispose ()` on `Application.Top` (via `Runstate.Toplevel`). This was incorrect as it meant that after `Application.Run` returned, `Application.Top` had been disposed, and any code that wanted to interogate the results of `Run` by accessing `Application.Top` only worked by accident. This is because GC had not actually happened; if it had the application would have crashed. In v2 `Application.End` does NOT call `Dispose`, and it is the caller to `Application.Run` who is responsible for disposing the `Toplevel` that was either passed to `Application.Run (View)` or created by `Application.Run<T> ()`.
+	* Any code that creates a `Toplevel`, either by using `top = new()` or by calling either `top = Application.Run ()` or `top = ApplicationRun<T>()` must call `top.Dispose` when complete.
+  	*  The exception to this is if `top` is passed to `myView.Add(top)` making it a subview of `myView`. This is because the semantics of `Add` are that the `myView` takes over responsibility for the subviews lifetimes. Of course, if someone calls `myView.Remove(top)` to remove said subview, they then re-take responsbility for `top`'s lifetime and they must call `top.Dispose`.
 * New! *Adornments* -  Adornments are a special form of View that appear outside the `Viewport`: `Margin`, `Border`, and `Padding`.
 * New! *Built-in Scrolling/Virtual Content Area* - In v1, to have a view a user could scroll required either a bespoke scrolling implementation, inheriting from `ScrollView`, or managing the complexity of `ScrollBarView` directly. In v2, the base-View class supports scrolling inherently. The area of a view visible to the user at a given moment was previously a rectangle called `Bounds`. `Bounds.Location` was always `Point.Empty`. In v2 the visible area is a rectangle called `Viewport` which is a protal into the Views content, which can be bigger (or smaller) than the area visible to the user. Causing a view to scroll is as simple as changing `View.Viewport.Location`. The View's content described by `View.GetContentSize()`. See [Layout](layout.md) for details.
 * New! *`Dim.Auto`* - Automatically sizes the view to fitthe view's Text, SubViews, or ContentArea.

Some files were not shown because too many files changed in this diff