public void SubCommandSectionFooter() { // Given var logger = new StringBuilderLogger(); var subCommand = new SubCommand() .RegisterSubCommand(new KatasCommand()) ; var root = new DefaultCommand() .RegisterSubCommand(subCommand) .Use(logger) ; // When var result = root.Execute("sub", "help"); // Then Assert.That(result, Is.EqualTo(0), logger.ErrorBuilder.ToString()); var lines = logger.InfoBuilder.ToString() .Split('\n') .Select(row => row.Replace("\r", "")) .SkipUntil(row => row == "To get help for subcommands") .ToArray() ; var i = -1; lines[++i].Trim().ShouldBe("To get help for subcommands"); lines[++i].Trim().ShouldBe("sub help <subcommand>"); }
//if timeout is set and window is not closed after timeout - click default button internal Thread CloseWindowOnTimeout(int timeout) { if (timeout < 100) { return(null); } Thread t = new Thread(() => { if (timeout < 2000) { Thread.Sleep(timeout); } else { int count = timeout / 300; for (int i = 0; i < count; i++) { Thread.Sleep(300); int idx = i; WPF_Helper.ExecuteOnUIThread(() => { UpdateDefaultButtonTimeout(idx * 300, timeout); return(0); }); } } if (IsVisible) { WPF_Helper.ExecuteOnUIThread(() => { DefaultCommand.Execute(this); return(0); }); } }); t.Name = "AutoCloseMessage"; t.Start(); return(t); }
public void HelpForSubSubCommands() { // Given var logger = new StringBuilderLogger(); var subCommand = new SubCommand() .RegisterSubCommand(new KatasCommand()) ; var root = new DefaultCommand() .RegisterSubCommand(subCommand) .Use(logger) ; // When var result = root.Execute("sub", "katas", "help"); // Then Assert.That(result, Is.EqualTo(0), logger.ErrorBuilder.ToString()); var lines = logger.InfoBuilder.ToString() .Split('\n') .Where(row => !string.IsNullOrWhiteSpace(row)) .Select(row => row.Replace("\r", "")) .ToArray() ; var i = -1; lines[++i].Trim().ShouldBe("This command is intended for demonstration purposes. It provides some katas"); }
// Falls back on a given Default or Help void ExecuteFallback(string[] args, string commandName) { if (DefaultCommand == null) { // If we have no default then invoke Help string message = $"The command '{commandName}' does not exist, and here is no default command"; HelpFacade.Execute(message); } else { // Pass on all arguments to the default Command DefaultCommand.Execute(args); } }
public void InvalidCommandTest() { ICommand command = new DefaultCommand(); var arguments = new List <string>() { "someUnknownCommand", "SomeArgument" }; var commandResult = command.Execute(arguments); Assert.IsNotNull(commandResult); Assert.IsTrue(commandResult.Count() == 1); Assert.AreEqual($"Command {arguments.First()} was not found", commandResult.First()); }
public void Run(TextReader reader = null, bool echoInput = false) { if (reader == null) { // set input limit to 10M var stdin = Console.OpenStandardInput(1024 * 1024 * 10); reader = new StreamReader(stdin); } while (keepRunning) { Console.Write(Welcome + "> "); var rawInput = reader.ReadLine(); if (rawInput == null) { break; } if (echoInput) { Console.WriteLine(rawInput); } var cmdline = rawInput.Split( new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries ); if (cmdline.Length == 0) { continue; } try { var cmd = FindCommand(cmdline[0]); if (cmd != null) { var parameters = new string[cmdline.Length - 1]; Array.Copy(cmdline, 1, parameters, 0, cmdline.Length - 1); cmd.Execute(parameters); } else { DefaultCommand.Execute(cmdline); } } catch (Exception x) { Console.WriteLine("ERROR: Unexpected exception occured\n{0}", x); } } }
public void Execute() { // Arrange var componentUnderTest = new DefaultCommand(); // Act componentUnderTest.Execute(); // Assert componentUnderTest.OnBeforeInitialiseTargetCalled.ShouldHaveSameValueAs(true); componentUnderTest.OnInitialiseTargetCalled.ShouldHaveSameValueAs(true); componentUnderTest.OnAuthoriseCalled.ShouldHaveSameValueAs(true); componentUnderTest.OnBeforeExecuteCalled.ShouldHaveSameValueAs(true); componentUnderTest.OnExecuteCalled.ShouldHaveSameValueAs(true); componentUnderTest.OnAfterExecuteCalled.ShouldHaveSameValueAs(true); componentUnderTest.OnAfterExecuteCalledWithException.ShouldHaveSameValueAs(false); }
public void Execute(object parameter) { var args = (SearchBoxResultSuggestionChosenEventArgs)parameter; var command = GetCommand(args); if (command == null && DefaultCommand == null) { return; } if (command == null) { DefaultCommand.Execute(args.Tag); } else { command.Command.Execute(command.CommandSelector.SelectTag(args.Tag)); } }
protected override bool ExecuteParent(ArraySegment <string> arguments, ICommandSender sender, out string response) { return(DefaultCommand.Execute(arguments, sender, out response)); }