Table of Contents

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

root Screen

The first screen.

width int

Terminal width.

height int

Terminal height.

time TimeProvider

The app's clock, such as a fake one; the system clock by default.

Properties

App

The app under test. Its Screens, Overlays and Toasts can be inspected and changed.

public App App { get; }

Property Value

App

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

x int
y int

Returns

Cell

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

x int
y int
button MouseButton

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

x int
y int

Mouse(MouseEvent)

Send one mouse event, then RunUntilIdle().

public void Mouse(MouseEvent mouse)

Parameters

mouse MouseEvent

Paste(string)

Paste text, as a terminal with bracketed paste does, then RunUntilIdle().

public void Paste(string text)

Parameters

text string

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

keys string

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

x int
y int
rows int

Type(string)

Type text, one key per character, then RunUntilIdle().

public void Type(string text)

Parameters

text string