* Fix #995 ICategoryChannel.CategoryID throws NotSupportedException * Add tests * change run mode of TestChannelCategories * Add throw for GetCategoryAsync * Add xml doc explaining why exception is thrown * Add test coverage for text and voice channel categories * initial implementation of INestedChannel * more implementation of INestedChannel design * Add case in RestChannel Create for Category type * set the CategoryID for RestVoiceChannel * rewrite channel category tests to work with existing pattern * remove outdated todo * Make IVoiceChannel implement INestedChannel * remove redundant interface implementation * Add c#7 feature from feedback * Remove redundant GetCategoryAsync methods from socket entities * Added configureawait to async methods * change signature of interface GetCategoryAsync * Add check for cachemode in rest channel GetCategory * remove redundant IGuildChannel interface from ITextChannel and IVoiceChannel
This commit is contained in:
committed by
Christopher F
parent
4d8764e124
commit
f9cbff5e42
@@ -1,4 +1,5 @@
|
||||
using Discord.Rest;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
@@ -15,17 +16,28 @@ namespace Discord
|
||||
var text4 = await guild.CreateTextChannelAsync("text4");
|
||||
var text5 = await guild.CreateTextChannelAsync("text5");
|
||||
|
||||
// create a channel category
|
||||
var cat1 = await guild.CreateCategoryChannelAsync("cat1");
|
||||
|
||||
if (text1 == null)
|
||||
{
|
||||
// the guild did not have a default channel, so make a new one
|
||||
text1 = await guild.CreateTextChannelAsync("default");
|
||||
}
|
||||
|
||||
//Modify #general
|
||||
await text1.ModifyAsync(x =>
|
||||
{
|
||||
x.Name = "text1";
|
||||
x.Position = 1;
|
||||
x.Topic = "Topic1";
|
||||
x.CategoryId = cat1.Id;
|
||||
});
|
||||
|
||||
await text2.ModifyAsync(x =>
|
||||
{
|
||||
x.Position = 2;
|
||||
x.CategoryId = cat1.Id;
|
||||
});
|
||||
await text3.ModifyAsync(x =>
|
||||
{
|
||||
@@ -89,10 +101,13 @@ namespace Discord
|
||||
var voice2 = await guild.CreateVoiceChannelAsync("voice2");
|
||||
var voice3 = await guild.CreateVoiceChannelAsync("voice3");
|
||||
|
||||
var cat2 = await guild.CreateCategoryChannelAsync("cat2");
|
||||
|
||||
await voice1.ModifyAsync(x =>
|
||||
{
|
||||
x.Bitrate = 96000;
|
||||
x.Position = 1;
|
||||
x.CategoryId = cat2.Id;
|
||||
});
|
||||
await voice2.ModifyAsync(x =>
|
||||
{
|
||||
@@ -103,6 +118,7 @@ namespace Discord
|
||||
x.Bitrate = 8000;
|
||||
x.Position = 1;
|
||||
x.UserLimit = 16;
|
||||
x.CategoryId = cat2.Id;
|
||||
});
|
||||
|
||||
CheckVoiceChannels(voice1, voice2, voice3);
|
||||
@@ -140,5 +156,63 @@ namespace Discord
|
||||
Assert.Equal(1, voice3.Position);
|
||||
Assert.Equal(16, voice3.UserLimit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestChannelCategories()
|
||||
{
|
||||
// (await _guild.GetVoiceChannelsAsync()).ToArray()
|
||||
var channels = await _guild.GetCategoryChannelsAsync();
|
||||
|
||||
await CheckChannelCategories(channels.ToArray(), (await _guild.GetChannelsAsync()).ToArray());
|
||||
}
|
||||
|
||||
private async Task CheckChannelCategories(RestCategoryChannel[] categories, RestGuildChannel[] allChannels)
|
||||
{
|
||||
// 2 categories
|
||||
Assert.Equal(categories.Length, 2);
|
||||
|
||||
var cat1 = categories.Where(x => x.Name == "cat1").FirstOrDefault();
|
||||
var cat2 = categories.Where(x => x.Name == "cat2").FirstOrDefault();
|
||||
|
||||
Assert.NotNull(cat1);
|
||||
Assert.NotNull(cat2);
|
||||
|
||||
// get text1, text2, ensure they have category id == cat1
|
||||
var text1 = allChannels.Where(x => x.Name == "text1").FirstOrDefault() as RestTextChannel;
|
||||
var text2 = allChannels.Where(x => x.Name == "text2").FirstOrDefault() as RestTextChannel;
|
||||
|
||||
Assert.NotNull(text1);
|
||||
Assert.NotNull(text2);
|
||||
|
||||
// check that CategoryID and .GetCategoryAsync work correctly
|
||||
// for both of the text channels
|
||||
Assert.Equal(text1.CategoryId, cat1.Id);
|
||||
var text1Cat = await text1.GetCategoryAsync();
|
||||
Assert.Equal(text1Cat.Id, cat1.Id);
|
||||
Assert.Equal(text1Cat.Name, cat1.Name);
|
||||
|
||||
Assert.Equal(text2.CategoryId, cat1.Id);
|
||||
var text2Cat = await text2.GetCategoryAsync();
|
||||
Assert.Equal(text2Cat.Id, cat1.Id);
|
||||
Assert.Equal(text2Cat.Name, cat1.Name);
|
||||
|
||||
// do the same for the voice channels
|
||||
var voice1 = allChannels.Where(x => x.Name == "voice1").FirstOrDefault() as RestVoiceChannel;
|
||||
var voice3 = allChannels.Where(x => x.Name == "voice3").FirstOrDefault() as RestVoiceChannel;
|
||||
|
||||
Assert.NotNull(voice1);
|
||||
Assert.NotNull(voice3);
|
||||
|
||||
Assert.Equal(voice1.CategoryId, cat2.Id);
|
||||
var voice1Cat = await voice1.GetCategoryAsync();
|
||||
Assert.Equal(voice1Cat.Id, cat2.Id);
|
||||
Assert.Equal(voice1Cat.Name, cat2.Name);
|
||||
|
||||
Assert.Equal(voice3.CategoryId, cat2.Id);
|
||||
var voice3Cat = await voice3.GetCategoryAsync();
|
||||
Assert.Equal(voice3Cat.Id, cat2.Id);
|
||||
Assert.Equal(voice3Cat.Name, cat2.Name);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user