/// <summary> /// Return command finder /// </summary> /// <param name="provider"></param> /// <returns></returns> private static ICommandFinder GetCommandFinder(IServiceProvider provider) { ICommandFinderFactory factory = provider.GetRequiredService <ICommandFinderFactory>(); ICommandFinder finder = factory.CreateCommandFinder(new[] { typeof(CommandTest).Assembly }); return(finder); }
public Interpreter(IEnvironment environment, ICommandExecutor commandExecutor, ICommandFinder commandFinder) { this.CommandExecutor = commandExecutor; this.CommandFinder = commandFinder; ContextStack.Push(environment); }
public void BelongingCommandsFound() { IServiceProvider provider = GetServiceProvider(); ICommandFinder finder = GetCommandFinder(provider); IEnumerable <CommandDescriptor> commands = finder.GetCommands(typeof(SpecificCommandSet)).OrderBy(c => c.Name); Assert.Collection( commands, descriptor => Assert.IsType <ExitCommand>(descriptor.Command), descriptor => Assert.IsType <ListCommand>(descriptor.Command) ); }
public void DefaultCommandsFound() { IServiceProvider provider = GetServiceProvider(); ICommandFinder finder = GetCommandFinder(provider); IEnumerable <CommandDescriptor> commands = finder.GetCommands().OrderBy(c => c.Name); Assert.Collection( commands, descriptor => Assert.IsType <ByeCommand>(descriptor.Command), descriptor => Assert.IsType <SayCommand>(descriptor.Command) ); }
public Shell(IValueConverter valueConverter, IWriteableHistory history, IFileSystem fileSystem, ICommandFinder commandFinder, IEnvironment environment, ICommandExecutor commandExecutor, ILsfRunner lsfRunner = null, ConsoleConfiguration config = null) { this.ValueConverter = valueConverter; this.History = history; this.FileSystem = fileSystem; this.CommandFinder = commandFinder; this._Environment = environment; this.CommandExecutor = commandExecutor; this.LsfRunner = lsfRunner ?? new LsfRunner(environment, commandFinder, fileSystem, commandExecutor); this.Config = config ?? new ConsoleConfiguration(); }
public void TryGetBelongingCommand() { IServiceProvider provider = GetServiceProvider(); ICommandFinder finder = GetCommandFinder(provider); if (finder.TryGetCommand("list", typeof(SpecificCommandSet), out ICommand? listCommand)) { Assert.True(true); Assert.NotNull(listCommand); } else { Assert.True(false); Assert.Null(listCommand); } }
public void TryGetCommand() { IServiceProvider provider = GetServiceProvider(); ICommandFinder finder = GetCommandFinder(provider); if (finder.TryGetCommand("say", out ICommand? sayCommand)) { Assert.True(true); Assert.NotNull(sayCommand); } else { Assert.True(false); Assert.Null(sayCommand); } }
public void ListCommand() { IServiceProvider provider = GetServiceProvider(); ICommandFinder finder = GetCommandFinder(provider); List <string> commands = new (); ICommand command = finder.GetCommand("list", belongsTo: typeof(SpecificCommandSet)); command.Execute(commands); this.testOutputHelper.WriteLine(string.Join(Environment.NewLine, commands)); Assert.Collection( commands.OrderBy(x => x), cmdDetails => Assert.Equal("Usage: bye", cmdDetails.Substring(0, 10)), cmdDetails => Assert.Equal("Usage: say", cmdDetails.Substring(0, 10)) ); }
static void ExecuteCommand(string[] args) { if (finder == null) { finder = new CommandFinder(); finder.Initialize(); } var command = finder.Search(args[0]); if (command == null) { Console.Error.WriteLine($"[ERROR] A command, \"{args[0]}\" is not found."); } else { command.Execute(args.Skip(1).ToArray()); } }
public void NullCommand() { IServiceProvider provider = GetServiceProvider(); ICommandFinder finder = GetCommandFinder(provider); string someCommandWhichRlyDonTExists = "some command which rly don't exists"; ICommand command = finder.GetCommand(someCommandWhichRlyDonTExists); Assert.IsType <NullCommand>(command); Assert.Equal(string.Empty, command.GetDetails()); Assert.Equal(someCommandWhichRlyDonTExists, ((NullCommand)command).RequestedCommandName); try { command.Execute(true, string.Empty, new object(), 1, 1.1); Assert.True(true); } catch (Exception) { Assert.True(false); } }
public LsfRunner(IEnvironment environment, ICommandFinder commandFinder, IFileSystem fileSystem, ICommandExecutor commandExecutor) { this.Interpreter = new Interpreter(environment, commandExecutor, commandFinder); this.Preprocessor = new Preprocessor(fileSystem); this.FileSystem = fileSystem; }
/// <summary> /// Ctor /// </summary> /// <param name="commandFinder"></param> public ListCommand(ICommandFinder commandFinder) { this.commandFinder = commandFinder; }