Skip to main content

ArlecchinoTestHost class

Namespace: Arlecchino.Testing · Assembly: Arlecchino.Testing

A whole application wired up for a test: real services, a terminal in memory, and no loop in the background. Frames are drawn when asked for, so a test presses keys and then reads the screen.

public sealed class ArlecchinoTestHost : IDisposable

Implements IDisposable

Constructors

MemberSummary
ArlecchinoTestHost(int, int, Action<ArlecchinoBuilder>)Builds the application, with the minimum size dropped to one cell and color fixed at ColorSupport.TrueColor. Assign TerminalCapabilities.Color to change it.

Properties

MemberSummary
ClockThe clock scheduled work runs on, moved by ArlecchinoTestHost.Advance.
HistoryUndo history. It is resolved as the host is built, so edits are recorded from the start.
NavigatorNavigation, for checking or forcing which view is current.
OptionsThe settings, for changing them after the application is built.
RepaintThe repaint flag, for checking that something actually asked for a frame.
ScreenWhat the screen holds after every frame drawn so far. ArlecchinoTestHost.FrameLines reads the last frame as it was written, which is the whole picture only while frames are written whole; this is the picture itself, diffed frames and all.
ServicesThe container, for reaching whatever the test registered.
StateThe shared state, for opening dialogs or reading the output line.
SurfaceThe cell grid, for tests that draw into it directly.
TerminalThe terminal being drawn to, for asserting on raw output or resizing mid-test.

Methods

MemberSummary
Advance(TimeSpan)Moves the clock forward and runs whatever fell due, exactly as the frame loop would. The frame is not drawn by this — ask for one afterward.
Click(int, int, MouseButton)Clicks a cell, in the terminal's own coordinates.
Dispose()Disposes the container and everything in it, and drops work still posted to the frame.
DrainInput()Routes whatever the reader has queued, which is what the frame loop does before it draws. ArlecchinoTestHost.ReadFromTerminal and ArlecchinoTestHost.Frame do it for you; call it yourself after driving TerminalInputReader directly, since the reader queues rather than routes.
Frame()Draws a frame as the difference from the last one, the way a running application does, and returns the whole screen afterward with the styling stripped away.
FrameContains(string)Whether a frame holds some text anywhere. Text split across rows will not be found.
FrameLineContaining(string)The first row holding some text, which is how a test reads what was drawn beside a label.
FrameLines()Draws a frame and returns the rows on screen afterward.
Press(ConsoleKey, KeyModifiers)Presses a key, routed exactly as a real key press is.
ReadFromTerminal(string)Feeds raw characters through the reader that recognizes escape sequences. This is the way to test what a real terminal sends for arrows, function keys and mouse reports.
Scroll(int, int, bool)Turns the wheel over a cell.
Send(KeyPress)Routes a key exactly as the terminal reported it, character and all, for a key played back from a SessionTape. A test writing keys by hand reaches for ArlecchinoTestHost.Press instead.
Send(MouseEvent)Routes a mouse event exactly as the terminal reported it.
SendPaste(string)Pastes a block of text, as bracketed paste delivers it.
Styles()Draws a frame whole and returns the color sequences in it, in order. A diffed frame would carry only the styles of the cells it rewrote.
Type(string)Types text one character at a time. The presses carry a character but no key, which is what a terminal reports for ordinary typing.

Constructors in detail

ArlecchinoTestHost(int, int, Action<ArlecchinoBuilder>)

public ArlecchinoTestHost(
int width = 80,
int height = 24,
Action<ArlecchinoBuilder>? configure = null);

Builds the application, with the minimum size dropped to one cell and color fixed at ColorSupport.TrueColor. Assign TerminalCapabilities.Color to change it.

Parameters

NameTypeDescription
widthintColumns of the fake terminal.
heightintRows of the fake terminal.
configureAction<T><ArlecchinoBuilder>Registers the views, commands and services under test.

Properties in detail

Clock

public TestClock Clock { get; }

The clock scheduled work runs on, moved by ArlecchinoTestHost.Advance.

Type TestClock

History

public AtomHistory History { get; }

Undo history. It is resolved as the host is built, so edits are recorded from the start.

Type AtomHistory

public Navigator Navigator { get; }

Navigation, for checking or forcing which view is current.

Type Navigator

Options

public ArlecchinoOptions Options { get; }

The settings, for changing them after the application is built.

Type ArlecchinoOptions

Repaint

public Repaint Repaint { get; }

The repaint flag, for checking that something actually asked for a frame.

