当前位置: 首页>>代码示例>>C#>>正文


C# CommandLineParser.ExtractOptions方法代码示例

本文整理汇总了C#中CommandLineParser.ExtractOptions方法的典型用法代码示例。如果您正苦于以下问题:C# CommandLineParser.ExtractOptions方法的具体用法?C# CommandLineParser.ExtractOptions怎么用?C# CommandLineParser.ExtractOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandLineParser的用法示例。


在下文中一共展示了CommandLineParser.ExtractOptions方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExtractOptionAddsValuesToListCommand

        public void ExtractOptionAddsValuesToListCommand()
        {
            // Arrange
            var cmdMgr = new CommandManager();
            var command = new MockCommandWithMultiple();
            var arguments = "/ListProperty Val1 /RegularProp RegularPropValue /ListProperty Val2  /ListProperty Val3";
            var parser = new CommandLineParser(cmdMgr);

            // Act
            parser.ExtractOptions(command, arguments.Split().AsEnumerable().GetEnumerator());

            // Assert
            Assert.AreEqual(command.RegularProp, "RegularPropValue");
            Assert.AreEqual(command.ListProperty.Count, 3);
            Assert.AreEqual(command.ListProperty[0], "Val1");
            Assert.AreEqual(command.ListProperty[1], "Val2");
            Assert.AreEqual(command.ListProperty[2], "Val3");
        }
开发者ID:jerriclynsjohn,项目名称:nuget,代码行数:18,代码来源:CommandLinePaserTests.cs

示例2: ExtractOptions_ReturnsEmptyCommandWhenCommandLineIsEmpty

 public void ExtractOptions_ReturnsEmptyCommandWhenCommandLineIsEmpty()
 {
     // Arrange
     var cmdMgr = new Mock<ICommandManager>();
     var MockCommandOptions = new Dictionary<OptionAttribute, PropertyInfo>();
     var mockOptionAttribute = new OptionAttribute("Mock Option");
     var mockPropertyInfo = typeof(MockCommand).GetProperty("Message");
     MockCommandOptions.Add(mockOptionAttribute, mockPropertyInfo);
     cmdMgr.Setup(cm => cm.GetCommandOptions(It.IsAny<ICommand>())).Returns(MockCommandOptions);
     CommandLineParser parser = new CommandLineParser(cmdMgr.Object);
     var ExpectedCommand = new MockCommand();
     var argsEnumerator = new List<string>().GetEnumerator();
     // Act
     ICommand actualCommand = parser.ExtractOptions(ExpectedCommand, argsEnumerator);
     // Assert
     Assert.Equal(0, actualCommand.Arguments.Count);
     Assert.Null(((MockCommand)actualCommand).Message);
 }
开发者ID:monoman,项目名称:NugetCracker,代码行数:18,代码来源:CommandLinePaserTests.cs

示例3: ExtractOptions_AddsArgumentsWhenItemsDoNotStartWithSlashOrDash

 public void ExtractOptions_AddsArgumentsWhenItemsDoNotStartWithSlashOrDash()
 {
     // Arrange
     var cmdMgr = new Mock<ICommandManager>();
     var MockCommandOptions = new Dictionary<OptionAttribute, PropertyInfo>();
     var mockOptionAttribute = new OptionAttribute("Mock Option");
     var mockPropertyInfo = typeof(MockCommand).GetProperty("Message");
     MockCommandOptions.Add(mockOptionAttribute, mockPropertyInfo);
     cmdMgr.Setup(cm => cm.GetCommandOptions(It.IsAny<ICommand>())).Returns(MockCommandOptions);
     CommandLineParser parser = new CommandLineParser(cmdMgr.Object);
     var ExpectedCommand = new MockCommand();
     var argsEnumerator = new List<string>() { "optionOne", "optionTwo" }.GetEnumerator();
     // Act
     ICommand actualCommand = parser.ExtractOptions(ExpectedCommand, argsEnumerator );
     // Assert
     Assert.AreEqual(2, actualCommand.Arguments.Count);
     Assert.AreEqual("optionOne", actualCommand.Arguments[0]);
     Assert.AreEqual("optionTwo", actualCommand.Arguments[1]);
     Assert.IsNull(((MockCommand)actualCommand).Message);
 }
