public void ParsePositionalOption_WithTooManyInputArguments_ReturnsFailedResult() { Func <string, string, string, IParsingResult <Tuple <string, string, string> > > parse = (value1, value2, value3) => ParsingResult <Tuple <string, string, string> > .SuccessfulResult(Tuple.Create(value1, value2, value3)); var option1 = StringOption.Create("value1 option", "value1"); var option2 = StringOption.Create("value2 option", "value2"); var option3 = StringOption.Create("value3 option", "value2"); var multiStringOption = new PositionalOption <string, string, string, Tuple <string, string, string> >(parse, true, true, "", option1, option2, option3, "positional-option"); OptionCollection <Tuple <Tuple <string, string, string>, string> > collection = new OptionCollection <Tuple <Tuple <string, string, string>, string> >(); collection.Add(multiStringOption); collection.Add(option1); string[] stringInputArgument = { "--positional-option", "1", "2", "3", "4", "--value1", "value" }; // act var result = collection.Parse(stringInputArgument); // assert IParsingResult <Tuple <Tuple <string, string, string>, string> > failedResult; Assert.False(result.Validate(out failedResult)); }
public void ParsePositionalOption_WithDefaultInputArguments_ReturnsMultipleStrings() { // arrange string inputArgument1 = "input"; string inputArgument2 = "input2"; Func <string, string, string, IParsingResult <Tuple <string, string, string> > > parse = (value1, value2, value3) => ParsingResult <Tuple <string, string, string> > .SuccessfulResult(Tuple.Create(value1, value2, value3)); var option1 = StringOption.CreateRequired("value1 option", "value1"); var option2 = StringOption.CreateRequired("value2 option", "value2"); var option3 = StringOption.Create("value3 option", "value2"); var multiStringOption = new PositionalOption <string, string, string, Tuple <string, string, string> >(parse, true, true, "", option1, option2, option3, "positional-option"); string[] stringInputArgument = { "--positional-option", inputArgument1, inputArgument2 }; // act var result = multiStringOption.Parse(stringInputArgument); // assert Assert.True(result.Success); Assert.Equal(inputArgument1, result.Result[0].Item1); Assert.Equal(inputArgument2, result.Result[0].Item2); Assert.Null(result.Result[0].Item3); }
public void ParseOptionInfo_WithStringInputArgument_ReturnsStringInputArgument() { // arrange string inputArgument = "input"; StringOption valueOption = StringOption.Create("value option", "value"); string[] stringInputArgument = { "--value", inputArgument }; // act string parsedResult = valueOption.Parse(stringInputArgument).Result; // assert Assert.Equal(inputArgument, parsedResult); }
public void ParseOptionInfo_WithMissingInputArgument_ReturnsFailedResult() { // arrange StringOption valueOption = StringOption.Create("value option", "value"); string[] stringInputArgument = { "--value" }; // act ParsingResult <string> result = valueOption.Parse(stringInputArgument); // assert Assert.False(result.Success); Assert.Contains("required", result.ErrorMessage); }
public void ParseRequiredPositionalOption_WithNoInputArguments_ReturnsFailedResult() { Func <string, string, string, IParsingResult <Tuple <string, string, string> > > parse = (value1, value2, value3) => ParsingResult <Tuple <string, string, string> > .SuccessfulResult(Tuple.Create(value1, value2, value3)); var option1 = StringOption.Create("value1 option", "value1"); var option2 = StringOption.Create("value2 option", "value2"); var option3 = StringOption.Create("value3 option", "value2"); var multiStringOption = new PositionalOption <string, string, string, Tuple <string, string, string> >(parse, true, true, "", option1, option2, option3, "positional-option"); string[] stringInputArgument = { }; // act var result = multiStringOption.Parse(stringInputArgument); // assert Assert.False(result.Success); }
public void ParseMultiStringOption_WithMultipleStringInputArguments_ReturnsMultipleStrings() { // arrange string inputArgument1 = "input"; string inputArgument2 = "input2"; var multiStringOption = new MultiValueOption <string>(StringOption.Create("value option", "value")); string[] stringInputArgument = { "--value", inputArgument1, "--value", inputArgument2 }; // act var result = multiStringOption.Parse(stringInputArgument); // assert Assert.True(result.Success); Assert.Equal(inputArgument1, result.Result[0]); Assert.Equal(inputArgument2, result.Result[1]); }