Beispiel #1
0
            public async Task ReturnsUnsuccessfulIfDescriptionIsTooLong()
            {
                var applicationID = new Snowflake(0);
                var name          = "aaa";
                var description   = new string('a', 101);
                var options       = new List <ApplicationCommandOption>();

                var api = CreateAPI
                          (
                    b => b
                    .Expect(HttpMethod.Post, $"{Constants.BaseURL}applications/{applicationID}/commands")
                    .WithJson
                    (
                        json => json.IsObject
                        (
                            o => o
                            .WithProperty("name", p => p.Is(name))
                            .WithProperty("description", p => p.Is(description))
                            .WithProperty("options", p => p.IsArray())
                        )
                    )
                    .Respond("application/json", SampleRepository.Samples[typeof(IApplicationCommand)])
                          );

                var result = await api.CreateGlobalApplicationCommandAsync
                             (
                    applicationID,
                    name,
                    description,
                    options
                             );

                ResultAssert.Unsuccessful(result);
            }
Beispiel #2
0
            public async Task ReturnsErrorIfLimitIsOutsideValidRange()
            {
                var services = CreateConfiguredAPIServices(_ => { });
                var api      = services.GetRequiredService <IDiscordRestAuditLogAPI>();

                var guildID    = new Snowflake(0);
                var userID     = new Snowflake(1);
                var actionType = AuditLogEvent.BotAdd;
                var before     = new Snowflake(2);

                var result = await api.GetAuditLogAsync
                             (
                    guildID,
                    userID,
                    actionType,
                    before,
                    0
                             );

                ResultAssert.Unsuccessful(result);

                result = await api.GetAuditLogAsync
                         (
                    guildID,
                    userID,
                    actionType,
                    before,
                    101
                         );

                ResultAssert.Unsuccessful(result);
            }
Beispiel #3
0
            public async Task ReturnsErrorForTooLargeImage()
            {
                var guildId = new Snowflake(0);
                var name    = "ff";

                // Create a dummy PNG image
                await using var image        = new MemoryStream();
                await using var binaryWriter = new BinaryWriter(image);
                binaryWriter.Write(new byte[256001]);
                image.Position = 0;

                var roles = Array.Empty <Snowflake>();

                var api = CreateAPI
                          (
                    b => b
                    .Expect(HttpMethod.Post, $"{Constants.BaseURL}guilds/{guildId}/emojis")
                    .WithJson
                    (
                        j => j.IsObject
                        (
                            o => o
                            .WithProperty("name", p => p.Is(name))
                            .WithProperty("image", p => p.IsString())
                            .WithProperty("roles", p => p.IsArray(a => a.WithCount(0)))
                        )
                    )
                    .Respond("application/json", SampleRepository.Samples[typeof(IEmoji)])
                          );

                var result = await api.CreateGuildEmojiAsync(guildId, name, image, roles);

                ResultAssert.Unsuccessful(result);
            }
Beispiel #4
0
            public async Task ReturnsErrorIfAvatarIsUnknownFormat()
            {
                // Create a dummy PNG image
                await using var avatar       = new MemoryStream();
                await using var binaryWriter = new BinaryWriter(avatar);
                binaryWriter.Write(0x000000);
                avatar.Position = 0;

                var webhookId = new Snowflake(0);
                var token     = "aa";

                var api = CreateAPI
                          (
                    b => b
                    .Expect(HttpMethod.Patch, $"{Constants.BaseURL}webhooks/{webhookId}/{token}")
                    .Respond("application/json", SampleRepository.Samples[typeof(IWebhook)])
                          );

                var result = await api.ModifyWebhookWithTokenAsync
                             (
                    webhookId,
                    token,
                    avatar : avatar
                             );

                ResultAssert.Unsuccessful(result);
            }
Beispiel #5
0
            public async Task ReturnsErrorIfAvatarIsUnknownFormat()
            {
                var channelId = new Snowflake(0);
                var name      = "aaa";

                // Create a dummy PNG image
                await using var avatar       = new MemoryStream();
                await using var binaryWriter = new BinaryWriter(avatar);
                binaryWriter.Write(0x00000000);
                avatar.Position = 0;

                var api = CreateAPI
                          (
                    b => b
                    .Expect(HttpMethod.Post, $"{Constants.BaseURL}channels/{channelId}/webhooks")
                    .Respond("application/json", SampleRepository.Samples[typeof(IWebhook)])
                          );

                var result = await api.CreateWebhookAsync
                             (
                    channelId,
                    name,
                    avatar
                             );

                ResultAssert.Unsuccessful(result);
            }
Beispiel #6
0
                public void ReturnsUnsuccessfulIfACommandHasTooManyParameters()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <TooManyCommandParameters>();

                    var tree = builder.Build();

                    var result = tree.CreateApplicationCommands(out _);

                    ResultAssert.Unsuccessful(result);
                }
Beispiel #7
0
                public void ReturnsUnsuccessfulIfGroupsAreTooDeeplyNested()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <TooDeeplyNested>();

                    var tree = builder.Build();

                    var result = tree.CreateApplicationCommands(out _);

                    ResultAssert.Unsuccessful(result);
                }
