public async Task PerformsNullableRequestCorrectly() { var webhookId = new Snowflake(0); var token = "aa"; var api = CreateAPI ( b => b .Expect(HttpMethod.Patch, $"{Constants.BaseURL}webhooks/{webhookId}/{token}") .WithJson ( j => j.IsObject ( o => o .WithProperty("avatar", p => p.IsNull()) ) ) .Respond("application/json", SampleRepository.Samples[typeof(IWebhook)]) ); var result = await api.ModifyWebhookWithTokenAsync ( webhookId, token, avatar : null ); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var webhookId = new Snowflake(0); var token = "aasdasdaa"; var name = "aaa"; // Create a dummy PNG image await using var avatar = new MemoryStream(); await using var binaryWriter = new BinaryWriter(avatar); binaryWriter.Write(9894494448401390090); avatar.Position = 0; 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, name, avatar ); ResultAssert.Successful(result); }
public void CreatesRequiredOptionsCorrectly() { var builder = new CommandTreeBuilder(); builder.RegisterModule <CommandsWithRequiredOrOptionalParameters>(); var tree = builder.Build(); var result = tree.CreateApplicationCommands(out var commands); ResultAssert.Successful(result); Assert.NotNull(commands); var requiredCommand = commands !.First(c => c.Name == "required"); var requiredParameter = requiredCommand.Options.Value !.First(); Assert.True(requiredParameter.IsRequired.HasValue); Assert.True(requiredParameter.IsRequired.Value); var optionalCommand = commands.First(c => c.Name == "optional"); var optionalParameter = optionalCommand.Options.Value !.First(); if (optionalParameter.IsRequired.HasValue) { Assert.False(optionalParameter.IsRequired.Value); } }
public async Task PerformsRequestCorrectly() { var interactionID = new Snowflake(0); var token = "aaaa"; var interactionResponse = new InteractionResponse(InteractionCallbackType.DeferredChannelMessageWithSource); var api = CreateAPI ( b => b .Expect(HttpMethod.Post, $"{Constants.BaseURL}interactions/{interactionID}/{token}/callback") .WithJson ( j => j.IsObject ( o => o.WithProperty("type", p => p.Is(5)) ) ) .Respond("application/json", SampleRepository.Samples[typeof(IInteractionResponse)]) ); var result = await api.CreateInteractionResponseAsync ( interactionID, token, interactionResponse ); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var templateCode = "aaa"; var guildId = new Snowflake(0); var name = "name"; var description = "description"; var api = CreateAPI ( b => b .Expect(HttpMethod.Patch, $"{Constants.BaseURL}guilds/{guildId}/templates/{templateCode}") .WithJson ( j => j.IsObject ( o => o .WithProperty("name", p => p.Is(name)) .WithProperty("description", p => p.Is(description)) ) ) .Respond("application/json", SampleRepository.Samples[typeof(ITemplate)]) ); var result = await api.ModifyGuildTemplateAsync(guildId, templateCode, name, description); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var inviteCode = "brr"; var withCounts = true; var withExpiration = false; var api = CreateAPI ( b => b .Expect(HttpMethod.Get, $"{Constants.BaseURL}invite/{inviteCode}") .WithQueryString ( new[] { new KeyValuePair <string, string>("with_counts", withCounts.ToString()), new KeyValuePair <string, string>("with_expiration", withExpiration.ToString()), } ) .Respond("application/json", SampleRepository.Samples[typeof(IInvite)]) ); var result = await api.GetInviteAsync(inviteCode, withCounts, withExpiration); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var templateCode = "aaa"; var name = "name"; // Create a dummy PNG image await using var icon = new MemoryStream(); await using var binaryWriter = new BinaryWriter(icon); binaryWriter.Write(9894494448401390090); icon.Position = 0; var api = CreateAPI ( b => b .Expect(HttpMethod.Post, $"{Constants.BaseURL}guilds/templates/{templateCode}") .WithJson ( j => j.IsObject ( o => o .WithProperty("name", p => p.Is(name)) .WithProperty("icon", p => p.IsString()) ) ) .Respond("application/json", SampleRepository.Samples[typeof(IGuild)]) ); var result = await api.CreateGuildFromTemplateAsync(templateCode, name, icon); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var channelID = new Snowflake(1); var topic = "aa"; var privacyLevel = StagePrivacyLevel.GuildOnly; var api = CreateAPI ( b => b .Expect(HttpMethod.Post, $"{Constants.BaseURL}stage-instances") .WithJson ( json => json.IsObject ( o => o .WithProperty("channel_id", p => p.Is(channelID.ToString())) .WithProperty("topic", p => p.Is(topic)) .WithProperty("privacy_level", p => p.Is((int)privacyLevel)) ) ) .Respond("application/json", SampleRepository.Samples[typeof(IStageInstance)]) ); var result = await api.CreateStageInstanceAsync(channelID, topic, privacyLevel); ResultAssert.Successful(result); }
public async Task PerformsNullableRequestCorrectly() { var guildId = new Snowflake(0); var emojiId = new Snowflake(1); var name = "ff"; var api = CreateAPI ( b => b .Expect(HttpMethod.Patch, $"{Constants.BaseURL}guilds/{guildId}/emojis/{emojiId}") .WithJson ( j => j.IsObject ( o => o .WithProperty("name", p => p.Is(name)) .WithProperty("roles", p => p.IsNull()) ) ) .Respond("application/json", SampleRepository.Samples[typeof(IEmoji)]) ); var result = await api.ModifyGuildEmojiAsync(guildId, emojiId, name, null); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var before = new Snowflake(0); var after = new Snowflake(1); var limit = 10; var api = CreateAPI ( b => b .Expect(HttpMethod.Get, $"{Constants.BaseURL}users/@me/guilds") .WithQueryString ( new[] { new KeyValuePair <string, string>("before", before.ToString()), new KeyValuePair <string, string>("after", after.ToString()), new KeyValuePair <string, string>("limit", limit.ToString()) } ) .Respond("application/json", "[]") ); var result = await api.GetCurrentUserGuildsAsync(before, after, limit); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var applicationID = new Snowflake(0); var name = "aaa"; var description = "wwww"; 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.Successful(result); }
public async Task PerformsRequestCorrectly() { var applicationID = new Snowflake(0); var guildID = new Snowflake(1); var commandID = new Snowflake(2); var api = CreateAPI ( b => b .Expect ( HttpMethod.Get, $"{Constants.BaseURL}applications/{applicationID}/guilds/{guildID}/commands/{commandID}" ) .WithNoContent() .Respond("application/json", SampleRepository.Samples[typeof(IApplicationCommand)]) ); var result = await api.GetGuildApplicationCommandAsync ( applicationID, guildID, commandID ); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { 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(9894494448401390090); 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.Successful(result); }
public async Task PerformsRequestCorrectly() { var username = "******"; // Create a dummy PNG image await using var avatar = new MemoryStream(); await using var binaryWriter = new BinaryWriter(avatar); binaryWriter.Write(9894494448401390090); avatar.Position = 0; var api = CreateAPI ( b => b .Expect(HttpMethod.Patch, $"{Constants.BaseURL}users/@me") .WithJson ( j => j.IsObject ( o => o .WithProperty("username", p => p.Is(username)) .WithProperty("avatar", p => p.IsString()) ) ) .Respond("application/json", SampleRepository.Samples[typeof(IUser)]) ); var result = await api.ModifyCurrentUserAsync(username, avatar); ResultAssert.Successful(result); }
public async Task CanExecuteCommandFromGroupThatWantsInterfaceContext() { var dummyContext = new Mock <ICommandContext>().Object; _contextInjection.Context = dummyContext; var result = await _commands.TryExecuteAsync("interface command", _services); ResultAssert.Successful(result); }
public void ReturnsSuccessForValidTree() { var builder = new CommandTreeBuilder(); builder.RegisterModule <ValidCommandGroup>(); var tree = builder.Build(); var result = tree.CreateApplicationCommands(out _); ResultAssert.Successful(result); }
public void ReturnsSuccessfulIfAnEnumHasTooManyChoices() { var builder = new CommandTreeBuilder(); builder.RegisterModule <TooManyChoiceValues>(); var tree = builder.Build(); var result = tree.CreateApplicationCommands(out _); ResultAssert.Successful(result); }
public async Task CanPackGIFAsync() { // Create a dummy GIF image await using var image = new MemoryStream(); await using var binaryWriter = new BinaryWriter(image); binaryWriter.Write(0x00464947); image.Position = 0; var result = await ImagePacker.PackImageAsync(image); ResultAssert.Successful(result); }
public async Task CanPackPNGAsync() { // Create a dummy PNG image await using var image = new MemoryStream(); await using var binaryWriter = new BinaryWriter(image); binaryWriter.Write(9894494448401390090); image.Position = 0; var result = await ImagePacker.PackImageAsync(image); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var api = CreateAPI ( b => b .Expect(HttpMethod.Get, $"{Constants.BaseURL}users/@me") .Respond("application/json", SampleRepository.Samples[typeof(IUser)]) ); var result = await api.GetCurrentUserAsync(); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var api = CreateAPI ( b => b .Expect(HttpMethod.Get, $"{Constants.BaseURL}users/@me/connections") .Respond("application/json", "[]") ); var result = await api.GetUserConnectionsAsync(); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var api = CreateAPI ( b => b .Expect(HttpMethod.Get, $"{Constants.BaseURL}oauth2/@me") .WithNoContent() .Respond("Authorization/json", SampleRepository.Samples[typeof(IAuthorizationInformation)]) ); var result = await api.GetCurrentAuthorizationInformationAsync(); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var inviteCode = "brr"; var api = CreateAPI ( b => b .Expect(HttpMethod.Delete, $"{Constants.BaseURL}invite/{inviteCode}") .Respond("application/json", SampleRepository.Samples[typeof(IInvite)]) ); var result = await api.DeleteInviteAsync(inviteCode); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var api = CreateAPI ( b => b .Expect(HttpMethod.Get, $"{Constants.BaseURL}gateway") .WithNoContent() .Respond("application/json", SampleRepository.Samples[typeof(IGatewayEndpoint)]) ); var result = await api.GetGatewayAsync(); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var guildId = new Snowflake(0); var api = CreateAPI ( b => b .Expect(HttpMethod.Get, $"{Constants.BaseURL}guilds/{guildId}/templates") .Respond("application/json", "[ ]") ); var result = await api.GetGuildTemplatesAsync(guildId); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var templateCode = "aaa"; var api = CreateAPI ( b => b .Expect(HttpMethod.Get, $"{Constants.BaseURL}guilds/templates/{templateCode}") .Respond("application/json", SampleRepository.Samples[typeof(ITemplate)]) ); var result = await api.GetTemplateAsync(templateCode); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var guildId = new Snowflake(0); var api = CreateAPI ( b => b .Expect(HttpMethod.Delete, $"{Constants.BaseURL}users/@me/guilds/{guildId}") .Respond(HttpStatusCode.NoContent) ); var result = await api.LeaveGuildAsync(guildId); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var channelID = new Snowflake(1); var api = CreateAPI ( b => b .Expect(HttpMethod.Delete, $"{Constants.BaseURL}stage-instances/{channelID}") .WithNoContent() .Respond(HttpStatusCode.NoContent) ); var result = await api.DeleteStageInstance(channelID); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var channelID = new Snowflake(1); var api = CreateAPI ( b => b .Expect(HttpMethod.Get, $"{Constants.BaseURL}stage-instances/{channelID}") .WithNoContent() .Respond("application/json", SampleRepository.Samples[typeof(IStageInstance)]) ); var result = await api.GetStageInstanceAsync(channelID); ResultAssert.Successful(result); }
public async Task PerformsRequestCorrectly() { var guildId = new Snowflake(0); var emojiId = new Snowflake(1); var api = CreateAPI ( b => b .Expect(HttpMethod.Get, $"{Constants.BaseURL}guilds/{guildId}/emojis/{emojiId}") .WithNoContent() .Respond("application/json", SampleRepository.Samples[typeof(IEmoji)]) ); var result = await api.GetGuildEmojiAsync(guildId, emojiId); ResultAssert.Successful(result); }