Open
Description
How do I obtain the InvocationContext after the Invoke
has completed? Main use case is for unit testing and examining the InvocationResult
.
The current workaround below, but this is dirty.
public class Program
{
internal InvocationContext InvocationContext { get; private set; }
public static async Task<int> Main(string[] args)
{
var _ = GetCommandLineBuilder()
.UseHost(_ => Host.CreateDefaultBuilder(),
host =>
{
InvocationContext = host.GetInvocationContext();
and the unit tests like
[Test]
public async Task Cli_NoCommand_ParseErrorResult()
{
var args = "";
var p = new Program();
await p.Main(args.Split(' '));
Assert.IsInstanceOf<ParseErrorResult>(p.InvocationContext.InvocationResult);
Assert.AreEqual(1, p.InvocationContext.ParseResult.Errors.Count(pe => pe.Message == "Required command was not provided."));
}