internal void AddCommand_Should_Throw_CommandNameAlreadyExistsException() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); mapper.AddCommand(x => x.Command, "command"); // Assert Assert.Throws <CommandNameAlreadyExistsException>(() => mapper.AddCommand(x => x.Command, "command") ); }
internal void Mapper_AddCommand_Should_Be_Initialized_With_Property_LongName() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); mapper.AddCommand(x => x.Command, "command"); }
internal void Command_Option_Value_Should_Be_Default_Value_Multiple() { // Arrange var mapper = new ArgsMapper <OneCommandWithThreeIntOptionsArgs>(); mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.AddOption(x => x.Option1, optionSettings => { optionSettings.DefaultValue = 1; }); commandSettings.AddOption(x => x.Option2, optionSettings => { optionSettings.DefaultValue = 2; }); commandSettings.AddOption(x => x.Option3, optionSettings => { optionSettings.DefaultValue = 3; }); }); // Act var result = mapper.Map("command"); // Assert Assert.Equal(1, result.Model.Command.Option1); Assert.Equal(2, result.Model.Command.Option2); Assert.Equal(3, result.Model.Command.Option3); }
internal void Command_Subcommand_Subcommand_Subcommand_Should_Be_Matched_With_Default_Name() { // Arrange var mapper = new ArgsMapper <FourLevelNestedCommandArgs>(); mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.AddSubcommand(x => x.Command, subcommandSettings0 => { subcommandSettings0.AddSubcommand(x => x.Command, subcommandSettings1 => { subcommandSettings1.AddSubcommand(x => x.Command); }); }); }); // Act var result = mapper.Map("command", "command", "command", "command"); // Assert Assert.NotNull(result.Model.Command); Assert.NotNull(result.Model.Command.Command); Assert.NotNull(result.Model.Command.Command.Command); Assert.NotNull(result.Model.Command.Command.Command.Command); Assert.IsType <ThreeLevelNestedCommandArgs>(result.Model.Command); Assert.IsType <TwoLevelNestedCommandArgs>(result.Model.Command.Command); Assert.IsType <OneCommandWithOneBoolOptionArgs>(result.Model.Command.Command.Command); Assert.IsType <OneBoolOptionArgs>(result.Model.Command.Command.Command.Command); }
internal void Usage_AddCommand_Usage_AddHelpOption() { var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.Usage.AddHelpOption(); }); }
internal void Mapper_AddCommand_Should_Be_Initialized_With_Property_Settings() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); mapper.AddCommand(x => x.Command, commandSettings => { }); }
internal void Usage_AddCommand_Usage_AddSection_AddTable_2_Columns() { var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.Usage.AddSection("header", section => { section.AddTable(("column1", "column2")); }); });
internal void Mapper_AddCommand_AddOption_Should_Be_Initialized_With_Property_ShortName_LongName() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); mapper.AddCommand(x => x.Command, "command", commandSettings => { commandSettings.AddOption(x => x.Option, 'o', "option"); }); }
internal void Mapper_AddCommand_AddSubcommand_Should_Be_Initialized_With_Property_LongName() { // Arrange var mapper = new ArgsMapper <TwoLevelNestedCommandArgs>(); mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.AddSubcommand(x => x.Command, "command"); }); }
internal void Mapper_AddCommand_AddPositionalOption_Should_Be_Initialized_With_Property() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); mapper.AddCommand(x => x.Command, "command", commandSettings => { commandSettings.AddPositionalOption(x => x.Option); }); }
internal void Usage_AddCommand_AddSubCommand_Usage_AddEmptyLine() { var mapper = new ArgsMapper <OneCommandWithOneClassWithOneBoolOption>(); mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.AddSubcommand(x => x.Command, subcommandSettings => { subcommandSettings.Usage.AddEmptyLine(); }); }); }
internal void Mapper_AddCommand_AddOption_AddPositionalOption_List_Should_Be_Initialized() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneListStringOptionWithOneBoolOptionArgs>(); mapper.AddCommand(x => x.Command, "command", commandSettings => { commandSettings.AddOption(x => x.Option); commandSettings.AddPositionalOption(x => x.Options); }); }
internal void AddCommand_Should_Throw_CommandNameRequiredException() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); // Assert Assert.Throws <CommandNameRequiredException>(() => mapper.AddCommand(x => x.Command, string.Empty) ); }
internal void Usage_AddCommand_Usage_AddSection_AddHelpOption_With_Settings() { var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.Usage.AddSection("header", section => { section.AddHelpOption(settings => { }); }); }); }
internal void AddCommand_Should_Throw_InvalidCommandNameException(string commandName) { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); // Assert Assert.Throws <InvalidCommandNameException>(() => mapper.AddCommand(x => x.Command, commandName) ); }
internal void AddCommand_Should_Throw_ArgumentException_When_Property_Method() { // Arrange var mapper = new ArgsMapper <OneCommandMethodWithOneBoolOptionArgs>(); // Assert Assert.Throws <ArgumentException>(() => mapper.AddCommand(x => x.Command()) ); }
internal void Mapper_AddCommand_AddSubcommand_AddSubcommand_Should_Be_Initialized() { // Arrange var mapper = new ArgsMapper <ThreeLevelNestedCommandArgs>(); mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.AddSubcommand(x => x.Command, subcommandSettings => { subcommandSettings.AddSubcommand(x => x.Command); }); }); }
internal void Mapper_AddCommand_AddSubcommand_Should_Be_Initialized_With_Property_Settings() { // Arrange var mapper = new ArgsMapper <TwoLevelNestedCommandArgs>(); mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.AddSubcommand(x => x.Command, subcommandSettings => { subcommandSettings.IsDisabled = false; }); }); }
private static void Main(string[] args) { var mapper = new ArgsMapper <Args>(); mapper.AddCommand(x => x.AddUser, commandSettings => { commandSettings.AddOption(x => x.Username); commandSettings.AddOption(x => x.Password); }); mapper.Execute(args, OnSuccess, OnError); }
internal void Usage_AddCommand_AddSubCommand_Usage_AddSection_AddHelpOption() { var mapper = new ArgsMapper <OneCommandWithOneClassWithOneBoolOption>(); mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.AddSubcommand(x => x.Command, subcommandSettings => { subcommandSettings.Usage.AddSection("header", section => { section.AddHelpOption(); }); }); }); }
internal void AddCommand_AddPositionalOption_Should_Throw_CommandOptionLongNameRequiredException() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); // Assert Assert.Throws <CommandOptionLongNameRequiredException>(() => mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.AddPositionalOption(x => x.Option, string.Empty); }) ); }
internal void AddCommand_AddPositionalOption_Should_Throw_ArgumentException_When_Property_Has_No_Setter() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolWithoutSetterOptionArgs>(); // Assert Assert.Throws <ArgumentException>(() => mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.AddPositionalOption(x => x.Option); }) ); }
internal void AddCommand_AddOption_Should_Throw_ArgumentException() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolMethodOptionArgs>(); // Assert Assert.Throws <ArgumentException>(() => mapper.AddCommand(x => x.Command, commandSettings => { commandSettings.AddOption(x => x.Option()); }) ); }
internal void AddOption_Should_Throw_ReservedCommandOptionShortNameException(char optionShortName) { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); // Assert mapper.AddCommand(x => x.Command, "command", commandSettings => { Assert.Throws <ReservedCommandOptionShortNameException>(() => commandSettings.AddOption(x => x.Option, optionShortName, "option") ); }); }
internal void AddCommand_AddPositionalOption_Should_Throw_UnsupportedCommandOptionPropertyTypeException_Class() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneClassWithOneBoolOption>(); // Assert mapper.AddCommand(x => x.Command, "command", commandSettings => { Assert.Throws <UnsupportedCommandOptionPropertyTypeException>(() => commandSettings.AddPositionalOption(x => x.Command) ); }); }
internal void AddCommand_AddOption_Should_Throw_InvalidCommandOptionLongNameException(string optionLongName) { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>(); // Assert mapper.AddCommand(x => x.Command, "command", commandSettings => { Assert.Throws <InvalidCommandOptionLongNameException>(() => commandSettings.AddOption(x => x.Option, optionLongName) ); }); }
internal void AddCommand_Should_Throw_CommandConflictsWithPositionalOptionException() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneBoolOptionAndOneBoolOptionArgs>(); mapper.AddPositionalOption(x => x.Option); // Assert Assert.Throws <CommandConflictsWithPositionalOptionException>(() => mapper.AddCommand(x => x.Command) ); }
internal void AddCommand_AddSubcommand_Should_Throw_ArgumentException_When_Property_Internal() { // Arrange var mapper = new ArgsMapper <OneCommandWithOneInternalCommandWithOneBoolOptionArgs>(); // Assert mapper.AddCommand(x => x.Command, commandSettings => { Assert.Throws <ArgumentException>(() => commandSettings.AddSubcommand(x => x.Command) ); }); }
internal void AddCommand_AddSubcommand_Should_Throw_InvalidCommandNameException(string commandName) { // Arrange var mapper = new ArgsMapper <TwoLevelNestedCommandArgs>(); // Assert mapper.AddCommand(x => x.Command, commandSettings => { Assert.Throws <InvalidSubcommandNameException>(() => commandSettings.AddSubcommand(x => x.Command, commandName) ); }); }
internal void AddCommand_AddSubcommand_Should_Throw_CommandNameRequiredException() { // Arrange var mapper = new ArgsMapper <TwoLevelNestedCommandArgs>(); // Assert mapper.AddCommand(x => x.Command, commandSettings => { Assert.Throws <SubcommandNameRequiredException>(() => commandSettings.AddSubcommand(x => x.Command, string.Empty) ); }); }