本文整理汇总了C#中ParameterDescriptor.AddCommandLineParameterTo方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterDescriptor.AddCommandLineParameterTo方法的具体用法?C# ParameterDescriptor.AddCommandLineParameterTo怎么用?C# ParameterDescriptor.AddCommandLineParameterTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParameterDescriptor
的用法示例。
在下文中一共展示了ParameterDescriptor.AddCommandLineParameterTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Arguments_HaveCorrectDescription_Returns_CorrectValue
public void Arguments_HaveCorrectDescription_Returns_CorrectValue(
string propertyName,
string expectedDescription)
{
//Arrange
var command = new CommandLineApplication();
var property = typeof(TestClass).GetProperty(propertyName);
var descriptor = new ParameterDescriptor(property);
//Act
descriptor.AddCommandLineParameterTo(command);
//Assert
var actualOption = command.Arguments.First();
Assert.Equal(propertyName, actualOption.Name);
Assert.Equal(expectedDescription, actualOption.Description);
//Arrange
command.Execute(new string[0] { });
//Assert
Assert.Equal(null, descriptor.Value); //Is this right assumption to test?
//Arrange
command.Execute(new string[] { "PassedValue" });
//Assert
Assert.Equal("PassedValue", descriptor.Value);
}
示例2: Options_UseCorrectName_Returns_CorrectValue
public void Options_UseCorrectName_Returns_CorrectValue(
string propertyName,
string expectedOptionTemplate,
string expectedOptionDescription,
int expectedCommandOptionType,
string commandLineStringWithTheOption,
object expectedValueWhenOptionIsPresent,
object expectedValueWhenOptionIsNotPresent)
{
//Arrange
var command = new CommandLineApplication();
var property = typeof(TestClass).GetProperty(propertyName);
var descriptor = new ParameterDescriptor(property);
var expectedOption = new CommandOption(expectedOptionTemplate, (CommandOptionType)expectedCommandOptionType);
//Act
descriptor.AddCommandLineParameterTo(command);
//Assert
var actualOption = command.Options.First();
Assert.Equal(expectedOption.LongName, actualOption.LongName);
Assert.Equal(expectedOption.ShortName, actualOption.ShortName);
Assert.Equal(expectedOption.OptionType, actualOption.OptionType);
Assert.Equal(expectedOptionDescription, actualOption.Description);
//Arrange
command.Execute(new string[0] { });
//Assert
Assert.Equal(expectedValueWhenOptionIsNotPresent, descriptor.Value);
//Arrange
command.Execute(commandLineStringWithTheOption.Split(' '));
//Assert
Assert.Equal(expectedValueWhenOptionIsPresent, descriptor.Value);
}