瀏覽代碼

Add screenshot method

tznind 4 月之前
父節點
當前提交
8d610a0dde
共有 2 個文件被更改,包括 34 次插入2 次删除
  1. 12 1
      TerminalGuiFluentAssertions/Class1.cs
  2. 22 1
      Tests/UnitTests/FluentTests/BasicFluentAssertionTests.cs

+ 12 - 1
TerminalGuiFluentAssertions/Class1.cs

@@ -38,6 +38,7 @@ class FakeWindowsInput (CancellationToken hardStopToken) : FakeInput<WindowsCons
 
 
 class FakeOutput : IConsoleOutput
 class FakeOutput : IConsoleOutput
 {
 {
+    public IOutputBuffer LastBuffer { get; set; }
     public Size Size { get; set; }
     public Size Size { get; set; }
 
 
     /// <inheritdoc />
     /// <inheritdoc />
@@ -55,9 +56,10 @@ class FakeOutput : IConsoleOutput
     /// <inheritdoc />
     /// <inheritdoc />
     public void Write (IOutputBuffer buffer)
     public void Write (IOutputBuffer buffer)
     {
     {
-
+        LastBuffer = buffer;
     }
     }
 
 
+
     /// <inheritdoc />
     /// <inheritdoc />
     public Size GetWindowSize ()
     public Size GetWindowSize ()
     {
     {
@@ -210,6 +212,15 @@ public class GuiTestContext<T> : IDisposable where T : Toplevel, new()
 
 
         return WaitIteration ();
         return WaitIteration ();
     }
     }
+    public GuiTestContext<T> ScreenShot (string title, TextWriter writer)
+    {
+        writer.WriteLine(title);
+        var text = Application.ToString ();
+
+        writer.WriteLine(text);
+
+        return WaitIteration ();
+    }
     public GuiTestContext<T> WaitIteration (Action? a = null)
     public GuiTestContext<T> WaitIteration (Action? a = null)
     {
     {
         a ??= () => { };
         a ??= () => { };

+ 22 - 1
Tests/UnitTests/FluentTests/BasicFluentAssertionTests.cs

@@ -5,10 +5,30 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using FluentAssertions;
 using FluentAssertions;
 using TerminalGuiFluentAssertions;
 using TerminalGuiFluentAssertions;
+using Xunit.Abstractions;
 
 
 namespace UnitTests.FluentTests;
 namespace UnitTests.FluentTests;
 public class BasicFluentAssertionTests
 public class BasicFluentAssertionTests
 {
 {
+    private readonly TextWriter _out;
+    public class TestOutputWriter : TextWriter
+    {
+        private readonly ITestOutputHelper _output;
+
+        public TestOutputWriter (ITestOutputHelper output)
+        {
+            _output = output;
+        }
+
+        public override void WriteLine (string? value)
+        {
+            _output.WriteLine (value ?? string.Empty);
+        }
+
+        public override Encoding Encoding => Encoding.UTF8;
+    }
+
+    public BasicFluentAssertionTests (ITestOutputHelper outputHelper) { _out = new TestOutputWriter(outputHelper); }
     [Fact]
     [Fact]
     public void GuiTestContext_StartsAndStopsWithoutError ()
     public void GuiTestContext_StartsAndStopsWithoutError ()
     {
     {
@@ -55,7 +75,8 @@ public class BasicFluentAssertionTests
                           .WithContextMenu(ctx,menuItems)
                           .WithContextMenu(ctx,menuItems)
                           // Click in main area inside border
                           // Click in main area inside border
                           .RightClick(1,1)
                           .RightClick(1,1)
-                          .LeftClick (2, 2)
+                          .ScreenShot ("After open menu:",_out)
+                          .LeftClick (3, 3)
                           /*.Assert (Application.Top.Focused.Should ().BeAssignableTo(typeof(MenuBarItem)))
                           /*.Assert (Application.Top.Focused.Should ().BeAssignableTo(typeof(MenuBarItem)))
                           .Down()
                           .Down()
                           .Enter()*/
                           .Enter()*/