public void GetHelpText_ShouldReturnSpecifiedHelpText() { var parser = new StringListOptionParser(typeof(DataTypesCommandOptions).GetProperty("Strings"), "strings"); parser.OptionHelp = "Help text for option strings."; parser.GetHelpText().Should().Be("Help text for option strings."); }
public void Parse_OptionNotPresent_ShouldAssignDefaultValueToTargetProperty() { var parser = new StringListOptionParser(typeof(DataTypesCommandOptions).GetProperty("Strings"), "strings"); parser.OptionDefaultValue = new List <String> { "value1", "value2" }; var tokens = new List <Token>(); var parseResult = new ParseResult(); var dataTypesCommandOptions = new DataTypesCommandOptions(); parseResult.CommandOptions = dataTypesCommandOptions; parser.Parse(tokens, parseResult); dataTypesCommandOptions.Strings.Should().BeEquivalentTo("value1", "value2"); }
public void Parse_ValidValue_ShouldParseAndAssignValueToTargetProperty() { var parser = new StringListOptionParser(typeof(DataTypesCommandOptions).GetProperty("Strings"), "strings"); var tokens = new List <Token> { new OptionToken("strings") { OptionValues = { "value1", "value2" } } }; var parseResult = new ParseResult(); var dataTypesCommandOptions = new DataTypesCommandOptions(); parseResult.CommandOptions = dataTypesCommandOptions; parser.Parse(tokens, parseResult); dataTypesCommandOptions.Strings.Should().BeEquivalentTo("value1", "value2"); }
public void Parse_RequiredOptionMissing_ShouldAddError() { var parser = new StringListOptionParser(typeof(DataTypesCommandOptions).GetProperty("Strings"), "strings"); parser.IsOptionRequired = true; var tokens = new List <Token>(); var parseResult = new ParseResult(); parseResult.CommandOptions = new DataTypesCommandOptions(); parser.Parse(tokens, parseResult); parseResult.HasErrors.Should().BeTrue(); parseResult.Errors.Should().HaveCount(1); parseResult.Errors[0].Should().BeOfType <OptionMissingError>(); var error = (OptionMissingError)parseResult.Errors[0]; error.OptionName.Should().Be("strings"); error.GetErrorMessage().Should().Be("The option --strings is required."); }
public void Parse_OptionValueMissing_ShouldAddError() { var parser = new StringListOptionParser(typeof(DataTypesCommandOptions).GetProperty("Strings"), "strings"); var tokens = new List <Token> { new OptionToken("strings") }; var parseResult = new ParseResult(); parseResult.CommandOptions = new DataTypesCommandOptions(); parser.Parse(tokens, parseResult); parseResult.HasErrors.Should().BeTrue(); parseResult.Errors.Should().HaveCount(1); parseResult.Errors[0].Should().BeOfType <OptionValueMissingError>(); var error = (OptionValueMissingError)parseResult.Errors[0]; error.OptionName.Should().Be("strings"); error.GetErrorMessage().Should().Be("The option --strings requires a value, but no value was specified."); }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="commandParser">The parser for the command the option belongs to.</param> /// <param name="optionParser">The parser for the option.</param> /// <exception cref="ArgumentNullException"><paramref name="commandParser" /> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="optionParser" /> is null.</exception> public StringListOptionSetup(CommandParser <TCommandOptions> commandParser, StringListOptionParser optionParser) : base(commandParser, optionParser) { }
public void OptionType_ShouldReturnMultiValueOption() { var parser = new StringListOptionParser(typeof(DataTypesCommandOptions).GetProperty("Strings"), "strings"); parser.OptionType.Should().Be(OptionType.MultiValueOption); }
public void OptionName_ShouldReturnNameSpecifiedViaConstructor() { var parser = new StringListOptionParser(typeof(DataTypesCommandOptions).GetProperty("Strings"), "strings"); parser.OptionName.Should().Be("strings"); }
public void OptionDefaultValue_Initially_ShouldReturnNull() { var parser = new StringListOptionParser(typeof(DataTypesCommandOptions).GetProperty("Strings"), "strings"); parser.OptionDefaultValue.Should().BeNull(); }
public void IsOptionRequired_Initially_ShouldReturnFalse() { var parser = new StringListOptionParser(typeof(DataTypesCommandOptions).GetProperty("Strings"), "strings"); parser.IsOptionRequired.Should().BeFalse(); }
public void TargetProperty_ShouldReturnPropertySpecifiedViaConstructor() { var parser = new StringListOptionParser(typeof(DataTypesCommandOptions).GetProperty("Strings"), "strings"); parser.TargetProperty.Should().BeSameAs(typeof(DataTypesCommandOptions).GetProperty("Strings")); }