public void Parse_CustomFormatSettings_ShouldPassCustomFormatToValueParser() { var valueParser = A.Fake <ValueParser>(ob => ob.CallsBaseMethods()); var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); parser.ValueParser = valueParser; parser.TimeSpanFormat = @"hh\:mm"; parser.TimeSpanStyles = TimeSpanStyles.AssumeNegative; parser.FormatProvider = new CultureInfo("de-DE"); var tokens = new List <Token> { new OptionToken("timeSpans") { OptionValues = { "23:59" } } }; var parseResult = new ParseResult(); var dataTypesCommandOptions = new DataTypesCommandOptions(); parseResult.CommandOptions = dataTypesCommandOptions; parser.Parse(tokens, parseResult); TimeSpan timeSpan; A.CallTo(() => valueParser.TryParseTimeSpan("23:59", @"hh\:mm", new CultureInfo("de-DE"), TimeSpanStyles.AssumeNegative, out timeSpan)).MustHaveHappened(); }
public void GetHelpText_ShouldReturnSpecifiedHelpText() { var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); parser.OptionHelp = "Help text for option timeSpans."; parser.GetHelpText().Should().Be("Help text for option timeSpans."); }
public void Parse_OptionNotPresent_ShouldAssignDefaultValueToTargetProperty() { var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); parser.OptionDefaultValue = new List <TimeSpan> { new TimeSpan(23, 59, 59), new TimeSpan(10, 30, 59) }; var tokens = new List <Token>(); var parseResult = new ParseResult(); var dataTypesCommandOptions = new DataTypesCommandOptions(); parseResult.CommandOptions = dataTypesCommandOptions; parser.Parse(tokens, parseResult); dataTypesCommandOptions.TimeSpans.Should().BeEquivalentTo(new TimeSpan(23, 59, 59), new TimeSpan(10, 30, 59)); }
public void Parse_RequiredOptionMissing_ShouldAddError() { var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); 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("timeSpans"); error.GetErrorMessage().Should().Be("The option --timeSpans is required."); }
public void Parse_ValidValue_ShouldParseAndAssignValueToTargetProperty() { var valueParser = A.Fake <ValueParser>(); var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); parser.ValueParser = valueParser; var tokens = new List <Token> { new OptionToken("timeSpans") { OptionValues = { "23:59:59", "10:30:59" } } }; var parseResult = new ParseResult(); var dataTypesCommandOptions = new DataTypesCommandOptions(); parseResult.CommandOptions = dataTypesCommandOptions; TimeSpan timeSpan; A.CallTo(() => valueParser.TryParseTimeSpan("23:59:59", null, new CultureInfo("en-US"), TimeSpanStyles.None, out timeSpan)) .Returns(true) .AssignsOutAndRefParameters(new TimeSpan(23, 59, 59)); A.CallTo(() => valueParser.TryParseTimeSpan("10:30:59", null, new CultureInfo("en-US"), TimeSpanStyles.None, out timeSpan)) .Returns(true) .AssignsOutAndRefParameters(new TimeSpan(10, 30, 59)); parser.Parse(tokens, parseResult); dataTypesCommandOptions.TimeSpans.Should().BeEquivalentTo(new TimeSpan(23, 59, 59), new TimeSpan(10, 30, 59)); A.CallTo(() => valueParser.TryParseTimeSpan("23:59:59", null, new CultureInfo("en-US"), TimeSpanStyles.None, out timeSpan)).MustHaveHappened(); A.CallTo(() => valueParser.TryParseTimeSpan("10:30:59", null, new CultureInfo("en-US"), TimeSpanStyles.None, out timeSpan)).MustHaveHappened(); }
public void Parse_OptionValueMissing_ShouldAddError() { var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); var tokens = new List <Token> { new OptionToken("timeSpans") }; 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("timeSpans"); error.GetErrorMessage().Should().Be("The option --timeSpans requires a value, but no value was specified."); }
public void Parse_InvalidValue_ShouldAddError() { var valueParser = A.Fake <ValueParser>(); var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); parser.ValueParser = valueParser; var tokens = new List <Token> { new OptionToken("timeSpans") { OptionValues = { "NotATimeSpan" } } }; var parseResult = new ParseResult(); parseResult.CommandOptions = new DataTypesCommandOptions(); TimeSpan timeSpan; A.CallTo(() => valueParser.TryParseTimeSpan("NotATimeSpan", null, new CultureInfo("en-US"), TimeSpanStyles.None, out timeSpan)) .Returns(false); parser.Parse(tokens, parseResult); parseResult.HasErrors.Should().BeTrue(); parseResult.Errors.Should().HaveCount(1); parseResult.Errors[0].Should().BeOfType <OptionValueInvalidFormatError>(); var error = (OptionValueInvalidFormatError)parseResult.Errors[0]; error.OptionName.Should().Be("timeSpans"); error.InvalidOptionValue.Should().Be("NotATimeSpan"); error.ExpectedValueFormat.Should().Be("A valid time interval"); error.GetErrorMessage().Should().Be("The value 'NotATimeSpan' of the option --timeSpans has an invalid format. The expected format is: A valid time interval."); }
/// <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 TimeSpanListOptionSetup(CommandParser <TCommandOptions> commandParser, TimeSpanListOptionParser optionParser) : base(commandParser, optionParser) { }
public void OptionDefaultValue_Initially_ShouldReturnNull() { var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); parser.OptionDefaultValue.Should().BeNull(); }
public void IsOptionRequired_Initially_ShouldReturnFalse() { var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); parser.IsOptionRequired.Should().BeFalse(); }
public void FormatProvider_Initially_ShouldReturnValueOfCurrentCulture() { var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); parser.FormatProvider.Should().Be(new CultureInfo("en-US")); }
public void TimeSpanStyles_Initially_ShouldReturnNone() { var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); parser.TimeSpanStyles.Should().Be(TimeSpanStyles.None); }
public void TargetProperty_ShouldReturnPropertySpecifiedViaConstructor() { var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); parser.TargetProperty.Should().BeSameAs(typeof(DataTypesCommandOptions).GetProperty("TimeSpans")); }
public void OptionType_ShouldReturnMultiValueOption() { var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); parser.OptionType.Should().Be(OptionType.MultiValueOption); }
public void OptionName_ShouldReturnNameSpecifiedViaConstructor() { var parser = new TimeSpanListOptionParser(typeof(DataTypesCommandOptions).GetProperty("TimeSpans"), "timeSpans"); parser.OptionName.Should().Be("timeSpans"); }