示例#1
0
 /// <summary>
 /// Adds a new option
 /// </summary>
 /// <param name="attribute"></param>
 /// <param name="propertyType"></param>
 internal void AddOptionFromAttribute(OptionDefinitionAttribute attribute, Type propertyType)
 {
     if (propertyType == null)
     {
         throw new ArgumentNullException(nameof(propertyType));
     }
     this.Options.Add(Option.FromAttribute(attribute).OnTargetProperty(propertyType));
 }
示例#2
0
        public void ParseDifferentOption_ThrowsException()
        {
            //************* GIVEN
            var test = new OptionDefinitionAttribute("s", "singleOutput", description: @"manage output as unique file instead to split it into several ones");

            this._Parser = new OptionParser(Option.FromAttribute(test).OnTargetProperty(typeof(bool)));

            //************* WHEN
            this._Parser.Parse("--t");

            //************* ASSERT
        }
示例#3
0
        public void ParseOptionWithArgumentsAndDefault_ReturnsTheDefaultIfThereIsNoValue()
        {
            //************* GIVEN
            var test = new OptionDefinitionAttribute("v", "verbosity", description: @"manage output as unique file instead to split it into several ones", mandatory: false, defaultValue: "DEFVAL");

            this._Parser = new OptionParser(Option.FromAttribute(test).OnTargetProperty(typeof(string)));

            //************* WHEN
            var returnedValue = this._Parser.Parse("--v");

            //************* ASSERT
            Assert.IsNotNull(returnedValue);
            Assert.IsInstanceOfType(returnedValue, typeof(string));
            Assert.AreEqual("DEFVAL", (string)returnedValue);
        }
示例#4
0
        public void ParseBoolOptionByLongCode_ReturnsTrue()
        {
            //************* GIVEN
            var test = new OptionDefinitionAttribute("s", "singleOutput", description: @"manage output as unique file instead to split it into several ones");

            this._Parser = new OptionParser(Option.FromAttribute(test).OnTargetProperty(typeof(bool)));

            //************* WHEN
            var returnedValue = this._Parser.Parse("--singleOutput");

            //************* ASSERT
            Assert.IsNotNull(returnedValue);
            Assert.IsInstanceOfType(returnedValue, typeof(bool));
            Assert.IsTrue((bool)returnedValue);
        }