Skip to content

Commit 8c105ae

Browse files
committed
Make tests pass
1 parent c7d26e6 commit 8c105ae

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

TerminalGuiFluentAssertions/Class1.cs

+24-9
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ public void Dispose ()
184184
/// <returns></returns>
185185
public GuiTestContext<T> Add (View v)
186186
{
187-
Application.Invoke (
188-
() =>
189-
{
190-
var top = Application.Top ?? throw new Exception("Top was null so could not add view");
191-
top.Add (v);
192-
top.Layout ();
193-
});
187+
WaitIteration (
188+
() =>
189+
{
190+
var top = Application.Top ?? throw new Exception("Top was null so could not add view");
191+
top.Add (v);
192+
top.Layout ();
193+
});
194194

195195
return this;
196196
}
@@ -201,10 +201,25 @@ public GuiTestContext<T> ResizeConsole (int width, int height)
201201

202202
return WaitIteration ();
203203
}
204-
public GuiTestContext<T> WaitIteration ()
204+
public GuiTestContext<T> WaitIteration (Action? a = null)
205205
{
206-
Application.Invoke (() => { });
206+
a ??= () => { };
207+
var ctsLocal = new CancellationTokenSource ();
208+
209+
210+
Application.Invoke (()=>
211+
{
212+
a();
213+
ctsLocal.Cancel ();
214+
});
207215

216+
// Blocks until either the token or the hardStopToken is cancelled.
217+
WaitHandle.WaitAny (new []
218+
{
219+
_cts.Token.WaitHandle,
220+
_hardStop.Token.WaitHandle,
221+
ctsLocal.Token.WaitHandle
222+
});
208223
return this;
209224
}
210225

Tests/UnitTests/FluentTests/BasicFluentAssertionTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public void TestWindowsResize ()
3333
};
3434
using var c = With.A<Window> (40, 10)
3535
.Add (lbl )
36-
.Assert (lbl.Frame.Width.Should().Be(40))
36+
.Assert (lbl.Frame.Width.Should().Be(38)) // Window has 2 border
3737
.ResizeConsole (20,20)
38-
.Assert (lbl.Frame.Width.Should ().Be (20))
38+
.Assert (lbl.Frame.Width.Should ().Be (18))
3939
.Stop ();
4040

4141
}

0 commit comments

Comments
 (0)