Ejemplo n.º 1
0
        public void EnsureDefaultCommandIsSetCorrectly()
        {
            var argumentInfo = ArgumentClassInfo.FromType(typeof(CommandClassWithDefault));

            argumentInfo.CommandInfos.Should().HaveCount(2);
            argumentInfo.DefaultCommand.Should().NotBeNull();
        }
Ejemplo n.º 2
0
        public override void InitializeFromString(T instance, string args)
        {
            try
            {
                CommandLineEngine.HandledCommandLineArgument   += OnMappedParameter;
                CommandLineEngine.UnhandledCommandLineArgument += OnUnmappedParameter;
                base.InitializeFromString(instance, args);

                var info = ArgumentClassInfo.FromType <T>();
                foreach (var property in info.Properties)
                {
                    application.Argument(property.ParameterName, property.PropertyInfo.GetValue(instance));
                }
            }
            finally
            {
                CommandLineEngine.HandledCommandLineArgument   -= OnMappedParameter;
                CommandLineEngine.UnhandledCommandLineArgument -= OnUnmappedParameter;
            }

            void OnMappedParameter(object sender, CommandLineArgumentEventArgs e)
            {
                var value = e.PropertyInfo.GetValue(e.Instance);

                application.MappedCommandLineParameter(e.PropertyInfo);
                application.MappedCommandLineParameter(e.PropertyInfo, value);
                application.MappedCommandLineParameter(e.PropertyInfo.Name, value);
            }

            void OnUnmappedParameter(object sender, CommandLineArgumentEventArgs e)
            {
                application.UnmappedCommandLineParameter(e.Argument.Name, e.Argument.Value);
            }
        }
Ejemplo n.º 3
0
        public void EnsureHasCommandsIsComputedCorrectly()
        {
            var argumentInfo = ArgumentClassInfo.FromType(typeof(ApplicationArgs));

            argumentInfo.HasCommands.Should().BeTrue();

            argumentInfo = ArgumentClassInfo.FromType(typeof(ExecuteArgs));
            argumentInfo.HasCommands.Should().BeFalse();
        }
Ejemplo n.º 4
0
        private static HelpCommandArguments GetArguments <T>(params string[] args)
        {
            var argumentDictionary = new Dictionary <string, CommandLineArgument>();
            int index = 0;

            foreach (var arg in args)
            {
                argumentDictionary[arg] = new CommandLineArgument {
                    Index = index, Name = arg
                };
                index++;
            }

            return(new HelpCommandArguments {
                ArgumentInfos = ArgumentClassInfo.FromType <T>(), ArgumentDictionary = argumentDictionary
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        ///    Executes the command that was specified in the command line arguments. If no argument was specified but the IsDefaultCommand property was set at one of the commands, a
        ///    simulated command
        /// </summary>
        /// <returns></returns>
        protected virtual bool ExecuteCommand()
        {
            var applicationArguments = ArgumentClassInfo.FromType <T>();

            if (!applicationArguments.HasCommands)
            {
                return(false);
            }

            ICommand command = GetMappedCommand();

            if (command == null)
            {
                return(false);
            }

            RunWithCommand(command);
            return(true);
        }
Ejemplo n.º 6
0
        public void EnsureCommandsAreSetCorrectly()
        {
            var argumentInfo = ArgumentClassInfo.FromType(typeof(CommandClassWithHelp));

            argumentInfo.CommandInfos.Should().HaveCount(2);
        }
Ejemplo n.º 7
0
        public void EnsurePropertiesAreSetCorrectly()
        {
            var argumentInfo = ArgumentClassInfo.FromType(typeof(CommandClassWithHelp));

            argumentInfo.Properties.Should().HaveCount(4);
        }
Ejemplo n.º 8
0
        public void EnsureHelpCommandIsSetCorrectly()
        {
            var argumentInfo = ArgumentClassInfo.FromType(typeof(CommandClassWithHelp));

            argumentInfo.HelpCommand.Should().NotBeNull();
        }