Exemplo n.º 1
0
        /// <summary>
        /// Executes the specified command line.
        /// </summary>
        /// <param name="commandString">The command line.</param>
        public void Execute(string commandString)
        {
            CommandLine          commandLine    = new CommandLine(commandString);
            IDangrCommandFactory commandFactory = this.GetCommandFactory(commandLine.CommandName);
            IDangrCommand        command        = commandFactory.Create(commandLine);

            command.Execute(this);
        }
Exemplo n.º 2
0
        public void Parse_Bool()
        {
            CommandLine          commandLine = new CommandLine($"Types -Bool");
            IDangrCommandFactory factory     = new DangrCommandFactory <TypeCommand>();

            IDangrCommand command = factory.Create(commandLine);

            Validate.Value.IsType <TypeCommand>(command, "Wrong type of command created.");
            TypeCommand typeCommand = (TypeCommand)command;

            Validate.Value.IsTrue(typeCommand.Bool, "Wrong value assigned arg.");
        }
Exemplo n.º 3
0
        public void Parse_String()
        {
            const string         expected    = "1234.5";
            CommandLine          commandLine = new CommandLine($"Types -String {expected}");
            IDangrCommandFactory factory     = new DangrCommandFactory <TypeCommand>();

            IDangrCommand command = factory.Create(commandLine);

            Validate.Value.IsType <TypeCommand>(command, "Wrong type of command created.");
            TypeCommand typeCommand = (TypeCommand)command;

            Validate.Value.AreEqual(expected, typeCommand.String, "Wrong value assigned arg.");
        }
Exemplo n.º 4
0
        public void Parse_Int()
        {
            const int            expected    = 12345;
            CommandLine          commandLine = new CommandLine($"Types -Int {expected}");
            IDangrCommandFactory factory     = new DangrCommandFactory <TypeCommand>();

            IDangrCommand command = factory.Create(commandLine);

            Validate.Value.IsType <TypeCommand>(command, "Wrong type of command created.");
            TypeCommand typeCommand = (TypeCommand)command;

            Validate.Value.AreEqual(expected, typeCommand.Int, "Wrong value assigned arg.");
        }
Exemplo n.º 5
0
        public void Parse_Decimal()
        {
            const decimal        expected    = 12.345M;
            CommandLine          commandLine = new CommandLine($"Types -Decimal {expected}");
            IDangrCommandFactory factory     = new DangrCommandFactory <TypeCommand>();

            IDangrCommand command = factory.Create(commandLine);

            Validate.Value.IsType <TypeCommand>(command, "Wrong type of command created.");
            TypeCommand typeCommand = (TypeCommand)command;

            Validate.Value.AreEqual(expected, typeCommand.Decimal, "Wrong value assigned arg.");
        }
Exemplo n.º 6
0
        public void Create_WithNamedArg()
        {
            CommandLine          commandLine = new CommandLine("ValidCommand -MandatoryArg 1 -Named0 named");
            IDangrCommandFactory factory     = new DangrCommandFactory <ValidCommand>();
            IDangrCommand        command     = factory.Create(commandLine);

            Validate.Value.IsType <ValidCommand>(command, "Wrong type of command created.");
            ValidCommand validCommand = (ValidCommand)command;

            Validate.Value.AreEqual("1", validCommand.MandatoryArg,
                                    "Wrong value assigned for madatory arg.");
            Validate.Value.AreEqual("named", validCommand.Named0,
                                    "Wrong value assigned for named arg.");
            Validate.Value.IsNull(validCommand.Parameter0,
                                  "Value should not have been assigned for positional arg 0.");
            Validate.Value.IsNull(validCommand.Parameter1,
                                  "Value should not have been assigned for positional arg 1.");
            Validate.Value.IsFalse(validCommand.Flag0, "Flag0 should not have been set.");
            Validate.Value.IsNull(validCommand.SkipThisProperty,
                                  "Value should not have been assigned for non parameter property.");
        }