Beispiel #8
0
                public void ReturnsUnsuccessfulIfThereAreOverloadsInAGroup()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <OverloadsAreNotSupportedInGroups>();

                    var tree = builder.Build();

                    var result = tree.CreateApplicationCommands(out _);

                    ResultAssert.Unsuccessful(result);
                }
Beispiel #9
0
                public void ReturnsUnsuccessfulIfACommandContainsASwitchParameter()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <SwitchesAreNotSupported>();

                    var tree = builder.Build();

                    var result = tree.CreateApplicationCommands(out _);

                    ResultAssert.Unsuccessful(result);
                }
            public async Task ReturnsErrorIfFormatIsUnknown()
            {
                // Create a dummy unknown image
                await using var image        = new MemoryStream();
                await using var binaryWriter = new BinaryWriter(image);
                binaryWriter.Write(0x00000000);
                image.Position = 0;

                var result = await ImagePacker.PackImageAsync(image);

                ResultAssert.Unsuccessful(result);
            }
Beispiel #11
0
                public void ReturnsUnsuccessfulIfThereAreTooManyRootLevelCommands()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <TooManyCommands>();

                    var tree = builder.Build();

                    var result = tree.CreateApplicationCommands(out _);

                    ResultAssert.Unsuccessful(result);
                }
Beispiel #12
0
                public void ReturnsUnsuccessfulIfAParameterDescriptionIsTooLong()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <TooLongParameterDescription>();

                    var tree = builder.Build();

                    var result = tree.CreateApplicationCommands();

                    ResultAssert.Unsuccessful(result);
                }
Beispiel #13
0
                public void ReturnsUnsuccessfulIfMultipleNamedGroupsWithTheSameNameHaveADefaultPermissionAttribute()
                {
                    var builder = new CommandTreeBuilder();

                    builder.RegisterModule <AtMostOneDefaultPermissionAttributeAllowed.Named.GroupOne>();
                    builder.RegisterModule <AtMostOneDefaultPermissionAttributeAllowed.Named.GroupTwo>();

                    var tree = builder.Build();

                    var result = tree.CreateApplicationCommands();

                    ResultAssert.Unsuccessful(result);
                }
Beispiel #14
0
            public async Task ReturnsErrorIfLimitIsTooHigh()
            {
                var limit = 201;

                var api = CreateAPI
                          (
                    b => b
                    .Expect(HttpMethod.Get, $"{Constants.BaseURL}users/@me/guilds")
                    .Respond("application/json", "[]")
                          );

                var result = await api.GetCurrentUserGuildsAsync(limit : limit);

                ResultAssert.Unsuccessful(result);
            }
Beispiel #15
0
            public async Task ReturnsUnsuccessfulIfNameIsTooShort()
            {
                var applicationID = new Snowflake(0);
                var guildID       = new Snowflake(1);
                var commandID     = new Snowflake(2);

                var name        = new string('a', 2);
                var description = "wwww";
                var options     = new List <ApplicationCommandOption>();

                var api = CreateAPI
                          (
                    b => b
                    .Expect
                    (
                        HttpMethod.Patch,
                        $"{Constants.BaseURL}applications/{applicationID}/guilds/{guildID}/commands/{commandID}"
                    )
                    .WithJson
                    (
                        json => json.IsObject
                        (
                            o => o
                            .WithProperty("name", p => p.Is(name))
                            .WithProperty("description", p => p.Is(description))
                            .WithProperty("options", p => p.IsArray())
                        )
                    )
                    .Respond("application/json", SampleRepository.Samples[typeof(IApplicationCommand)])
                          );

                var result = await api.EditGuildApplicationCommandAsync
                             (
                    applicationID,
                    guildID,
                    commandID,
                    name,
                    description,
                    options
                             );

                ResultAssert.Unsuccessful(result);
            }
Beispiel #16
0
            public async Task ReturnsErrorIfAvatarIsUnknownFormat()
            {
                var username = "******";

                // Create a dummy PNG image
                await using var avatar       = new MemoryStream();
                await using var binaryWriter = new BinaryWriter(avatar);
                binaryWriter.Write(0x000000);
                avatar.Position = 0;

                var api = CreateAPI
                          (
                    b => b
                    .Expect(HttpMethod.Patch, $"{Constants.BaseURL}users/@me")
                    .Respond("application/json", SampleRepository.Samples[typeof(IUser)])
                          );

                var result = await api.ModifyCurrentUserAsync(username, avatar);

                ResultAssert.Unsuccessful(result);
            }
Beispiel #17
0
            public async Task ReturnsErrorIfNameIsTooShort()
            {
                var channelId = new Snowflake(0);
                var name      = string.Empty;

                var api = CreateAPI
                          (
                    b => b
                    .Expect(HttpMethod.Post, $"{Constants.BaseURL}channels/{channelId}/webhooks")
                    .Respond("application/json", SampleRepository.Samples[typeof(IWebhook)])
                          );

                var result = await api.CreateWebhookAsync
                             (
                    channelId,
                    name,
                    null
                             );

                ResultAssert.Unsuccessful(result);
            }