开发者ID:jerriclynsjohn,项目名称:nuget,代码行数:20,代码来源:CommandLinePaserTests.cs

示例4: ExtractOptionsSplitsValueBySemiColorForCollectionOption

        public void ExtractOptionsSplitsValueBySemiColorForCollectionOption()
        {
            // Arrange
            var cmdMgr = new CommandManager();
            var command = new MockCommandWithMultiple();
            var arguments = "/ListProperty Val1 /RegularProp RegularPropValue /ListProperty Val2;Val3;Val4  /ListProperty Val5";
            var parser = new CommandLineParser(cmdMgr);

            // Act
            parser.ExtractOptions(command, arguments.Split().AsEnumerable().GetEnumerator());

            // Assert
            Assert.AreEqual(command.RegularProp, "RegularPropValue");
            Assert.AreEqual(command.ListProperty.Count, 5);
            Assert.AreEqual(command.ListProperty[0], "Val1");
            Assert.AreEqual(command.ListProperty[1], "Val2");
            Assert.AreEqual(command.ListProperty[2], "Val3");
            Assert.AreEqual(command.ListProperty[3], "Val4");
            Assert.AreEqual(command.ListProperty[4], "Val5");
        }
开发者ID:jerriclynsjohn,项目名称:nuget,代码行数:20,代码来源:CommandLinePaserTests.cs

示例5: ExtractOptions_ParsesBoolOptionsAsFalseIfFollowedByDash

 public void ExtractOptions_ParsesBoolOptionsAsFalseIfFollowedByDash()
 {
     // Arrange
     var cmdMgr = new Mock<ICommandManager>();
     var MockCommandOptions = new Dictionary<OptionAttribute, PropertyInfo>();
     var mockOptionAttribute = new OptionAttribute("Mock Option");
     var mockPropertyInfo = typeof(MockCommand).GetProperty("IsWorking");
     MockCommandOptions.Add(mockOptionAttribute, mockPropertyInfo);
     cmdMgr.Setup(cm => cm.GetCommandOptions(It.IsAny<ICommand>())).Returns(MockCommandOptions);
     CommandLineParser parser = new CommandLineParser(cmdMgr.Object);
     var ExpectedCommand = new MockCommand();
     var argsEnumerator = new List<string>() { "-IsWorking-" }.GetEnumerator();
     // Act
     ICommand actualCommand = parser.ExtractOptions(ExpectedCommand, argsEnumerator);
     // Assert
     Assert.IsFalse(((MockCommand)actualCommand).IsWorking);
 }
开发者ID:jerriclynsjohn,项目名称:nuget,代码行数:17,代码来源:CommandLinePaserTests.cs

示例6: ExtractOptions_UsesShortenedForm

 public void ExtractOptions_UsesShortenedForm()
 {
     // Arrange
     var cmdMgr = new Mock<ICommandManager>();
     var MockCommandOptions = new Dictionary<OptionAttribute, PropertyInfo>();
     var mockOptionAttribute = new OptionAttribute("Mock Option");
     var mockPropertyInfo = typeof(MockCommand).GetProperty("Message");
     MockCommandOptions.Add(mockOptionAttribute, mockPropertyInfo);
     cmdMgr.Setup(cm => cm.GetCommandOptions(It.IsAny<ICommand>())).Returns(MockCommandOptions);
     CommandLineParser parser = new CommandLineParser(cmdMgr.Object);
     var ExpectedCommand = new MockCommand();
     var argsEnumerator = new List<string>() { "/Mess", "foo bar" }.GetEnumerator();
     // Act
     ICommand actualCommand = parser.ExtractOptions(ExpectedCommand, argsEnumerator);
     // Assert
     Assert.AreEqual("foo bar", ((MockCommand)actualCommand).Message);
 }
开发者ID:jerriclynsjohn,项目名称:nuget,代码行数:17,代码来源:CommandLinePaserTests.cs

