Skip to content

RunInMem#

The RunInMem extension method takes a fully configured AppRunner instance and runs it in memory.

public class Git
{
    public void Checkout(string branch)
    {
        System.Console.Error.WriteLine($"error: pathspec '{branch}' did not match any file(s) known to git");
    }
}

public static void RunInMem_Error_Example()
{
    var result = new AppRunner<Git>()
        .UseDefaultMiddleware()
        .RunInMem("checkout lala");

    // result.ExitCode.Should().Be(1);
    // result.Console.Error.Should().Contain("error: pathspec 'lala' did not match any file(s) known to git");
}
snippet source | anchor

What it does#

Configure CommandDotNet logging#

if TestConfig.PrintCommandDotNetLogs = true

Configure TestConsole#

A new TestConsole will be configured as the IConsole for the app to capture all output.

If these RunInMem parameters are provided, they are

  • Func<TestConsole, string> onReadLine
  • IEnumerable<string> pipedInput
  • IPromptResponder promptResponder

Execute appRunner.Run(args)#

If an argument string was provided instead of an argument array, the string is split into an array.

Executes the AppRunner.Run method with the argument array.

Log Output#

Log output based on TestConfig.OnSuccess.Print or TestConfig.OnError.Print settings

Return AppRunnerResult#

public class AppRunnerResult
{
    internal AppRunner Runner { get; }
    internal TestConfig Config { get; }

    public int ExitCode { get; }

    public TestConsole Console { get; }

    /// <summary>The <see cref="CommandContext"/> used during the run</summary>
    public CommandContext CommandContext { get; }

    /// <summary>The exception that escaped from <see cref="AppRunner.Run"/><br/></summary>
    public Exception? EscapedException { get; }
}