public void Run_CommandResolveExceptionCommandFound_WritesInvalidArguments() { var commandLoop = this.CreateCommandLoop(); #pragma warning disable CC0031 // Check for null before calling a delegate this.commandFactoryMock .Setup(f => f("CommandGroup", "exit")) .Callback(GetCommandLoopCancellationTokenSource(commandLoop).Cancel) .Throws(new CommandResolveException("exit", new[] { "Arg0" })); this.commandGroupMetadataFactoryMock .Setup(f => f("CommandGroup")) .Returns(new[] { CommandFactoryHelper.CreateExitCommandMeta(commandLoop).Metadata }); #pragma warning restore CC0031 // Check for null before calling a delegate string outputString; using (var newOut = new StringWriter(CultureInfo.InvariantCulture)) using (var newIn = new StringReader("exit Arg0")) { var previousOut = Console.Out; var previousIn = Console.In; Console.SetOut(newOut); Console.SetIn(newIn); commandLoop.Run(); Console.SetIn(previousIn); Console.SetOut(previousOut); outputString = newOut.ToString(); } Assert.That(outputString, Does.Contain("Invalid arguments on command 'exit'.")); Assert.That(outputString, Does.Not.Contain("Exit help text.")); }
public void Run_ValidCommand() { var commandLoop = this.CreateCommandLoop(); #pragma warning disable CC0031 // Check for null before calling a delegate this.commandFactoryMock .Setup(f => f("CommandGroup", "exit")) .Returns(() => CommandFactoryHelper.CreateExitCommandMeta(commandLoop)); #pragma warning restore CC0031 // Check for null before calling a delegate using (var newOut = new StringWriter(CultureInfo.InvariantCulture)) using (var newIn = new StringReader("exit")) { var previousOut = Console.Out; var previousIn = Console.In; Console.SetOut(newOut); Console.SetIn(newIn); commandLoop.Run(); Console.SetIn(previousIn); Console.SetOut(previousOut); } }