예제 #1
0
 private static void SetValueForOption(CommandOptionInfo option, CommandLineApplication command)
 {
     option.SetValue(command.Option(option.Template,
                                    option.AnnotatedDescription,
                                    option.CommandOptionType,
                                    _ => {},
                                    option.Inherited,
                                    option.TypeDisplayName,
                                    option.DefaultValue,
                                    option.IsMultipleType,
                                    option.AllowedValues));
 }
예제 #2
0
        public void CanGiveValueWhenUserHasNotProvidedValueAndThereIsNoDefaultValue()
        {
            AppSettings appSettings = new AppSettings();

            ValueMachine valueMachine = new ValueMachine(appSettings);

            ParameterInfo parameterInfo =
                typeof(ValueMachineTests).GetMethod("TestMethodWithNoDefaultValue").GetParameters()[0];

            CommandOptionInfo optionInfo = new CommandOptionInfo(parameterInfo, appSettings);

            optionInfo.SetValue(new CommandOption("--test", CommandOptionType.SingleValue));

            object value = valueMachine.GetValue(optionInfo);

            value.Should().Be(0);
        }
예제 #3
0
        public void CanParIntegers(string propertyName, Type valueType, string value, object typedValue)
        {
            SingleValueParser valueParser       = new SingleValueParser(valueType);
            PropertyInfo      propertyInfo      = typeof(PropertyModel).GetProperty(propertyName);
            AppSettings       appSettings       = new AppSettings();
            CommandOptionInfo commandOptionInfo = new CommandOptionInfo(propertyInfo, appSettings);

            //set value
            CommandOption option = new CommandOption("--test", CommandOptionType.SingleValue);

            commandOptionInfo.SetValue(option);
            commandOptionInfo.ValueInfo.Values = new List <string>()
            {
                value
            };

            object parsedValue = valueParser.Parse(commandOptionInfo);

            parsedValue.Should().BeOfType(valueType);
            parsedValue.Should().Be(typedValue);
        }