public void FindMatchingCommandWithArguments_ShouldThrowCustomExceptionIfGenerateWalletArgumentNotPresent() { // Arrange const string command = "generate-wallet"; var commands = new List <string> { command, "help", // <-- Should be argument for command e.g. "wallet-file=test2.json" "show-balances", "wallet-file=test2.json", "send", "btc=1.00", "address=mq6fK8fkFyCy9p53m4GG4fiE2XCKvcwgi4", "wallet-file=test2.json", }; // Act try { var commandWithArgs = CommandIdentifier.FindMatchingCommandWithArguments(command, commands); commandWithArgs.Should().BeNull(); // Should not get here - force a fail commands.Should().BeNull(); } catch (InvalidCommandArgumentFoundException ex) { ex.Message.Should().Contain("Argument should be 'wallet-file=$NameOfWalletFile' actual is:"); ex.Message.Should().Contain("For Command 'generate-wallet'"); } catch (Exception ex) { // Should not get here. ex.Should().BeNull(); } }
public void FindMatchingCommandWithArguments_ShouldThrowCustomExceptionForUnknownCommand() { // Arrange const string command = "Unknown-command"; var commands = new List <string> { "help", "show-balances", "wallet-file=test2.json", "send", "btc=1.00", "address=mq6fK8fkFyCy9p53m4GG4fiE2XCKvcwgi4", "wallet-file=test2.json", }; // Act try { var commandWithArgs = CommandIdentifier.FindMatchingCommandWithArguments(command, commands); commandWithArgs.Should().BeNull(); // Should not get here - force a fail commands.Should().BeNull(); } catch (CommandNotFoundException ex) { ex.Message.Should().Contain("Unknown command provided:"); } catch (Exception ex) { // Should not get here. ex.Should().BeNull(); } }
public void FindMatchingCommandWithArguments_ShouldMatchShowHistoryCorrectly() { // Arrange const string command = "show-history"; var commands = new List <string> { command, "wallet-file=test.json", "send", "btc=1.00", "address=mq6fK8fkFyCy9p53m4GG4fiE2XCKvcwgi4", "wallet-file=test2.json", "recover-wallet", "wallet-file=test.json", "receive", "wallet-file=test1.json", "generate-wallet", "wallet-file=test2.json", "help", "send", "btc=1.00", "address=mq6fK8fkFyCy9p53m4GG4fiE2XCKvcwgi4", "wallet-file=test2.json", }; var expected = new List <string> { command, commands[1], }; // Act var commandWithArgs = CommandIdentifier.FindMatchingCommandWithArguments(command, commands); // Assert commandWithArgs.Should().Equal(expected); }
public Command(TimeSpan startTime, TimeSpan endTime, CommandIdentifier commandIdentifier, object[] parameterValues) { StartTime = startTime; EndTime = endTime; this.CommandIdentifier = commandIdentifier; ParameterValues = parameterValues ?? new object[] { }; }
public static void Main(string[] args) { CommandIdentifier commandIdentifier = new CommandIdentifier(); while (true) { string command = Console.ReadLine(); var output = commandIdentifier.CallCorrespondingFunction(command); Console.WriteLine(output); Console.WriteLine(); } }
/// <summary> /// Processes the next command. /// </summary> /// <returns>Result of processing command.</returns> /// <exception cref="CommandNotFoundException">Command not found for index.</exception> public string ProcessNextCommand() { var result = string.Empty; if (this.CanContinueToProcessCommands()) { var nextCommandToProcess = this.GetNextCommandToProcess(); var commandWithArguments = CommandIdentifier.FindMatchingCommandWithArguments(nextCommandToProcess, this.Commands); result = this.BitcoinLibrary.ProcessCommand(commandWithArguments); this.CleanUpPostCommandProcess(commandWithArguments); } return(result); }
public void FindMatchingCommandWithArguments_ShouldMatchHelpCorrectly() { // Arrange const string command = "help"; var commands = new List <string> { "help", "show-balances", "wallet-file=test2.json", "send", "btc=1.00", "address=mq6fK8fkFyCy9p53m4GG4fiE2XCKvcwgi4", "wallet-file=test2.json", }; var expected = new List <string> { "help", }; // Act var commandWithArgs = CommandIdentifier.FindMatchingCommandWithArguments(command, commands); // Assert commandWithArgs.Should().Equal(expected); }
/// <summary> /// Define a new command to the Commands dictionary. /// </summary> /// <param name="identifier">A CommandIdentifier object containing all the command's information.</param> /// <param name="action">The action this command should execute on run.</param> public void AddCommand(CommandIdentifier identifier, Action <Types.UserLevel, string, List <string> > action) { }