Skip to content

Commit c14bb90

Browse files
committedMar 16, 2025·
Add screenshot method
1 parent 8bf3576 commit c14bb90

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed
 

‎TerminalGuiFluentAssertions/Class1.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class FakeWindowsInput (CancellationToken hardStopToken) : FakeInput<WindowsCons
3838

3939
class FakeOutput : IConsoleOutput
4040
{
41+
public IOutputBuffer LastBuffer { get; set; }
4142
public Size Size { get; set; }
4243

4344
/// <inheritdoc />
@@ -55,9 +56,10 @@ public void Write (ReadOnlySpan<char> text)
5556
/// <inheritdoc />
5657
public void Write (IOutputBuffer buffer)
5758
{
58-
59+
LastBuffer = buffer;
5960
}
6061

62+
6163
/// <inheritdoc />
6264
public Size GetWindowSize ()
6365
{
@@ -210,6 +212,15 @@ public GuiTestContext<T> ResizeConsole (int width, int height)
210212

211213
return WaitIteration ();
212214
}
215+
public GuiTestContext<T> ScreenShot (string title, TextWriter writer)
216+
{
217+
writer.WriteLine(title);
218+
var text = Application.ToString ();
219+
220+
writer.WriteLine(text);
221+
222+
return WaitIteration ();
223+
}
213224
public GuiTestContext<T> WaitIteration (Action? a = null)
214225
{
215226
a ??= () => { };

‎Tests/UnitTests/FluentTests/BasicFluentAssertionTests.cs

+22-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,30 @@
55
using System.Threading.Tasks;
66
using FluentAssertions;
77
using TerminalGuiFluentAssertions;
8+
using Xunit.Abstractions;
89

910
namespace UnitTests.FluentTests;
1011
public class BasicFluentAssertionTests
1112
{
13+
private readonly TextWriter _out;
14+
public class TestOutputWriter : TextWriter
15+
{
16+
private readonly ITestOutputHelper _output;
17+
18+
public TestOutputWriter (ITestOutputHelper output)
19+
{
20+
_output = output;
21+
}
22+
23+
public override void WriteLine (string? value)
24+
{
25+
_output.WriteLine (value ?? string.Empty);
26+
}
27+
28+
public override Encoding Encoding => Encoding.UTF8;
29+
}
30+
31+
public BasicFluentAssertionTests (ITestOutputHelper outputHelper) { _out = new TestOutputWriter(outputHelper); }
1232
[Fact]
1333
public void GuiTestContext_StartsAndStopsWithoutError ()
1434
{
@@ -55,7 +75,8 @@ public void ContextMenu_CrashesOnRight ()
5575
.WithContextMenu(ctx,menuItems)
5676
// Click in main area inside border
5777
.RightClick(1,1)
58-
.LeftClick (2, 2)
78+
.ScreenShot ("After open menu:",_out)
79+
.LeftClick (3, 3)
5980
/*.Assert (Application.Top.Focused.Should ().BeAssignableTo(typeof(MenuBarItem)))
6081
.Down()
6182
.Enter()*/

0 commit comments

Comments
 (0)
Please sign in to comment.