Ejemplo n.º 1
0
        public void Parse_ValuePresent_ShouldAddError()
        {
            var parser = new BooleanOptionParser(typeof(DataTypesCommandOptions).GetProperty("Boolean"), "boolean");

            var tokens = new List <Token>
            {
                new OptionToken("boolean")
                {
                    OptionValues = { "value" }
                }
            };
            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 <InvalidOptionError>();

            var error = (InvalidOptionError)parseResult.Errors[0];

            error.OptionName.Should().Be("boolean");
            error.GetErrorMessage().Should().Be("The option --boolean is invalid: This option does not support any values.");
        }
Ejemplo n.º 2
0
        public void GetHelpText_ShouldReturnSpecifiedHelpText()
        {
            var parser = new BooleanOptionParser(typeof(DataTypesCommandOptions).GetProperty("Boolean"), "boolean");

            parser.OptionHelp = "Help text for option boolean.";

            parser.GetHelpText().Should().Be("Help text for option boolean.");
        }
Ejemplo n.º 3
0
        public void Parse_OptionNotPresent_ShouldSetTargetPropertyToTrue()
        {
            var parser = new BooleanOptionParser(typeof(DataTypesCommandOptions).GetProperty("Boolean"), "boolean");

            var tokens                  = new List <Token>();
            var parseResult             = new ParseResult();
            var dataTypesCommandOptions = new DataTypesCommandOptions();

            parseResult.CommandOptions = dataTypesCommandOptions;

            parser.Parse(tokens, parseResult);

            dataTypesCommandOptions.Boolean.Should().BeFalse();
        }
 /// <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 BooleanOptionSetup(CommandParser <TCommandOptions> commandParser, BooleanOptionParser optionParser) : base(commandParser, optionParser)
 {
 }
Ejemplo n.º 5
0
        public void OptionType_ShouldReturnValuelessOption()
        {
            var parser = new BooleanOptionParser(typeof(DataTypesCommandOptions).GetProperty("Boolean"), "boolean");

            parser.OptionType.Should().Be(OptionType.ValuelessOption);
        }
Ejemplo n.º 6
0
        public void OptionName_ShouldReturnNameSpecifiedViaConstructor()
        {
            var parser = new BooleanOptionParser(typeof(DataTypesCommandOptions).GetProperty("Boolean"), "boolean");

            parser.OptionName.Should().Be("boolean");
        }
Ejemplo n.º 7
0
        public void IsOptionRequired_ShouldReturnFalse()
        {
            var parser = new BooleanOptionParser(typeof(DataTypesCommandOptions).GetProperty("Boolean"), "boolean");

            parser.IsOptionRequired.Should().BeFalse();
        }
Ejemplo n.º 8
0
        public void TargetProperty_ShouldReturnPropertySpecifiedViaConstructor()
        {
            var parser = new BooleanOptionParser(typeof(DataTypesCommandOptions).GetProperty("Boolean"), "boolean");

            parser.TargetProperty.Should().BeSameAs(typeof(DataTypesCommandOptions).GetProperty("Boolean"));
        }