示例7: ExtractOptions_ThrowsWhenOptionHasNoValue

        public void ExtractOptions_ThrowsWhenOptionHasNoValue()
        {
            // Arrange
            var cmdMgr = new Mock<ICommandManager>();
            var MockCommandOptions = new Dictionary<OptionAttribute, PropertyInfo>();
            var mockOptionAttribute = new OptionAttribute("Mock Option");
            var mockPropertyInfo = typeof(MockCommand).GetProperty("Message");
            MockCommandOptions.Add(mockOptionAttribute, mockPropertyInfo);
            cmdMgr.Setup(cm => cm.GetCommandOptions(It.IsAny<ICommand>())).Returns(MockCommandOptions);
            CommandLineParser parser = new CommandLineParser(cmdMgr.Object);
            var ExpectedCommand = new MockCommand();
            string expectedErrorMessage = "Missing option value for: '/Message'";
            var argsEnumerator = new List<string>() { "/Message" }.GetEnumerator();

            // Act & Assert
            ExceptionAssert.Throws<CommandLineException>(() => parser.ExtractOptions(ExpectedCommand, argsEnumerator), expectedErrorMessage);
        }
开发者ID:jerriclynsjohn,项目名称:nuget,代码行数:17,代码来源:CommandLinePaserTests.cs

示例8: ExtractOptions_ThrowsIfCommandOptionIsAmbigious

        public void ExtractOptions_ThrowsIfCommandOptionIsAmbigious()
        {
            // Arrange
            var cmdMgr = new Mock<ICommandManager>();

            var MockCommandOptions = new Dictionary<OptionAttribute, PropertyInfo>();
            var mockOptionAttribute = new OptionAttribute("Mock Option 1");
            var mockPropertyInfo = typeof(MockCommand).GetProperty("Count");
            MockCommandOptions.Add(mockOptionAttribute, mockPropertyInfo);
            mockOptionAttribute = new OptionAttribute("Mock Option 2");
            mockPropertyInfo = typeof(MockCommand).GetProperty("Counter");
            MockCommandOptions.Add(mockOptionAttribute, mockPropertyInfo);

            cmdMgr.Setup(cm => cm.GetCommandOptions(It.IsAny<ICommand>())).Returns(MockCommandOptions);
            CommandLineParser parser = new CommandLineParser(cmdMgr.Object);
            var ExpectedCommand = new MockCommand();
            string expectedErrorMessage = "Ambiguous option 'Co'. Possible values: Count Counter.";
            var argsEnumerator = new List<string>() { "/Co", "null" }.GetEnumerator();

            // Act & Assert

            ExceptionAssert.Throws<CommandLineException>(() => parser.ExtractOptions(ExpectedCommand, argsEnumerator), expectedErrorMessage);
        }
开发者ID:jerriclynsjohn,项目名称:nuget,代码行数:23,代码来源:CommandLinePaserTests.cs

示例9: ExtractOptions_ThrowsIfCommandOptionDoesNotExist

        public void ExtractOptions_ThrowsIfCommandOptionDoesNotExist()
        {
            // Arrange
            var cmdMgr = new Mock<ICommandManager>();

            var MockCommandOptions = new Dictionary<OptionAttribute, PropertyInfo>();
            var mockOptionAttribute = new OptionAttribute("Mock Option 1");
            var mockPropertyInfo = typeof(MockCommand).GetProperty("Count");
            MockCommandOptions.Add(mockOptionAttribute, mockPropertyInfo);
            mockOptionAttribute = new OptionAttribute("Mock Option 2");
            mockPropertyInfo = typeof(MockCommand).GetProperty("Counter");
            MockCommandOptions.Add(mockOptionAttribute, mockPropertyInfo);

            cmdMgr.Setup(cm => cm.GetCommandOptions(It.IsAny<ICommand>())).Returns(MockCommandOptions);
            CommandLineParser parser = new CommandLineParser(cmdMgr.Object);
            var ExpectedCommand = new MockCommand();
            string expectedErrorMessage = "Unknown option: '/37264752DOESNOTEXIST!!'";
            var argsEnumerator = new List<string>() { "/37264752DOESNOTEXIST!!", "false" }.GetEnumerator();

            // Act & Assert

            ExceptionAssert.Throws<CommandLineException>(() => parser.ExtractOptions(ExpectedCommand, argsEnumerator), expectedErrorMessage);
        }
开发者ID:jerriclynsjohn,项目名称:nuget,代码行数:23,代码来源:CommandLinePaserTests.cs

