Beispiel #1
0
        public void ParsingTest(string command, bool resultShouldParse, ParserNotation notation)
        {
            var target      = new CommandParser(notation);
            var commandTree = target.Parse(command);

            // Assert
            if (resultShouldParse)
            {
                Assert.True(commandTree.Any());
            }
            else
            {
                Assert.False(commandTree.Any());
            }
        }
Beispiel #2
0
        public void RunnerTest(string commandLineArguments, ResultState expectedResultValidate, ResultState expectedResultRun, ParserNotation notation)
        {
            var configuration = new CommandConfiguration();
            configuration.CommandAssemblies.Add(Assembly.GetExecutingAssembly());
            var runner = new CommandRunner(new CommandParser(notation), new CommandLookup(configuration));
            var result1 = runner.Validate(commandLineArguments);
            var result2 = runner.Run(commandLineArguments);

            // Assert
            Assert.NotNull(result1);
            Assert.NotNull(result2);
            Assert.True(result1.State == expectedResultValidate);
            Assert.True(result2.State == expectedResultRun);
            Assert.NotNull(result1.CommandInfo);
        }
Beispiel #3
0
        public void ParsingTest(string command, bool resultShouldParse, ParserNotation notation)
        {
            var target = new CommandParser(notation);
            var commandTree = target.Parse(command);

            // Assert
            if (resultShouldParse)
            {
                Assert.True(commandTree.Any());
            }
            else
            {
                Assert.False(commandTree.Any());
            }
        }
Beispiel #4
0
        public void MappingTest(string commandLineArguments, ResultState expectedResult, string firstArgumentValue, ParserNotation notation)
        {
            // Setup
            var parser = new CommandParser(notation);
            var args = parser.Parse(commandLineArguments);
            var configuration = new CommandConfiguration();
            configuration.CommandAssemblies.Add(Assembly.GetExecutingAssembly());
            var lookup = new CommandLookup(configuration);
            var command = lookup.GetCommand(args.First().Key);
            Assert.NotNull(args);
            Assert.NotNull(command);

            // Test
            var target = new CommandMapper();
            var result = target.Map(args.Skip(1), command.Arguments);

            // Assert
            Assert.NotNull(result);
            Assert.True(result.State == expectedResult);
            Assert.True(firstArgumentValue == null || firstArgumentValue == result?.ResultArguments?.First().ToString());
        }
        [InlineData("dummysearch -take=10 -language=de", ResultState.MissingArguments, null, ParserNotation.Unix)]                             // check required arguments
        public void MappingTest(string commandLineArguments, ResultState expectedResult, string firstArgumentValue, ParserNotation notation)
        {
            // Setup
            var parser        = new CommandParser(notation);
            var args          = parser.Parse(commandLineArguments);
            var configuration = new CommandConfiguration();

            configuration.CommandAssemblies.Add(Assembly.GetExecutingAssembly());
            var lookup  = new CommandLookup(configuration);
            var command = lookup.GetCommand(args.First().Key);

            Assert.NotNull(args);
            Assert.NotNull(command);

            // Test
            var target = new CommandMapper();
            var result = target.Map(args.Skip(1), command.Arguments);

            // Assert
            Assert.NotNull(result);
            Assert.True(result.State == expectedResult);
            Assert.True(firstArgumentValue == null || firstArgumentValue == result?.ResultArguments?.First().ToString());
        }
Beispiel #6
0
        //[InlineData(@"throwexceptiontask", ResultState.Success, ResultState.ErrorWhileExecuting, ParserNotation.Unix)]
        public void RunnerTest(string commandLineArguments, ResultState expectedResultValidate, ResultState expectedResultRun, ParserNotation notation)
        {
            var configuration = new CommandConfiguration();

            configuration.CommandAssemblies.Add(Assembly.GetExecutingAssembly());
            var runner  = new CommandRunner(new CommandParser(notation), new CommandLookup(configuration));
            var result1 = runner.Validate(commandLineArguments);
            var result2 = runner.Run(commandLineArguments);

            // Assert
            Assert.NotNull(result1);
            Assert.NotNull(result2);
            Assert.True(result1.State == expectedResultValidate);
            Assert.True(result2.State == expectedResultRun);
            Assert.NotNull(result1.CommandInfo);
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandParser"/> class.
 /// </summary>
 /// <param name="notation">The notation.</param>
 public CommandParser(ParserNotation notation)
 {
     _notation = notation;
 }
Beispiel #8
0
        private readonly List<string> _systemCommands = new List<string>() { "help", "exit", "quit", "cancel" }; // mode

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="CommandParser"/> class.
        /// </summary>
        /// <param name="notation">The notation.</param>
        public CommandParser(ParserNotation notation)
        {
            _notation = notation;
        }