Class ComponentHarness
- Namespace
- MiniTui
- Assembly
- MiniTui.dll
Runs a screen in a test (§9.6): an app on a TestBackend with scripted input, driven one loop iteration at a time on the calling thread. It never touches the real console.
public sealed class ComponentHarness : IDisposable
- Inheritance
-
ComponentHarness
- Implements
- Inherited Members
Examples
using var harness = new ComponentHarness(new ServicesScreen(fakeApi));
harness.Press("j j enter");
Assert.Contains("svc-3", harness.Lines[0]);
Constructors
ComponentHarness(Screen, int, int, TimeProvider?)
Push root on a new app and render the first frame.
public ComponentHarness(Screen root, int width = 80, int height = 24, TimeProvider? time = null)
Parameters
rootScreenThe first screen.
widthintTerminal width.
heightintTerminal height.
timeTimeProviderThe app's clock, such as a fake one; the system clock by default.
Properties
App
public App App { get; }
Property Value
Lines
The screen, one string per row.
public string[] Lines { get; }
Property Value
- string[]
Methods
CellAt(int, int)
The cell at a position, as last drawn.
public Cell CellAt(int x, int y)
Parameters
Returns
Click(int, int, MouseButton)
Press and release button at (x, y), then RunUntilIdle().
public void Click(int x, int y, MouseButton button = MouseButton.Left)
Parameters
xintyintbuttonMouseButton
Dispose()
Stop the app: screens and overlays stay mounted, but loads are cancelled through Stopping.
public void Dispose()
DoubleClick(int, int)
Press and release the left button twice at (x, y), a double-click
(1.x spec §17.3), then RunUntilIdle().
public void DoubleClick(int x, int y)
Parameters
Mouse(MouseEvent)
Send one mouse event, then RunUntilIdle().
public void Mouse(MouseEvent mouse)
Parameters
mouseMouseEvent
Paste(string)
Paste text, as a terminal with bracketed paste does, then RunUntilIdle().
public void Paste(string text)
Parameters
textstring
Press(string)
Press keys, then RunUntilIdle(). keys is space-separated
KeyBinding names, such as "j j enter" or "ctrl+r".
public void Press(string keys)
Parameters
keysstring
Exceptions
- FormatException
A key name isn't valid.
RunUntilIdle()
Handle queued keys, posted work and UI-thread continuations until nothing is left and no load or
RunTask(Func<CancellationToken, Task>) is in flight (other than ones waiting on a dialog), then render one frame.
An exception the app would rethrow from Run() is rethrown here.
public void RunUntilIdle()
Exceptions
- TimeoutException
Work is still in flight after 5 seconds of real time.
Scroll(int, int, int)
Scroll the wheel at (x, y), one event per row: positive
rows scroll down, negative up. Then RunUntilIdle().
public void Scroll(int x, int y, int rows)
Parameters
Type(string)
Type text, one key per character, then RunUntilIdle().
public void Type(string text)
Parameters
textstring