예제 #1
0
                public void CreatesUnnamedGroupWithDefaultPermissionCorrectly()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <UnnamedGroupWithDefaultPermission>();

                    var tree = builder.Build();

                    var result   = tree.CreateApplicationCommands();
                    var commands = result.Entity;

                    ResultAssert.Successful(result);
                    Assert.NotNull(commands);

                    var command = commands !.SingleOrDefault();

                    Assert.True(command !.DefaultPermission.Value);
                }
예제 #2
0
                public void CanFindCommandWithDifferentCasing()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <GroupWithCasingDifferences>();

                    var tree = builder.Build();

                    var options = new TreeSearchOptions(StringComparison.OrdinalIgnoreCase);

                    var result = tree.Search
                                 (
                        "test somecommand",
                        new Dictionary <string, IReadOnlyList <string> >(),
                        searchOptions: options
                                 );

                    Assert.NotEmpty(result);
                }
예제 #3
0
                public void CreatesValidTreeCorrectly()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <ValidCommandGroup>();

                    var tree = builder.Build();

                    var result   = tree.CreateApplicationCommands();
                    var commands = result.Entity;

                    ResultAssert.Successful(result);

                    Assert.NotNull(commands);
                    Assert.Equal(2, commands !.Count);

                    var topLevelCommand = commands.FirstOrDefault(c => c.Name == "top-level-command");

                    Assert.NotNull(topLevelCommand);

                    var topLevelGroup = commands.FirstOrDefault(c => c.Name == "top-level-group");

                    Assert.NotNull(topLevelGroup);

                    Assert.True(topLevelGroup !.Options.HasValue);
                    Assert.Equal(2, topLevelGroup.Options.Value.Count);

                    var firstNestedCommand = topLevelGroup.Options.Value.FirstOrDefault(c => c.Type == SubCommand);

                    Assert.NotNull(firstNestedCommand);

                    var nestedGroup = topLevelGroup.Options.Value.FirstOrDefault(c => c.Type == SubCommandGroup);

                    Assert.NotNull(nestedGroup);

                    Assert.True(nestedGroup !.Options.HasValue);
                    Assert.Single(nestedGroup.Options.Value);

                    var secondNestedCommand = nestedGroup.Options.Value.FirstOrDefault(c => c.Type == SubCommand);

                    Assert.NotNull(secondNestedCommand);
                }
예제 #4
0
        public void ParsesGroupWithVariousReturnTypesCorrectly()
        {
            var builder = new CommandTreeBuilder();

            builder.RegisterModule <GroupWithVariousReturnTypes>();

            var tree = builder.Build();
            var root = tree.Root;

            Assert.Collection
            (
                root.Children,
                a => Assert.Equal(nameof(a), a.Key),
                b => Assert.Equal(nameof(b), b.Key),
                c => Assert.Equal(nameof(c), c.Key),
                d => Assert.Equal(nameof(d), d.Key),
                e => Assert.Equal(nameof(e), e.Key),
                f => Assert.Equal(nameof(f), f.Key)
            );
        }
예제 #5
0
                public void CreatesUngroupedTopLevelCommandsWithDefaultPermissionCorrectly()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <MultipleCommandsWithDefaultPermission.GroupOne>();
                    builder.RegisterModule <MultipleCommandsWithDefaultPermission.GroupTwo>();

                    var tree = builder.Build();

                    var result   = tree.CreateApplicationCommands();
                    var commands = result.Entity;

                    ResultAssert.Successful(result);
                    Assert.NotNull(commands);

                    Assert.Equal(2, commands !.Count);
                    var a = commands[0];
                    var b = commands[1];

                    Assert.True(a.DefaultPermission.Value);
                    Assert.False(b.DefaultPermission.Value);
                }
예제 #6
0
        public void ParsesNamedGroupWithCommandsWithNestedNamedGroupWithCommandsCorrectly()
        {
            var builder = new CommandTreeBuilder();

            builder.RegisterModule <NamedGroupWithCommandsWithNestedNamedGroupWithCommands>();

            var tree = builder.Build();
            var root = tree.Root;

            Assert.Single(root.Children);
            Assert.IsType <GroupNode>(root.Children[0]);

            var groupNode = (GroupNode)root.Children[0];

            Assert.Equal("a", groupNode.Key);

            var groupType = Assert.Single(groupNode.GroupTypes);

            Assert.Equal(typeof(NamedGroupWithCommandsWithNestedNamedGroupWithCommands), groupType);

            Assert.Equal(2, groupNode.Children.Count);
            Assert.Contains(groupNode.Children, n => n is GroupNode);
            Assert.Contains(groupNode.Children, n => n is CommandNode);

            var command1 = (CommandNode)groupNode.Children.First(n => n is CommandNode);

            Assert.Equal("b", command1.Key);

            var nestedGroupNode = (GroupNode)groupNode.Children.First(n => n is GroupNode);

            Assert.Equal("c", nestedGroupNode.Key);

            Assert.Single(nestedGroupNode.Children);
            var command2 = (CommandNode)nestedGroupNode.Children[0];

            Assert.Equal("d", command2.Key);
        }
