public string ExecuteCommand(string commandName, string[] commandArguments) { ICommand command = null; if (commandName == "AddPhone" && commandArguments.Length >= 2) { command = new AddPhoneCommand(this.phonebookRepository, commandArguments); } else if (commandName == "ChangePhone" && commandArguments.Length == 2) { command = new ChangePhoneCommand(this.phonebookRepository, commandArguments); } else if (commandName == "List" && commandArguments.Length == 2) { command = new ListCommand(this.phonebookRepository, commandArguments); } else { return "Invalid command"; } string commandResult; try { commandResult = command.Execute(); } catch (Exception e) { commandResult = e.Message; } return commandResult; }
public void when_list_command_is_executed_then_a_database_connection_is_established() { var listCommand = new ListCommand(MockSecureConsole.Object, _mockConnectionFactory.Object, _mockVersionRepositoryFactory.Object); listCommand.Execute(_requiredListCommandArguments); _mockConnectionFactory.Verify(m => m.Create(It.IsAny<DatabaseConnectionInfo>()), Times.Once); }
public void when_list_command_is_executed_then_all_versions_are_fetched_from_database() { var listCommand = new ListCommand(MockSecureConsole.Object, _mockConnectionFactory.Object, _mockVersionRepositoryFactory.Object); listCommand.Execute(_requiredListCommandArguments); _mockVersionRepository.Verify(m => m.GetAllVersions(It.IsAny<string>()), Times.Once); }
public void Test() { var input = new ListInput() { PointFlag = @"..\..\..\.." }; var cmd = new ListCommand(); cmd.Execute(input); //REVIEW: how do I test the console out put? }
public void Test() { var input = new ListInput() { PointFlag = @"..{0}..{0}..{0}..".ToFormat(Path.DirectorySeparatorChar) }; var cmd = new ListCommand(); cmd.Execute(input); //REVIEW: how do I test the console out put? }
public void CanPushStringList() { ParserParameter param = new ParserPositionalParameter("Names", true); ParseResult result = new ParseResult(); result.AddCommandListValue(param, "Fred"); result.AddCommandListValue(param, "Barney"); var pusher = new CommandPusher(result); var command = new ListCommand(); pusher.Push(command); command.Names.ShouldContain(x => x == "Fred"); command.Names.ShouldContain(x => x == "Barney"); }
public void when_database_contains_versions_then_they_are_listed_to_the_screen() { _mockVersionRepository.Setup(m => m.GetAllVersions(It.IsAny<string>())) .Returns(new List<DatabaseVersion> { new DatabaseVersion(1, "some script"), new DatabaseVersion(2, "some other script") }); var listCommand = new ListCommand(MockSecureConsole.Object, _mockConnectionFactory.Object, _mockVersionRepositoryFactory.Object); using (var stringWriter = new StringWriter()) { Console.SetOut(stringWriter); listCommand.Execute(_requiredListCommandArguments); Assert.That(stringWriter.ToString().Contains(" 1\t\tsome script")); Assert.That(stringWriter.ToString().Contains(" 2\t\tsome other script")); } }
public static ListCommand Parse(String command) { ListCommand newCommand = new ListCommand(); if (command.StartsWith("+", StringComparison.Ordinal)) { newCommand.Operator = "+"; String[] newItemText = command.Substring(1).Split(textSeperator); newCommand.Value = newItemText[0]; newCommand.Text = newItemText[1]; if (newItemText.Length == 3) { String IndexText = newItemText[2]; try { newCommand.Index = Int32.Parse(IndexText, System.Globalization.CultureInfo.InvariantCulture); } catch { } } } else if (command.StartsWith("-", StringComparison.Ordinal)) { newCommand.Operator = "-"; String removalIndexString = command.Substring(1); try { newCommand.Index = Int32.Parse(removalIndexString, System.Globalization.CultureInfo.InvariantCulture); } catch { } } return newCommand; }
public GenericListPage() { ContextMenuCommand = new ListCommand(this); InitializeComponent(); }
/// <summary> /// Splits a full command string set into an array of ListCommands. /// </summary> /// <remarks>You don't need to use this from your code.</remarks> /// <param name="postedCommands">The set of commands to split.</param> /// <returns>The created array of ListCommands.</returns> public static ListCommand[] Split(String postedCommands) { String[] commandsText = postedCommands.Split(commandSeperator); ListCommand[] commands = new ListCommand[commandsText.Length]; for (Int32 i = 0; i < commandsText.Length; i++) { commands[i] = ListCommand.Parse(commandsText[i]); } return commands; }
public void when_no_arguments_have_been_specified_then_the_list_command_help_text_is_displayed() { var stringWriter = new StringWriter(); typeof(ParserSettings).GetProperty("Consumed", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(Parser.Default.Settings, false); Parser.Default.Settings.HelpWriter = stringWriter; var listCommand = new ListCommand(MockSecureConsole.Object, _mockConnectionFactory.Object, _mockVersionRepositoryFactory.Object); listCommand.Execute(new string[] { }); Assert.That(stringWriter, Is.Not.Null.Or.Empty); }