Table of Contents

Class TigerCliAppTestHost

Namespace
ItTiger.TigerCli.Testing
Assembly
ItTiger.TigerCli.dll
App-level test host for running a TigerCliApp without the real console input path. The host injects a test shell, queues planned prompt answers (WithTextInput(string), WithSelectIndex(int), WithConfirm(bool), WithMultiSelectIndexes(params int[])), redirects Out and Error for the duration of the run (restoring both in finally), pins a deterministic colour mode so captured output carries no ANSI escapes, restores the process-global active theme the run may have changed through --theme, and returns the captured output plus the exit code as a TigerCliAppRunResult.
public sealed class TigerCliAppTestHost
Inheritance
TigerCliAppTestHost
Inherited Members

Remarks

A host is single-use: calling RunAsync(CancellationToken) twice on the same instance throws InvalidOperationException. Create a new host for each run. Configuration methods are fluent and may be chained in any order before RunAsync(CancellationToken).

Methods

For(TigerCliApp)

Creates a test host for app. This is the only way to obtain a host — the constructor is private.
public static TigerCliAppTestHost For(TigerCliApp app)

Parameters

app TigerCliApp
The built app to run; must not be null.

Returns

TigerCliAppTestHost

Exceptions

ArgumentNullException
app is null.

RunAsync(CancellationToken)

Runs the app once with the configured arguments, planned prompt answers, viewport, and prompt timeout, and returns the exit code plus the output captured from Out and Error. The run is forced to a colour-free output mode so captured text never contains ANSI escape sequences; the original console writers, colour mode, and active theme are restored even when the run throws.
public Task<TigerCliAppRunResult> RunAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken
Cancellation token passed through to the app run.

Returns

Task<TigerCliAppRunResult>
The exit code and captured output of the completed run.

Exceptions

InvalidOperationException
The host has already run once — hosts are single-use.

WithArgs(params string[])

Replaces the command-line arguments passed to the run. When not called, the app runs with no arguments.
public TigerCliAppTestHost WithArgs(params string[] args)

Parameters

args string[]
The argument tokens; the array and its elements must not be null.

Returns

TigerCliAppTestHost

Exceptions

ArgumentNullException
args is null.
ArgumentException
args contains a null element.

WithConfirm(bool)

Queues a planned answer for a Yes/No confirm prompt. true accepts the default Yes button with Enter; false navigates to the No button and confirms.
public TigerCliAppTestHost WithConfirm(bool value)

Parameters

value bool
true to answer Yes, false to answer No.

Returns

TigerCliAppTestHost

WithHtmlCapture(HtmlSinkOptions?)

Additionally captures the run's TigerCli output as deterministic HTML (via HtmlSink), exposed on StdOutHtml / StdErrHtml — for documentation artifacts and styled-output assertions. Opt-in: without this call both properties stay null and the run behaves exactly as before.

Semantics: TigerCli-rendered output (markup, help, framework errors, structured output) goes to the HTML capture instead of the plain StdOut/StdErr strings; unstyled text is captured without machine-dependent console colours; line endings are normalized to \n. options controls hyperlink mode, layout width (SoftMaxWidth), and whether the returned fragments are wrapped in <pre class="tigercli"> (WrapInPre, default true). No ANSI is ever emitted.

public TigerCliAppTestHost WithHtmlCapture(HtmlSinkOptions? options = null)

Parameters

options HtmlSinkOptions

Returns

TigerCliAppTestHost

WithMultiSelectIndexes(params int[])

Queues a planned answer for a multi-select (checklist) prompt. Indexes are normalized by sorting and removing duplicates; the answer walks the rows top-to-bottom, toggles each selected row with Spacebar, then confirms with Enter. An empty indexes confirms with nothing selected.
public TigerCliAppTestHost WithMultiSelectIndexes(params int[] indexes)

Parameters

indexes int[]
The zero-based choice indexes to toggle; none may be negative.

Returns

TigerCliAppTestHost

Exceptions

ArgumentNullException
indexes is null.
ArgumentOutOfRangeException
Any index is negative.

WithPromptTimeout(TimeSpan)

Sets the prompt timeout passed through to RunAsync(string[], ICliAppShell?, TimeSpan?, CancellationToken). When not called, no prompt timeout applies.
public TigerCliAppTestHost WithPromptTimeout(TimeSpan timeout)

Parameters

timeout TimeSpan
The prompt timeout; must not be negative.

Returns

TigerCliAppTestHost

Exceptions

ArgumentOutOfRangeException
timeout is negative.

WithSelectIndex(int)

Queues a planned answer for a select prompt: DownArrow is pressed index times, then Enter — selecting the zero-based row index in the choice list.
public TigerCliAppTestHost WithSelectIndex(int index)

Parameters

index int
The zero-based choice index to select; must not be negative.

Returns

TigerCliAppTestHost

Exceptions

ArgumentOutOfRangeException
index is negative.

WithTextInput(string)

Queues a planned answer for a text prompt: each character of value is typed using its key character, followed by Enter. Answers are consumed by prompts in the order they were queued.
public TigerCliAppTestHost WithTextInput(string value)

Parameters

value string
The text to type; must not be null (empty submits an empty answer).

Returns

TigerCliAppTestHost

Exceptions

ArgumentNullException
value is null.

WithViewport(int, int)

Configures the injected test shell's viewport size. The default is 80×24.
public TigerCliAppTestHost WithViewport(int width, int height)

Parameters

width int
Viewport width in columns; must be positive.
height int
Viewport height in rows; must be positive.

Returns

TigerCliAppTestHost

Exceptions

ArgumentOutOfRangeException
width or height is zero or negative.