Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        public Interpreter(IEnvironment environment, ICommandExecutor commandExecutor, ICommandFinder commandFinder)
        {
            this.CommandExecutor = commandExecutor;
            this.CommandFinder   = commandFinder;

            ContextStack.Push(environment);
        }
Exemplo n.º 3
0
        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)
                );
        }
Exemplo n.º 4
0
        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)
                );
        }
Exemplo n.º 5
0
 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();
 }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        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))
                );
        }
Exemplo n.º 9
0
        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());
            }
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
0
 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;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="commandFinder"></param>
 public ListCommand(ICommandFinder commandFinder)
 {
     this.commandFinder = commandFinder;
 }