예제 #7
0
        public void ParsesAliasedGroupWithCommandCorrectly()
        {
            var builder = new CommandTreeBuilder();

            builder.RegisterModule <AliasedGroupWithCommand>();

            var tree = builder.Build();
            var root = tree.Root;

            Assert.Single(root.Children);

            var firstChild = root.Children[0];

            Assert.IsType <GroupNode>(firstChild);

            var group = (GroupNode)firstChild;

            Assert.Equal("test", group.Key);

            var groupType = Assert.Single(group.GroupTypes);

            Assert.Equal(typeof(AliasedGroupWithCommand), groupType);

            Assert.Collection(group.Aliases, a => Assert.Equal("t", a));

            Assert.Single(group.Children);

            var firstGroupChild = group.Children[0];

            Assert.IsType <CommandNode>(firstGroupChild);

            var command = (CommandNode)firstGroupChild;

            Assert.Equal("command", command.Key);
            Assert.Empty(command.Aliases);
        }
                public void CreatesTypedOptionsCorrectly()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <TypedCommands>();

                    var tree = builder.Build();

                    var result   = tree.CreateApplicationCommands();
                    var commands = result.Entity;

                    ResultAssert.Successful(result);
                    Assert.NotNull(commands);

                    void AssertExistsWithType(string commandName, ApplicationCommandOptionType type)
                    {
                        var command = commands !.FirstOrDefault(c => c.Name == commandName);

                        Assert.NotNull(command);

                        var parameter = command !.Options.Value ![0];

                        Assert.Equal(type, parameter.Type);
                    }
예제 #9
0
                public void CreatesTypedOptionsCorrectly()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <TypedCommands>();

                    var tree = builder.Build();

                    var result = tree.CreateApplicationCommands(out var commands);

                    ResultAssert.Successful(result);
                    Assert.NotNull(commands);

                    void AssertExistsWithType(string commandName, ApplicationCommandOptionType type)
                    {
                        var command = commands !.FirstOrDefault(c => c.Name == commandName);

                        Assert.NotNull(command);

                        var parameter = command !.Options.Value !.First();

                        Assert.Equal(type, parameter.Type);
                    }

                    AssertExistsWithType("sbyte-value", Integer);
                    AssertExistsWithType("byte-value", Integer);
                    AssertExistsWithType("short-value", Integer);
                    AssertExistsWithType("ushort-value", Integer);
                    AssertExistsWithType("int-value", Integer);
                    AssertExistsWithType("uint-value", Integer);
                    AssertExistsWithType("long-value", Integer);
                    AssertExistsWithType("ulong-value", Integer);

                    AssertExistsWithType("float-value", String);
                    AssertExistsWithType("double-value", String);
                    AssertExistsWithType("decimal-value", String);

                    AssertExistsWithType("string-value", String);

                    AssertExistsWithType("bool-value", Boolean);

                    AssertExistsWithType("role-value", Role);
                    AssertExistsWithType("user-value", User);
                    AssertExistsWithType("channel-value", Channel);
                    AssertExistsWithType("member-value", User);

                    AssertExistsWithType("enum-value", String);
                    var enumCommand   = commands !.First(c => c.Name == "enum-value");
                    var enumParameter = enumCommand.Options.Value !.First();

                    Assert.True(enumParameter.Choices.HasValue);

                    var enumChoices = enumParameter.Choices.Value !;

                    Assert.Equal(2, enumChoices.Count);
                    Assert.Collection
                    (
                        enumChoices,
                        choice =>
                    {
                        Assert.Equal(nameof(TestEnum.Value1), choice.Name);
                        Assert.True(choice.Value.IsT0);
                        Assert.Equal(nameof(TestEnum.Value1), choice.Value.AsT0);
                    },
                        choice =>
                    {
                        Assert.Equal(nameof(TestEnum.Value2), choice.Name);
                        Assert.True(choice.Value.IsT0);
                        Assert.Equal(nameof(TestEnum.Value2), choice.Value.AsT0);
                    }
                    );
                }
예제 #10
0
 public void Build(ICommandNode node, Command parent = null)
 {
     CommandTreeBuilder.Build(this, node, parent);
 }