示例10: ExtractOptions_ThrowsIfCommandHasNoProperties

        public void ExtractOptions_ThrowsIfCommandHasNoProperties()
        {
            // Arrange
            var cmdMgr = new Mock<ICommandManager>();

            var MockCommandOptions = new Dictionary<OptionAttribute, PropertyInfo>();
            cmdMgr.Setup(cm => cm.GetCommandOptions(It.IsAny<ICommand>())).Returns(MockCommandOptions);
            CommandLineParser parser = new CommandLineParser(cmdMgr.Object);
            var ExpectedCommand = new MockCommand();
            string expectedErrorMessage = "Unknown option: '/Count'";
            var argsEnumerator = new List<string>() { "/Count", "null" }.GetEnumerator();

            // Act & Assert
            ExceptionAssert.Throws<CommandLineException>(() => parser.ExtractOptions(ExpectedCommand, argsEnumerator), expectedErrorMessage);
        }
开发者ID:jerriclynsjohn,项目名称:nuget,代码行数:15,代码来源:CommandLinePaserTests.cs

示例11: ExtractOptions_ThrowsIfUnableToConvertType

        public void ExtractOptions_ThrowsIfUnableToConvertType()
        {
            // Arrange
            var cmdMgr = new Mock<ICommandManager>();

            var MockCommandOptions = new Dictionary<OptionAttribute, PropertyInfo>();
            var mockOptionAttribute = new OptionAttribute("Mock Option");
            var mockPropertyInfo = typeof(MockCommand).GetProperty("Count");
            MockCommandOptions.Add(mockOptionAttribute, mockPropertyInfo);

            cmdMgr.Setup(cm => cm.GetCommandOptions(It.IsAny<ICommand>())).Returns(MockCommandOptions);
            CommandLineParser parser = new CommandLineParser(cmdMgr.Object);
            var command = new MockCommand();
            string expectedErrorMessage = "Invalid option value: '/Count null'";
            var argsEnumerator = new List<string>() { "/Count", "null" }.GetEnumerator();
            
            // Act & Assert
            ExceptionAssert.Throws<CommandLineException>(() => parser.ExtractOptions(command, argsEnumerator), expectedErrorMessage);
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:19,代码来源:CommandLinePaserTests.cs

示例12: ExtractOptions_ParsesBoolOptionsAsTrueIfPresent

 public void ExtractOptions_ParsesBoolOptionsAsTrueIfPresent()
 {
     // Arrange
     var cmdMgr = new Mock<ICommandManager>();
     var MockCommandOptions = new Dictionary<OptionAttribute, PropertyInfo>();
     var mockOptionAttribute = new OptionAttribute("Mock Option");
     var mockPropertyInfo = typeof(MockCommand).GetProperty("IsWorking");
     MockCommandOptions.Add(mockOptionAttribute, mockPropertyInfo);
     cmdMgr.Setup(cm => cm.GetCommandOptions(It.IsAny<ICommand>())).Returns(MockCommandOptions);
     CommandLineParser parser = new CommandLineParser(cmdMgr.Object);
     var command = new MockCommand();
     var argsEnumerator = new List<string>() { "-IsWorking" }.GetEnumerator();
     
     // Act
     parser.ExtractOptions(command, argsEnumerator);
     
     // Assert
     Assert.True(command.IsWorking);
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:19,代码来源:CommandLinePaserTests.cs

示例13: ExtractOptions_ParsesOptionsThatStartWithDash

 public void ExtractOptions_ParsesOptionsThatStartWithDash()
 {
     // Arrange
     var cmdMgr = new Mock<ICommandManager>();
     var MockCommandOptions = new Dictionary<OptionAttribute, PropertyInfo>();
     var mockOptionAttribute = new OptionAttribute("Mock Option");
     var mockPropertyInfo = typeof(MockCommand).GetProperty("Message");
     MockCommandOptions.Add(mockOptionAttribute, mockPropertyInfo);
     cmdMgr.Setup(cm => cm.GetCommandOptions(It.IsAny<ICommand>())).Returns(MockCommandOptions);
     CommandLineParser parser = new CommandLineParser(cmdMgr.Object);
     var command = new MockCommand();
     var argsEnumerator = new List<string>() { "-Message", "foo bar" }.GetEnumerator();
     
     // Act
     parser.ExtractOptions(command, argsEnumerator);
     
     // Assert
     Assert.Equal("foo bar", command.Message);
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:19,代码来源:CommandLinePaserTests.cs


注:本文中的CommandLineParser.ExtractOptions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。