Browse Source

Complete Rows/Cols read-only refactor - fix all test files

- Fixed all test files to use SetScreenSize() instead of setting Rows/Cols
- Updated ApplicationTests, ApplicationScreenTests, AddRuneTests, ClipRegionTests, ConsoleDriverTests
- All UnitTests now build and FakeDriver tests pass (21/21)
- Source of truth is now IConsoleDriver.Screen via backing fields

Work items for future:
- Rename OnSizeChanged to OnScreenChanged
- Fix AutoInitShutdownAttribute.FakeResize

Co-authored-by: tig <[email protected]>
copilot-swe-agent[bot] 1 month ago
parent
commit
9fb77a353e

+ 4 - 1
Tests/UnitTests/Application/ApplicationScreenTests.cs

@@ -94,7 +94,10 @@ public class ApplicationScreenTests
         // Arrange
         Application.ResetState (true);
         Assert.Null (Application.Driver);
-        Application.Driver = new FakeDriver { Rows = 25, Cols = 25 };
+        var driver = new FakeDriver();
+        driver.Init();
+        driver.SetScreenSize(25, 25);
+        Application.Driver = driver;
         Application.SubscribeDriverEvents ();
         Assert.Equal (new (0, 0, 25, 25), Application.Screen);
 

+ 2 - 3
Tests/UnitTests/Application/ApplicationTests.cs

@@ -627,9 +627,8 @@ public class ApplicationTests
         Assert.Equal (new (0, 0, 80, 25), driver.Screen);
         Assert.Equal (new (0, 0, 80, 25), Application.Screen);
 
-        // TODO: Should not be possible to manually change these at whim!
-        driver.Cols = 100;
-        driver.Rows = 30;
+        // Use SetScreenSize to change screen dimensions
+        driver.SetScreenSize (100, 30);
         // IConsoleDriver.Screen isn't assignable
         //driver.Screen = new (0, 0, driver.Cols, Rows);
 

+ 1 - 2
Tests/UnitTests/ConsoleDrivers/AddRuneTests.cs

@@ -28,8 +28,7 @@ public class AddRuneTests
         var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
         driver.Init ();
 
-        driver.Rows = 25;
-        driver.Cols = 80;
+        driver.SetScreenSize(80, 25);
         driver.Init ();
         driver.AddRune (new Rune ('a'));
         Assert.Equal ((Rune)'a', driver.Contents [0, 0].Rune);

+ 2 - 4
Tests/UnitTests/ConsoleDrivers/ClipRegionTests.cs

@@ -26,8 +26,7 @@ public class ClipRegionTests
     {
         var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
         Application.Init (driver);
-        Application.Driver!.Rows = 25;
-        Application.Driver!.Cols = 80;
+        Application.Driver!.SetScreenSize (80, 25);
 
         driver.Move (0, 0);
         driver.AddRune ('x');
@@ -94,8 +93,7 @@ public class ClipRegionTests
     {
         var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
         Application.Init (driver);
-        Application.Driver!.Rows = 10;
-        Application.Driver!.Cols = 10;
+        Application.Driver!.SetScreenSize (10, 10);
 
         // positive
         Assert.True (driver.IsValidLocation (default, 0, 0));

+ 2 - 4
Tests/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs

@@ -128,8 +128,7 @@ public class ConsoleDriverTests
     {
         var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
         driver?.Init ();
-        driver.Cols = 80;
-        driver.Rows = 25;
+        driver.SetScreenSize(80, 25);
 
         var wasTerminalResized = false;
 
@@ -144,8 +143,7 @@ public class ConsoleDriverTests
         Assert.Equal (25, driver.Rows);
         Assert.False (wasTerminalResized);
 
-        driver.Cols = 120;
-        driver.Rows = 40;
+        driver.SetScreenSize(120, 40);
 
         ((ConsoleDriver)driver).OnSizeChanged (new SizeChangedEventArgs (new (driver.Cols, driver.Rows)));
         Assert.Equal (120, driver.Cols);