Type Repaint

Screen

public ScreenGrid Screen { get; }

What the screen holds after every frame drawn so far. ArlecchinoTestHost.FrameLines reads the last frame as it was written, which is the whole picture only while frames are written whole; this is the picture itself, diffed frames and all.

Type ScreenGrid

Services

public IServiceProvider Services { get; }

The container, for reaching whatever the test registered.

Type IServiceProvider

State

public ArlecchinoState State { get; }

The shared state, for opening dialogs or reading the output line.

Type ArlecchinoState

Surface

public Surface Surface { get; }

The cell grid, for tests that draw into it directly.

Type Surface

Terminal

public FakeTerminal Terminal { get; }

The terminal being drawn to, for asserting on raw output or resizing mid-test.

Type FakeTerminal

Methods in detail

Advance(TimeSpan)

public void Advance(TimeSpan amount);

Moves the clock forward and runs whatever fell due, exactly as the frame loop would. The frame is not drawn by this — ask for one afterward.

Parameters

NameTypeDescription
amountTimeSpanHow far to move the clock.

Click(int, int, MouseButton)

public void Click(int row, int column, MouseButton button = Left);

Clicks a cell, in the terminal's own coordinates.

Parameters

NameTypeDescription
rowintRow, counted from the top of the terminal.
columnintColumn, counted from its left edge.
buttonMouseButtonWhich button was pressed.

Dispose()

public void Dispose();

Disposes the container and everything in it, and drops work still posted to the frame.

DrainInput()

public void DrainInput();

Routes whatever the reader has queued, which is what the frame loop does before it draws. ArlecchinoTestHost.ReadFromTerminal and ArlecchinoTestHost.Frame do it for you; call it yourself after driving TerminalInputReader directly, since the reader queues rather than routes.

Frame()

public string Frame();

Draws a frame as the difference from the last one, the way a running application does, and returns the whole screen afterward with the styling stripped away.

Returns string — The screen.

FrameContains(string)

public bool FrameContains(string text);

Whether a frame holds some text anywhere. Text split across rows will not be found.

Parameters

NameTypeDescription
textstringWhat to look for.

Returns booltrue when it is there.

FrameLineContaining(string)

public string FrameLineContaining(string text);

The first row holding some text, which is how a test reads what was drawn beside a label.

Parameters

NameTypeDescription
textstringWhat to look for.

Returns string — The whole row, or an empty string when no row holds it.

FrameLines()

public string[] FrameLines();

Draws a frame and returns the rows on screen afterward.

Returns string[] — One string per row.

Press(ConsoleKey, KeyModifiers)

public void Press(ConsoleKey key, KeyModifiers modifiers = None);

Presses a key, routed exactly as a real key press is.

Parameters

NameTypeDescription
keyConsoleKeyThe key.
modifiersKeyModifiersWhat was held with it.

ReadFromTerminal(string)

public void ReadFromTerminal(string sequence);

Feeds raw characters through the reader that recognizes escape sequences. This is the way to test what a real terminal sends for arrows, function keys and mouse reports.

Parameters

NameTypeDescription
sequencestringThe characters, escapes included.

Scroll(int, int, bool)

public void Scroll(int row, int column, bool down);

Turns the wheel over a cell.

Parameters

NameTypeDescription
rowintRow the pointer is over.
columnintColumn the pointer is over.
downboolWhether the wheel turned down.

Send(KeyPress)

public void Send(KeyPress key);

Routes a key exactly as the terminal reported it, character and all, for a key played back from a SessionTape. A test writing keys by hand reaches for ArlecchinoTestHost.Press instead.

Parameters

NameTypeDescription
keyKeyPressThe key as the terminal reported it.

Send(MouseEvent)

public void Send(MouseEvent mouse);

Routes a mouse event exactly as the terminal reported it.

Parameters

NameTypeDescription
mouseMouseEventThe event.

SendPaste(string)

public void SendPaste(string text);

Pastes a block of text, as bracketed paste delivers it.

Parameters

NameTypeDescription
textstringWhat was pasted.

Styles()

public IReadOnlyList<string> Styles();

Draws a frame whole and returns the color sequences in it, in order. A diffed frame would carry only the styles of the cells it rewrote.

Returns IReadOnlyList<T><string> — The sequences as they appeared.

Type(string)

public void Type(string text);

Types text one character at a time. The presses carry a character but no key, which is what a terminal reports for ordinary typing.

Parameters

NameTypeDescription
textstringWhat to type.