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)); }
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); }
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); }