public void CanIdentifyArgumentInfoFromMethodsUsingParameterInfo( string parameterName, CommandOptionType commandOptionType, object defaultValue, string typeDisplayName, //string parameterDetails, string annotatedDescription, //string effectiveDescription, string template, Type type //bool showParameterDetails ) { MethodInfo methodInfo = typeof(TestApplication).GetMethod("Execute"); var parameters = methodInfo.GetParameters(); var parameter = parameters.Single(p => p.Name == parameterName); CommandOptionInfo commandParameterInfo = new CommandOptionInfo(parameter, new AppSettings { MethodArgumentMode = ArgumentMode.Option }); commandParameterInfo.CommandOptionType.Should().Be(commandOptionType, nameof(commandOptionType)); commandParameterInfo.DefaultValue.Should().Be(defaultValue, nameof(defaultValue)); commandParameterInfo.TypeDisplayName.Should().Be(typeDisplayName, nameof(typeDisplayName)); // commandParameterInfo.Details.Should().Be(parameterDetails, nameof(parameterDetails)); commandParameterInfo.AnnotatedDescription.Should().Be(annotatedDescription, nameof(annotatedDescription)); // commandParameterInfo.EffectiveDescription.Should().Be(effectiveDescription, nameof(effectiveDescription)); commandParameterInfo.Template.Should().Be(template, nameof(template)); commandParameterInfo.Type.Should().Be(type, nameof(type)); }
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 CanCreateCommandOptionInfoFromPropertyInfo() { PropertyInfo propertyInfo = typeof(ParameterModel).GetProperty("foreignKeyId"); CommandOptionInfo commandOptionInfo = new CommandOptionInfo(propertyInfo, new AppSettings()); // commandOptionInfo.Details.Should().Be("Int32", "Details"); commandOptionInfo.Template.Should().Be("--foreignKeyId"); commandOptionInfo.LongName.Should().Be("foreignKeyId"); commandOptionInfo.TypeDisplayName.Should().Be(Constants.TypeDisplayNames.Number); // commandOptionInfo.EffectiveDescription.Should().Be("Int32".PadRight(Constants.PadLength)); commandOptionInfo.IsMultipleType.Should().BeFalse(); }
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); }