public void ThrowIfInvalid_throws_if_there_are_duplicate_sibling_subcommand_aliases_on_a_subcommand()
    {
        var command1 = new Command("dupe");
        var command2 = new Command("not-a-dupe");

        command2.AddAlias("dupe");

        var command = new RootCommand
        {
            new Command("subcommand")
            {
                command1,
                command2
            }
        };

        var config = new CommandLineConfiguration(command);

        var validate = () => config.ThrowIfInvalid();

        validate.Should()
        .Throw <CommandLineConfigurationException>()
        .Which
        .Message
        .Should()
        .Be("Duplicate alias 'dupe' found on command 'subcommand'.");
    }
    public void ThrowIfInvalid_throws_if_there_are_duplicate_sibling_option_aliases_on_a_subcommand()
    {
        var option1 = new Option <string>("--dupe");
        var option2 = new Option <string>("--ok");

        option2.AddAlias("--dupe");

        var command = new RootCommand
        {
            new Command("subcommand")
            {
                option1,
                option2
            }
        };

        var config = new CommandLineConfiguration(command);

        var validate = () => config.ThrowIfInvalid();

        validate.Should()
        .Throw <CommandLineConfigurationException>()
        .Which
        .Message
        .Should()
        .Be("Duplicate alias '--dupe' found on command 'subcommand'.");
    }
    public void ThrowIfInvalid_throws_if_sibling_command_and_option_aliases_collide_on_a_subcommand()
    {
        var option  = new Option <string>("dupe");
        var command = new Command("not-a-dupe");

        command.AddAlias("dupe");

        var rootCommand = new RootCommand
        {
            new Command("subcommand")
            {
                option,
                command
            }
        };

        var config = new CommandLineConfiguration(rootCommand);

        var validate = () => config.ThrowIfInvalid();

        validate.Should()
        .Throw <CommandLineConfigurationException>()
        .Which
        .Message
        .Should()
        .Be("Duplicate alias 'dupe' found on command 'subcommand'.");
    }
    public void ThrowIfInvalid_throws_if_a_command_is_its_own_parent()
    {
        var command = new RootCommand();

        command.Add(command);

        var config = new CommandLineConfiguration(command);

        var validate = () => config.ThrowIfInvalid();

        validate.Should()
        .Throw <CommandLineConfigurationException>()
        .Which
        .Message
        .Should()
        .Be($"Cycle detected in command tree. Command '{command.Name}' is its own ancestor.");
    }
    public void ThrowIfInvalid_does_not_throw_if_global_option_alias_is_the_same_as_subcommand_alias()
    {
        var rootCommand = new RootCommand
        {
            new Command("subcommand")
            {
                new Command("--dupe")
            }
        };

        rootCommand.AddGlobalOption(new Option <string>("--dupe"));

        var config = new CommandLineConfiguration(rootCommand);

        var validate = () => config.ThrowIfInvalid();

        validate.Should().NotThrow();
    }
    public void ThrowIfInvalid_throws_if_there_are_duplicate_sibling_global_option_aliases_on_the_root_command()
    {
        var option1 = new Option <string>("--dupe");
        var option2 = new Option <string>("-y");

        option2.AddAlias("--dupe");

        var command = new RootCommand();

        command.AddGlobalOption(option1);
        command.AddGlobalOption(option2);

        var config = new CommandLineConfiguration(command);

        var validate = () => config.ThrowIfInvalid();

        validate.Should()
        .Throw <CommandLineConfigurationException>()
        .Which
        .Message
        .Should()
        .Be($"Duplicate alias '--dupe' found on command '{command.Name}'.");
    }