From 4316378f6eea537e981740c8fd4cd17bdc9514d7 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 16 Mar 2025 15:39:33 +0000 Subject: [PATCH] Make tests pass --- TerminalGuiFluentAssertions/Class1.cs | 33 ++++++++++++++----- .../FluentTests/BasicFluentAssertionTests.cs | 4 +-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/TerminalGuiFluentAssertions/Class1.cs b/TerminalGuiFluentAssertions/Class1.cs index 0ab4296f5..0075e6221 100644 --- a/TerminalGuiFluentAssertions/Class1.cs +++ b/TerminalGuiFluentAssertions/Class1.cs @@ -184,13 +184,13 @@ public class GuiTestContext : IDisposable where T : Toplevel, new() /// public GuiTestContext 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 : IDisposable where T : Toplevel, new() return WaitIteration (); } - public GuiTestContext WaitIteration () + public GuiTestContext 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; } diff --git a/Tests/UnitTests/FluentTests/BasicFluentAssertionTests.cs b/Tests/UnitTests/FluentTests/BasicFluentAssertionTests.cs index 0f35ede61..b52d07188 100644 --- a/Tests/UnitTests/FluentTests/BasicFluentAssertionTests.cs +++ b/Tests/UnitTests/FluentTests/BasicFluentAssertionTests.cs @@ -33,9 +33,9 @@ public class BasicFluentAssertionTests }; using var c = With.A (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 (); }