コード例 #1
0
        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")
                                                              );
        }
コード例 #2
0
        internal void Mapper_AddCommand_Should_Be_Initialized_With_Property_LongName()
        {
            // Arrange
            var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>();

            mapper.AddCommand(x => x.Command, "command");
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        internal void Usage_AddCommand_Usage_AddHelpOption()
        {
            var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>();

            mapper.AddCommand(x => x.Command, commandSettings => {
                commandSettings.Usage.AddHelpOption();
            });
        }
コード例 #6
0
        internal void Mapper_AddCommand_Should_Be_Initialized_With_Property_Settings()
        {
            // Arrange
            var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>();

            mapper.AddCommand(x => x.Command, commandSettings => {
            });
        }
コード例 #7
0
        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"));
                });
            });
コード例 #8
0
        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");
            });
        }
コード例 #9
0
        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");
            });
        }
コード例 #10
0
        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);
            });
        }
コード例 #11
0
        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();
                });
            });
        }
コード例 #12
0
        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);
            });
        }
コード例 #13
0
        internal void AddCommand_Should_Throw_CommandNameRequiredException()
        {
            // Arrange
            var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>();

            // Assert
            Assert.Throws <CommandNameRequiredException>(() =>
                                                         mapper.AddCommand(x => x.Command, string.Empty)
                                                         );
        }
コード例 #14
0
        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 => { });
                });
            });
        }
コード例 #15
0
        internal void AddCommand_Should_Throw_InvalidCommandNameException(string commandName)
        {
            // Arrange
            var mapper = new ArgsMapper <OneCommandWithOneBoolOptionArgs>();

            // Assert
            Assert.Throws <InvalidCommandNameException>(() =>
                                                        mapper.AddCommand(x => x.Command, commandName)
                                                        );
        }
コード例 #16
0
        internal void AddCommand_Should_Throw_ArgumentException_When_Property_Method()
        {
            // Arrange
            var mapper = new ArgsMapper <OneCommandMethodWithOneBoolOptionArgs>();

            // Assert
            Assert.Throws <ArgumentException>(() =>
                                              mapper.AddCommand(x => x.Command())
                                              );
        }
コード例 #17
0
        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);
                });
            });
        }
コード例 #18
0
        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;
                });
            });
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: akanmuratcimen/args-mapper
        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);
        }
コード例 #20
0
        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();
                    });
                });
            });
        }
コード例 #21
0
        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);
            })
                                                                   );
        }
コード例 #22
0
        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);
            })
                                              );
        }
コード例 #23
0
        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());
            })
                                              );
        }
コード例 #24
0
        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")
                                                                        );
            });
        }
コード例 #25
0
        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)
                                                                              );
            });
        }
コード例 #26
0
        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)
                                                                      );
            });
        }
コード例 #27
0
        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)
                                                                          );
        }
コード例 #28
0
        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)
                                                  );
            });
        }
コード例 #29
0
        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)
                                                               );
            });
        }
コード例 #30
0
        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)
                                                                );
            });
        }