Class TigerCliAppTestHost
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
appTigerCliApp- The built app to run; must not be
null.
Returns
Exceptions
- ArgumentNullException
appisnull.
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
cancellationTokenCancellationToken- 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
argsstring[]- The argument tokens; the array and its elements must not be
null.
Returns
Exceptions
- ArgumentNullException
argsisnull.- ArgumentException
argscontains anullelement.
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
valuebooltrueto answer Yes,falseto answer No.
Returns
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
optionsHtmlSinkOptions
Returns
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
indexesint[]- The zero-based choice indexes to toggle; none may be negative.
Returns
Exceptions
- ArgumentNullException
indexesisnull.- 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
timeoutTimeSpan- The prompt timeout; must not be negative.
Returns
Exceptions
- ArgumentOutOfRangeException
timeoutis 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
indexint- The zero-based choice index to select; must not be negative.
Returns
Exceptions
- ArgumentOutOfRangeException
indexis 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
valuestring- The text to type; must not be
null(empty submits an empty answer).
Returns
Exceptions
- ArgumentNullException
valueisnull.
WithViewport(int, int)
Configures the injected test shell's viewport size. The default is 80×24.
public TigerCliAppTestHost WithViewport(int width, int height)
Parameters
widthint- Viewport width in columns; must be positive.
heightint- Viewport height in rows; must be positive.
Returns
Exceptions
- ArgumentOutOfRangeException
widthorheightis zero or negative.