TestTerminal
ConsoleMonster.Testing
Helpers for testing console output in any test framework: render a widget at a fixed size, glyph tier, colour depth and culture (so results do not depend on the machine), drive prompts, menus and forms with scripted keys, and capture the screens they draw. Pair with GoldenFile for snapshot tests.
Inheritance
- object
- TestTerminal
Methods
public static InteractiveOptions Interactive(string keys, ScreenCapture capture, GlyphTier glyphs = Full) #Options that run a prompt, menu or form against scripted keys and draw into capture (rich mode, dark theme, no colour, invariant culture, the capture's size).
Parameters
- keys string
- The keys (see TestTerminal.Keys).
- capture ConsoleMonster.Interactive.ScreenCapture
- Where the screens go.
- glyphs ConsoleMonster.Capabilities.GlyphTier = Full
- The glyph tier.
public static ScriptedInput Keys(string script) #Scripted keys for prompts and menus, for example "Down Down Space Enter", "\"typed text\" Tab", "Ctrl+K paste:'x' wait:200". Paced, so every step draws a frame.
Parameters
- script string
- The keys.
public static TerminalProfile Profile(int width = 80, int height = 24, GlyphTier glyphs = Full, ColorDepth colors = None, CultureInfo? culture = null) #A fixed terminal profile: no detection, the given size, tier, depth and culture (invariant by default).
Parameters
- width int = 80
- Width in cells.
- height int = 24
- Height in cells.
- glyphs ConsoleMonster.Capabilities.GlyphTier = Full
- The glyph tier.
- colors ConsoleMonster.Capabilities.ColorDepth = None
- The colour depth (none by default, so text is plain).
- culture System.Globalization.CultureInfo? = null
- The culture; null for the invariant culture.
public static CellBuffer Render(IWidget widget, int width = 80, int height = 0, GlyphTier glyphs = Full, CultureInfo? culture = null, ITheme? theme = null) #Renders a widget into cells: as tall as it measures, or exactly height rows.
Parameters
- widget ConsoleMonster.Layout.IWidget
- The widget.
- width int = 80
- Width in cells.
- height int = 0
- Height in cells; 0 measures the widget.
- glyphs ConsoleMonster.Capabilities.GlyphTier = Full
- The glyph tier.
- culture System.Globalization.CultureInfo? = null
- The culture; null for the invariant culture.
- theme ConsoleMonster.Styling.ITheme? = null
- The theme; null for the dark theme.
public static string RenderText(IWidget widget, int width = 80, int height = 0, GlyphTier glyphs = Full, CultureInfo? culture = null) #Renders a widget to plain text: rows joined with \n, trailing spaces trimmed.
Parameters
- widget ConsoleMonster.Layout.IWidget
- The widget.
- width int = 80
- Width in cells.
- height int = 0
- Height in cells; 0 measures the widget.
- glyphs ConsoleMonster.Capabilities.GlyphTier = Full
- The glyph tier.
- culture System.Globalization.CultureInfo? = null
- The culture; null for the invariant culture.
Returns
string The text.public static RecordingTarget Target(int width = 80, int height = 24, GlyphTier glyphs = Full, ColorDepth colors = None, CultureInfo? culture = null, string? keys = null) #An in-memory target with a fixed profile (append-only output, no detection): pass it to code that takes an ITerminalTarget, or scope the static Terminal methods to it with Terminal.Use. Its RecordingTarget.Text goes to GoldenFile through RecordingTarget.MatchGolden; scripted keys answer prompts, which draw into RecordingTarget.Screens.
Parameters
- width int = 80
- Width in cells.
- height int = 24
- Height in cells (the screen size for prompts).
- glyphs ConsoleMonster.Capabilities.GlyphTier = Full
- The glyph tier.
- colors ConsoleMonster.Capabilities.ColorDepth = None
- The colour depth (none by default, so the text is plain).
- culture System.Globalization.CultureInfo? = null
- The culture for numbers, dates and labels; null for the invariant culture (English labels).
- keys string? = null
- Scripted keys for prompts (see TestTerminal.Keys), or null so prompts use their defaults.