public void Parse_MoreThanOneOptionValue_ShouldAddError() { var parser = new GuidOptionParser(typeof(DataTypesCommandOptions).GetProperty("Guid"), "guid"); var tokens = new List <Token> { new OptionToken("guid") { OptionValues = { "13d02a84-84f7-4a2d-8f09-2f96defb8c79", "9e6a5202-102f-4eb9-a217-0a58f4db40b6" } } }; 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 <OptionMultipleValuesError>(); var error = (OptionMultipleValuesError)parseResult.Errors[0]; error.OptionName.Should().Be("guid"); error.GetErrorMessage().Should().Be("Multiple values are given for the option --guid, but the option expects a single value."); }
public void Parse_ValidValue_ShouldParseAndAssignValueToTargetProperty() { var valueParser = A.Fake <ValueParser>(); var parser = new GuidOptionParser(typeof(DataTypesCommandOptions).GetProperty("Guid"), "guid"); parser.ValueParser = valueParser; var tokens = new List <Token> { new OptionToken("guid") { OptionValues = { "501a44e0-6d8f-4dd8-994e-773300572d37" } } }; var parseResult = new ParseResult(); var dataTypesCommandOptions = new DataTypesCommandOptions(); parseResult.CommandOptions = dataTypesCommandOptions; Guid guid; A.CallTo(() => valueParser.TryParseGuid("501a44e0-6d8f-4dd8-994e-773300572d37", null, out guid)) .Returns(true) .AssignsOutAndRefParameters(new Guid("501a44e0-6d8f-4dd8-994e-773300572d37")); parser.Parse(tokens, parseResult); dataTypesCommandOptions.Guid.Should().Be(new Guid("501a44e0-6d8f-4dd8-994e-773300572d37")); A.CallTo(() => valueParser.TryParseGuid("501a44e0-6d8f-4dd8-994e-773300572d37", null, out guid)).MustHaveHappened(); }
public void Parse_CustomFormatSettings_ShouldPassCustomFormatToValueParser() { var valueParser = A.Fake <ValueParser>(ob => ob.CallsBaseMethods()); var parser = new GuidOptionParser(typeof(DataTypesCommandOptions).GetProperty("Guid"), "guid"); parser.ValueParser = valueParser; parser.GuidFormat = "X"; var tokens = new List <Token> { new OptionToken("guid") { OptionValues = { "{0x501a44e0,0x6d8f,0x4dd8,{0x99,0x4e,0x77,0x33,0x00,0x57,0x2d,0x37}}" } } }; var parseResult = new ParseResult(); var dataTypesCommandOptions = new DataTypesCommandOptions(); parseResult.CommandOptions = dataTypesCommandOptions; parser.Parse(tokens, parseResult); Guid guid; A.CallTo(() => valueParser.TryParseGuid("{0x501a44e0,0x6d8f,0x4dd8,{0x99,0x4e,0x77,0x33,0x00,0x57,0x2d,0x37}}", "X", out guid)).MustHaveHappened(); }
public void Parse_OptionNotPresent_ShouldAssignDefaultValueToTargetProperty() { var parser = new GuidOptionParser(typeof(DataTypesCommandOptions).GetProperty("Guid"), "guid"); parser.OptionDefaultValue = new Guid("501a44e0-6d8f-4dd8-994e-773300572d37"); var tokens = new List <Token>(); var parseResult = new ParseResult(); var dataTypesCommandOptions = new DataTypesCommandOptions(); parseResult.CommandOptions = dataTypesCommandOptions; parser.Parse(tokens, parseResult); dataTypesCommandOptions.Guid.Should().Be(new Guid("501a44e0-6d8f-4dd8-994e-773300572d37")); }
public void Parse_RequiredOptionMissing_ShouldAddError() { var parser = new GuidOptionParser(typeof(DataTypesCommandOptions).GetProperty("Guid"), "guid"); 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("guid"); error.GetErrorMessage().Should().Be("The option --guid is required."); }
public void Parse_OptionValueMissing_ShouldAddError() { var parser = new GuidOptionParser(typeof(DataTypesCommandOptions).GetProperty("Guid"), "guid"); var tokens = new List <Token> { new OptionToken("guid") }; 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("guid"); error.GetErrorMessage().Should().Be("The option --guid requires a value, but no value was specified."); }
public void Parse_InvalidValue_ShouldAddError() { var valueParser = A.Fake <ValueParser>(); var parser = new GuidOptionParser(typeof(DataTypesCommandOptions).GetProperty("Guid"), "guid"); parser.ValueParser = valueParser; var tokens = new List <Token> { new OptionToken("guid") { OptionValues = { "NotAGuid" } } }; var parseResult = new ParseResult(); parseResult.CommandOptions = new DataTypesCommandOptions(); Guid guid; A.CallTo(() => valueParser.TryParseGuid("NotAGuid", null, out guid)) .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("guid"); error.InvalidOptionValue.Should().Be("NotAGuid"); error.ExpectedValueFormat.Should().Be("A valid Guid"); error.GetErrorMessage().Should().Be("The value 'NotAGuid' of the option --guid has an invalid format. The expected format is: A valid Guid."); }