Jelajahi Sumber

Make tests pass

tznind 4 bulan lalu
induk
melakukan
4316378f6e

+ 24 - 9
TerminalGuiFluentAssertions/Class1.cs

@@ -184,13 +184,13 @@ public class GuiTestContext<T> : IDisposable where T : Toplevel, new()
     /// <returns></returns>
     public GuiTestContext<T> Add (View v)
     {
-        Application.Invoke (
-                            () =>
-                            {
-                                var top = Application.Top ?? throw new Exception("Top was null so could not add view");
-                                top.Add (v);
-                                top.Layout ();
-                            });
+        WaitIteration (
+                       () =>
+                       {
+                           var top = Application.Top ?? throw new Exception("Top was null so could not add view");
+                           top.Add (v);
+                           top.Layout ();
+                       });
 
         return this;
     }
@@ -201,10 +201,25 @@ public class GuiTestContext<T> : IDisposable where T : Toplevel, new()
 
         return WaitIteration ();
     }
-    public GuiTestContext<T> WaitIteration ()
+    public GuiTestContext<T> WaitIteration (Action? a = null)
     {
-        Application.Invoke (() => { });
+        a ??= () => { };
+        var ctsLocal = new CancellationTokenSource ();
+
+
+        Application.Invoke (()=>
+                            {
+                                a();
+                                ctsLocal.Cancel ();
+                            });
 
+        // Blocks until either the token or the hardStopToken is cancelled.
+        WaitHandle.WaitAny (new []
+        {
+            _cts.Token.WaitHandle,
+            _hardStop.Token.WaitHandle,
+            ctsLocal.Token.WaitHandle
+        });
         return this;
     }
 

+ 2 - 2
Tests/UnitTests/FluentTests/BasicFluentAssertionTests.cs

@@ -33,9 +33,9 @@ public class BasicFluentAssertionTests
                                 };
         using var c = With.A<Window> (40, 10)
                           .Add (lbl )
-                          .Assert (lbl.Frame.Width.Should().Be(40))
+                          .Assert (lbl.Frame.Width.Should().Be(38)) // Window has 2 border
                           .ResizeConsole (20,20)
-                          .Assert (lbl.Frame.Width.Should ().Be (20))
+                          .Assert (lbl.Frame.Width.Should ().Be (18))
                           .Stop ();
 
     }