public void ShouldThrowAnExceptionOnUnexpectedMultipleOccurencesOfArgument() { var args = new[] { "--value", "5", "--value", "6" }; var parser = new OptionsParser(new ParserConfiguration { ThrowValidationException = true }); var options = new OptionsWithInt(); Assert.Throws <ValidationException>(() => parser.Parse(options, args)); }
public void ShouldHandleIntOptionWithDefaultValueFollowedByString() { var args = new [] { "--value", "test" }; var parser = new OptionsParser(new ParserConfiguration { AllowUnexpectedArguments = true }); var options = new OptionsWithInt(); parser.Parse(options, args); Assert.AreEqual(-1, options.Value); Assert.AreEqual(1, parser.UnexpectedArguments.Count()); Assert.AreEqual("test", parser.UnexpectedArguments.First().Value); Assert.AreEqual("test", parser.RecreateUnparsedArguments()); }
public void ShouldNotParseAfterDoubleHyphen() { var args = new [] { "--", "--value", "test" }; var parser = new OptionsParser(new ParserConfiguration { AllowUnexpectedArguments = true }); var options = new OptionsWithInt(); parser.Parse(options, args); Assert.AreEqual(-1, options.Value); Assert.AreEqual(0, parser.ParsedOptions.Count()); Assert.AreEqual(2, parser.UnexpectedArguments.Count()); Assert.AreEqual("--value", parser.UnexpectedArguments.ElementAt(0).Value); Assert.AreEqual("test", parser.UnexpectedArguments.ElementAt(1).Value); Assert.AreEqual("--value test", parser.RecreateUnparsedArguments()); }
public void ShouldThrowAnExceptionOnUnexpectedMultipleOccurencesOfArgument() { var args = new[] { "--value", "5", "--value", "6" }; var parser = new OptionsParser(new ParserConfiguration { ThrowValidationException = true }); var options = new OptionsWithInt(); parser.Parse(options, args); }