Guilds ------ + Get Guild + Get Invalid Guild + Get Guilds + Get Guild/Bans * Get Guild/User + Get Guild/Invalid User + Get Guild/Users - Get Guild/Role - Get Guild/Invalid Role - Get Guild/Roles - Get Guild/Invites Users ----- + Get Invalid Userpull/62/head
| @@ -55,12 +55,17 @@ | |||||
| </Otherwise> | </Otherwise> | ||||
| </Choose> | </Choose> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <Compile Include="Rest\Framework\Serializer.cs" /> | |||||
| <Compile Include="Rest\GuildTests.cs" /> | |||||
| <Compile Include="Rest\LoginTests.cs" /> | <Compile Include="Rest\LoginTests.cs" /> | ||||
| <Compile Include="Rest\Framework\EndpointHandler.cs" /> | <Compile Include="Rest\Framework\EndpointHandler.cs" /> | ||||
| <Compile Include="Rest\Responses\Users\Me_Mocks.cs" /> | |||||
| <Compile Include="Rest\Responses\Guilds\GuildHandlers.cs" /> | |||||
| <Compile Include="Rest\Responses\Guilds\Guild_Mocks.cs" /> | |||||
| <Compile Include="Rest\Responses\Roles\Role_Mocks.cs" /> | |||||
| <Compile Include="Rest\Responses\Guilds\Member_Mocks.cs" /> | |||||
| <Compile Include="Rest\Responses\Users\User_Mocks.cs" /> | |||||
| <Compile Include="Rest\Responses\Users\UserHandlers.cs" /> | <Compile Include="Rest\Responses\Users\UserHandlers.cs" /> | ||||
| <Compile Include="Rest\Framework\TestRestClient.cs" /> | <Compile Include="Rest\Framework\TestRestClient.cs" /> | ||||
| <Compile Include="Rest\Responses\Users\User_Mocks.cs" /> | |||||
| <Compile Include="Rest\UserTests.cs" /> | <Compile Include="Rest\UserTests.cs" /> | ||||
| <Compile Include="Tests.cs" /> | <Compile Include="Tests.cs" /> | ||||
| <Compile Include="Properties\AssemblyInfo.cs" /> | <Compile Include="Properties\AssemblyInfo.cs" /> | ||||
| @@ -19,14 +19,25 @@ namespace Discord.Tests.Rest | |||||
| Handlers = new Dictionary<string, RestMessageHandler>(); | Handlers = new Dictionary<string, RestMessageHandler>(); | ||||
| // /users Endpoints | // /users Endpoints | ||||
| Handlers.Add("users/@me", Responses.Users.UserHandlers.Me_Handler); | |||||
| Handlers.Add("users/96642168176807936", Responses.Users.UserHandlers.Id_User_Valid); | |||||
| Handlers.Add("GET->users/@me", Responses.Users.UserHandlers.Me_Handler); | |||||
| Handlers.Add("GET->users/96642168176807936", Responses.Users.UserHandlers.Id_User_Valid); | |||||
| Handlers.Add("GET->users/1", Responses.Users.UserHandlers.Id_User_Invalid); | |||||
| Handlers.Add("GET->users/@me/guilds", Responses.Users.UserHandlers.Me_Guilds); | |||||
| // /guilds endpoints | |||||
| Handlers.Add("GET->guilds/66078535390867456", Responses.Guilds.GuildHandlers.Id_Valid); | |||||
| Handlers.Add("GET->guilds/66078535390867456/bans", Responses.Guilds.GuildHandlers.Bans_Valid); | |||||
| Handlers.Add("GET->guilds/66078535390867456/members?limit=2147483647&offset=0", Responses.Guilds.GuildHandlers.Members_Valid); | |||||
| Handlers.Add("GET->guilds/66078535390867456/members/1", Responses.Guilds.GuildHandlers.Member_Invalid); | |||||
| Handlers.Add("GET->guilds/66078535390867456/members/66078337084162048", Responses.Guilds.GuildHandlers.Member_Valid); | |||||
| Handlers.Add("GET->guilds/1", Responses.Guilds.GuildHandlers.Id_Invalid); | |||||
| } | } | ||||
| public string HandleMessage(string method, string endpoint, string json) | public string HandleMessage(string method, string endpoint, string json) | ||||
| { | { | ||||
| if (Handlers.ContainsKey(endpoint)) | |||||
| return Handlers[endpoint].Invoke(method, json); | |||||
| var key = $"{method}->{endpoint}"; | |||||
| if (Handlers.ContainsKey(key)) | |||||
| return Handlers[key].Invoke(method, json); | |||||
| throw new NotImplementedException($"{method} -> {endpoint} -> {json}"); | throw new NotImplementedException($"{method} -> {endpoint} -> {json}"); | ||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,41 @@ | |||||
| using Discord.Net.Converters; | |||||
| using Newtonsoft.Json; | |||||
| using System; | |||||
| using System.IO; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| using System.Globalization; | |||||
| namespace Discord.Tests.Rest | |||||
| { | |||||
| public class Json | |||||
| { | |||||
| public static JsonSerializer Serializer; | |||||
| public Json() | |||||
| { | |||||
| Serializer = new JsonSerializer(); | |||||
| var _serializer = new JsonSerializer(); | |||||
| _serializer.Converters.Add(new ChannelTypeConverter()); | |||||
| _serializer.Converters.Add(new ImageConverter()); | |||||
| _serializer.Converters.Add(new NullableUInt64Converter()); | |||||
| _serializer.Converters.Add(new PermissionTargetConverter()); | |||||
| _serializer.Converters.Add(new StringEntityConverter()); | |||||
| _serializer.Converters.Add(new UInt64Converter()); | |||||
| _serializer.Converters.Add(new UInt64EntityConverter()); | |||||
| _serializer.Converters.Add(new UserStatusConverter()); | |||||
| Serializer = _serializer; | |||||
| } | |||||
| public static string SerializeObject(object o) | |||||
| { | |||||
| var sb = new StringBuilder(256); | |||||
| using (TextWriter text = new StringWriter(sb, CultureInfo.InvariantCulture)) | |||||
| using (JsonWriter writer = new JsonTextWriter(text)) | |||||
| Serializer.Serialize(writer, o); | |||||
| return sb.ToString(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,119 @@ | |||||
| using Discord.Rest; | |||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace Discord.Tests.Rest | |||||
| { | |||||
| [TestClass] | |||||
| public class GuildTests | |||||
| { | |||||
| public static TestContext Context; | |||||
| private static IDiscordClient _client; | |||||
| [ClassInitialize] | |||||
| public static void Initialize(TestContext context) | |||||
| { | |||||
| Context = context; | |||||
| _client = new DiscordClient(new DiscordConfig() { RestClientProvider = (url, ct) => new TestRestClient(url, ct) }); | |||||
| if (EndpointHandler.Instance == null) EndpointHandler.Instance = new EndpointHandler(); | |||||
| if (Json.Serializer == null) new Json(); | |||||
| Responses.Users.UserHandlers.Mode = Rest.Responses.Users.TestMode.User; | |||||
| _client.Login(TokenType.User, "UserToken_Voltana").Wait(); | |||||
| } | |||||
| [TestMethod] | |||||
| [TestCategory("Guilds")] | |||||
| public async Task Test_Get_Guild() | |||||
| { | |||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| Assert.AreEqual(66078535390867456UL, guild.Id, "Expected ID '66078535390867456'"); | |||||
| Assert.AreEqual("Discord API", guild.Name, "Expected Name 'Discord API'"); | |||||
| // Cannot Verify Guild URL, ID not publicly exposed. | |||||
| Assert.IsNull(guild.SplashUrl, "Expected SplashUrl 'null'"); | |||||
| Assert.AreEqual(66078337084162048UL, guild.OwnerId, "Expected OwnerId '66078337084162048'"); | |||||
| Assert.AreEqual(3600, guild.AFKTimeout, "Expected AFKTimeout '3600'"); | |||||
| Assert.AreEqual(true, guild.IsEmbeddable, "Expected Embeddable 'true'"); | |||||
| Assert.IsNull(guild.EmbedChannelId, "Expected EmbedChannelId 'null'"); | |||||
| Assert.AreEqual(0, guild.VerificationLevel, "Expected VerificationLevel '0'"); | |||||
| } | |||||
| [TestMethod] | |||||
| [TestCategory("Guilds")] | |||||
| public async Task Test_Get_Guild_Invalid_Id() | |||||
| { | |||||
| var guild = await _client.GetGuild(1); | |||||
| Assert.IsNull(guild); | |||||
| } | |||||
| [TestMethod] | |||||
| [TestCategory("Guilds")] | |||||
| public async Task Test_Get_Guilds() | |||||
| { | |||||
| var guilds = await _client.GetGuilds(); | |||||
| Assert.AreEqual(2, guilds.Count(), "Expected 2 Guilds"); | |||||
| } | |||||
| [TestMethod] | |||||
| [TestCategory("Guilds")] | |||||
| public async Task Test_Guild_Get_Bans() | |||||
| { | |||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var bans = await guild.GetBans(); | |||||
| Assert.AreEqual(2, bans.Count()); | |||||
| } | |||||
| [TestMethod] | |||||
| [TestCategory("Guilds")] | |||||
| public async Task Test_Guild_Get_User() | |||||
| { | |||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var user = await guild.GetUser(66078337084162048); | |||||
| // TODO: Asserts | |||||
| } | |||||
| [TestMethod] | |||||
| [TestCategory("Guilds")] | |||||
| public async Task Test_Guild_Get_Invalid_User() | |||||
| { | |||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var user = await guild.GetUser(1); | |||||
| Assert.IsNull(user, "Expected returned user to be null"); | |||||
| } | |||||
| [TestMethod] | |||||
| [TestCategory("Guilds")] | |||||
| public async Task Test_Guild_Get_Users() | |||||
| { | |||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var users = await guild.GetUsers(); | |||||
| Assert.AreEqual(2, users.Count()); | |||||
| } | |||||
| [TestMethod] | |||||
| [TestCategory("Guilds")] | |||||
| public async Task Test_Guild_Get_Role() | |||||
| { | |||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var role = await guild.GetRole(1); | |||||
| } | |||||
| [TestMethod] | |||||
| [TestCategory("Guilds")] | |||||
| public async Task Test_Guild_Get_Invalid_Role() | |||||
| { | |||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var role = await guild.GetRole(1); | |||||
| Assert.IsNull(role, "Expected returned role to be null."); | |||||
| } | |||||
| [TestMethod] | |||||
| [TestCategory("Guilds")] | |||||
| public async Task Test_Guild_Get_Roles() | |||||
| { | |||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var roles = await guild.GetRoles(); | |||||
| } | |||||
| [TestMethod] | |||||
| [TestCategory("Guilds")] | |||||
| public async Task Test_Guild_Get_Invites() | |||||
| { | |||||
| var guild = await _client.GetGuild(66078535390867456); | |||||
| var invites = await guild.GetInvites(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -20,6 +20,7 @@ namespace Discord.Tests.Rest | |||||
| Context = context; | Context = context; | ||||
| _client = new DiscordClient(new DiscordConfig() { RestClientProvider = (url, ct) => new TestRestClient(url, ct) }); | _client = new DiscordClient(new DiscordConfig() { RestClientProvider = (url, ct) => new TestRestClient(url, ct) }); | ||||
| if (EndpointHandler.Instance == null) EndpointHandler.Instance = new EndpointHandler(); | if (EndpointHandler.Instance == null) EndpointHandler.Instance = new EndpointHandler(); | ||||
| if (Json.Serializer == null) new Json(); | |||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| @@ -0,0 +1,50 @@ | |||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | |||||
| using Newtonsoft.Json; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Net; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace Discord.Tests.Rest.Responses.Guilds | |||||
| { | |||||
| public static class GuildHandlers | |||||
| { | |||||
| public static string Id_Valid(string method, string json) | |||||
| { | |||||
| Assert.AreEqual("GET", method, "Expected method to '/guilds/:id' is GET."); | |||||
| return Json.SerializeObject(Guild_Mocks.Guild_From_Id); | |||||
| } | |||||
| public static string Id_Invalid(string method, string json) | |||||
| { | |||||
| Assert.AreEqual("GET", method, "Expected method to '/guilds/:id' is GET."); | |||||
| throw new Net.HttpException((HttpStatusCode)404); | |||||
| } | |||||
| public static string Bans_Valid(string method, string json) | |||||
| { | |||||
| Assert.AreEqual("GET", method, "Expected method to '/guilds/:id/bans' is GET."); | |||||
| return Json.SerializeObject(Guild_Mocks.GuildBansList); | |||||
| } | |||||
| public static string Members_Valid(string method, string json) | |||||
| { | |||||
| Assert.AreEqual("GET", method, "Expected method to '/guilds/:id/members' is GET."); | |||||
| return Json.SerializeObject(Member_Mocks.Guild_Members); | |||||
| } | |||||
| public static string Member_Valid(string method, string json) | |||||
| { | |||||
| Assert.AreEqual("GET", method, "Expected method to '/guilds/:id/members/:member_id' is GET."); | |||||
| return Json.SerializeObject(Member_Mocks.Guild_Member_1); | |||||
| } | |||||
| public static string Member_Invalid(string method, string json) | |||||
| { | |||||
| Assert.AreEqual("GET", method, "Expected method to '/guilds/:id/members/:member_id' is GET."); | |||||
| throw new Net.HttpException((HttpStatusCode)404); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,64 @@ | |||||
| using Discord.API; | |||||
| using Newtonsoft.Json; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace Discord.Tests.Rest.Responses.Guilds | |||||
| { | |||||
| public static class Guild_Mocks | |||||
| { | |||||
| public static Guild Guild_From_Id { get | |||||
| { | |||||
| return new Guild | |||||
| { | |||||
| Id = 66078535390867456, | |||||
| Name = "Discord API", | |||||
| Icon = "c8829ee5a88cbe065519befa9093f63a", | |||||
| Splash = null, | |||||
| OwnerId = 66078337084162048, | |||||
| Region = "us-east", | |||||
| AFKChannelId = 66081976485941248, | |||||
| AFKTimeout = 3600, | |||||
| EmbedEnabled = true, | |||||
| EmbedChannelId = null, | |||||
| VerificationLevel = 0, | |||||
| Roles = new Role[] {Roles.Constant_Role_Mocks.Mock_Everyone_Role}, | |||||
| }; | |||||
| } } | |||||
| public static IEnumerable<User> GuildBansList => new List<User> { Users.User_Mocks.Bot_User, Users.User_Mocks.Me_User }; | |||||
| public static IEnumerable<UserGuild> UserGuildsList() => new List<UserGuild>{ User_Guild_1, User_Guild_2 }; | |||||
| public static UserGuild User_Guild_1 { get | |||||
| { | |||||
| return new UserGuild | |||||
| { | |||||
| Id = 41771983423143937, | |||||
| Name = "Discord Developers", | |||||
| Icon = "ae140f33228348df347067059474bb11", | |||||
| Owner = false, | |||||
| Permissions = 103926785 | |||||
| }; | |||||
| } } | |||||
| public static UserGuild User_Guild_2 | |||||
| { | |||||
| get | |||||
| { | |||||
| return new UserGuild | |||||
| { | |||||
| Id = 81384788765712384, | |||||
| Name = "Discord API", | |||||
| Icon = "2aab26934e72b4ec300c5aa6cf67c7b3", | |||||
| Owner = false, | |||||
| Permissions = 103926785 | |||||
| }; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,36 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| using Discord.API; | |||||
| namespace Discord.Tests.Rest.Responses.Guilds | |||||
| { | |||||
| public static class Member_Mocks | |||||
| { | |||||
| public static IEnumerable<GuildMember> Guild_Members => new List<GuildMember> { Guild_Member_1, Guild_Member_2 }; | |||||
| public static GuildMember Guild_Member_1 { get { | |||||
| return new GuildMember() | |||||
| { | |||||
| User = Users.User_Mocks.Me_User, | |||||
| Nick = "Voltamom", | |||||
| JoinedAt = new DateTime(2009, 4, 19), | |||||
| Deaf = true, | |||||
| Mute = false, | |||||
| Roles = new ulong[] { 1UL } | |||||
| }; | |||||
| } } | |||||
| public static GuildMember Guild_Member_2 { get | |||||
| { | |||||
| return new GuildMember() | |||||
| { | |||||
| User = Users.User_Mocks.Bot_User, | |||||
| Nick = "foxbot", | |||||
| JoinedAt = new DateTime(2016, 5, 5), | |||||
| }; | |||||
| } } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,23 @@ | |||||
| using Newtonsoft.Json; | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| using Discord.API; | |||||
| namespace Discord.Tests.Rest.Responses.Roles | |||||
| { | |||||
| public static class Constant_Role_Mocks | |||||
| { | |||||
| public static Role Mock_Everyone_Role { get { return new Role { | |||||
| Id = 66078535390867456, | |||||
| Color = 0, | |||||
| Position = 0, | |||||
| Hoist = false, | |||||
| Managed = false, | |||||
| Name = "@everyone", | |||||
| Permissions = 36953089 | |||||
| }; } } | |||||
| } | |||||
| } | |||||
| @@ -1,38 +0,0 @@ | |||||
| using Newtonsoft.Json; | |||||
| namespace Discord.Tests.Rest.Responses.Users | |||||
| { | |||||
| public class Mock_Me_User_Valid | |||||
| { | |||||
| [JsonProperty("id")] | |||||
| public string Id => "66078337084162048"; | |||||
| [JsonProperty("username")] | |||||
| public string Username => "Voltana"; | |||||
| [JsonProperty("discriminator")] | |||||
| public ushort Discriminator => 0001; | |||||
| [JsonProperty("avatar")] | |||||
| public string Avatar => "ec2b259bfe24686bf9d214b6bebe0834"; | |||||
| [JsonProperty("verified")] | |||||
| public bool IsVerified => true; | |||||
| [JsonProperty("email")] | |||||
| public string Email => "hello-i-am-not-real@foxbot.me"; | |||||
| } | |||||
| public class Mock_Me_Token_Valid | |||||
| { | |||||
| [JsonProperty("id")] | |||||
| public string Id => "66078337084162048"; | |||||
| [JsonProperty("username")] | |||||
| public string Username => "foxboat"; | |||||
| [JsonProperty("discriminator")] | |||||
| public ushort Discriminator => 0005; | |||||
| [JsonProperty("avatar")] | |||||
| public string Avatar => "ec2b259bfe24686bf9d214b6bebe0834"; | |||||
| [JsonProperty("verified")] | |||||
| public bool IsVerified => true; | |||||
| [JsonProperty("email")] | |||||
| public string Email => "hello-i-am-not-real@foxbot.me"; | |||||
| [JsonProperty("bot")] | |||||
| public bool Bot => true; | |||||
| } | |||||
| } | |||||
| @@ -27,20 +27,32 @@ namespace Discord.Tests.Rest.Responses.Users | |||||
| { | { | ||||
| Assert.AreEqual("GET", method, "Expected method to '/users/@me' is GET."); | Assert.AreEqual("GET", method, "Expected method to '/users/@me' is GET."); | ||||
| if (TestRestClient.Headers["authorization"] != "UserToken_Voltana") throw new HttpException((HttpStatusCode)401); | if (TestRestClient.Headers["authorization"] != "UserToken_Voltana") throw new HttpException((HttpStatusCode)401); | ||||
| return JsonConvert.SerializeObject(new Mock_Me_User_Valid()); | |||||
| return Json.SerializeObject(User_Mocks.Me_User); | |||||
| } | } | ||||
| public static string Me_Bot_Valid(string method, string json) | public static string Me_Bot_Valid(string method, string json) | ||||
| { | { | ||||
| Assert.AreEqual("GET", method, "Expected method to '/users/@me' is GET."); | Assert.AreEqual("GET", method, "Expected method to '/users/@me' is GET."); | ||||
| if (TestRestClient.Headers["authorization"] != "Bot UserToken_VoltanaBot") throw new HttpException((HttpStatusCode)401); | if (TestRestClient.Headers["authorization"] != "Bot UserToken_VoltanaBot") throw new HttpException((HttpStatusCode)401); | ||||
| return JsonConvert.SerializeObject(new Mock_Me_User_Valid()); | |||||
| return Json.SerializeObject(User_Mocks.Bot_User); | |||||
| } | } | ||||
| public static string Id_User_Valid(string method, string json) | public static string Id_User_Valid(string method, string json) | ||||
| { | { | ||||
| Assert.AreEqual("GET", method, "Expected method to '/users/:id' is GET"); | Assert.AreEqual("GET", method, "Expected method to '/users/:id' is GET"); | ||||
| return JsonConvert.SerializeObject(new Mock_ID_PublicUser()); | |||||
| return Json.SerializeObject(User_Mocks.Public_User); | |||||
| } | |||||
| public static string Id_User_Invalid(string method, string json) | |||||
| { | |||||
| Assert.AreEqual("GET", method, "Expected method to '/users/:id' is GET"); | |||||
| throw new HttpException((HttpStatusCode)404); | |||||
| } | |||||
| public static string Me_Guilds(string method, string json) | |||||
| { | |||||
| Assert.AreEqual("GET", method, "Expected method to '/users/@me/guilds' is GET"); | |||||
| return Json.SerializeObject(Guilds.Guild_Mocks.UserGuildsList()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,16 +1,45 @@ | |||||
| using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
| using Discord.API; | |||||
| namespace Discord.Tests.Rest.Responses.Users | namespace Discord.Tests.Rest.Responses.Users | ||||
| { | { | ||||
| class Mock_ID_PublicUser | |||||
| public static class User_Mocks | |||||
| { | { | ||||
| [JsonProperty("id")] | |||||
| public string Id => "96642168176807936"; | |||||
| [JsonProperty("username")] | |||||
| public string Username => "Khionu"; | |||||
| [JsonProperty("discriminator")] | |||||
| public ushort Discriminator => 9999; | |||||
| [JsonProperty("avatar")] | |||||
| public string Avatar => "ceeff590f1e0e1ccae0afc89967131ff"; | |||||
| public static User Me_User { get { | |||||
| return new User | |||||
| { | |||||
| Id = 66078337084162048, | |||||
| Username = "Voltana", | |||||
| Discriminator = 0001, | |||||
| Avatar = "ec2b259bfe24686bf9d214b6bebe0834", | |||||
| IsVerified = true, | |||||
| Email = "hello-i-am-not-real@foxbot.me" | |||||
| }; | |||||
| } } | |||||
| public static User Bot_User { get | |||||
| { | |||||
| return new User | |||||
| { | |||||
| Id = 66078337084162048, | |||||
| Username = "foxboat", | |||||
| Discriminator = 0005, | |||||
| Avatar = "ec2b259bfe24686bf9d214b6bebe0834", | |||||
| IsVerified = true, | |||||
| Email = "hello-i-am-not-real@foxbot.me", | |||||
| Bot = true | |||||
| }; | |||||
| } } | |||||
| public static User Public_User { get | |||||
| { | |||||
| return new User | |||||
| { | |||||
| Id = 96642168176807936, | |||||
| Username = "Khionu", | |||||
| Discriminator = 9999, | |||||
| Avatar = "ceeff590f1e0e1ccae0afc89967131ff" | |||||
| }; | |||||
| } } | |||||
| } | } | ||||
| } | } | ||||
| @@ -20,6 +20,7 @@ namespace Discord.Tests.Rest | |||||
| Context = context; | Context = context; | ||||
| _client = new DiscordClient(new DiscordConfig() { RestClientProvider = (url, ct) => new TestRestClient(url, ct) }); | _client = new DiscordClient(new DiscordConfig() { RestClientProvider = (url, ct) => new TestRestClient(url, ct) }); | ||||
| if (EndpointHandler.Instance == null) EndpointHandler.Instance = new EndpointHandler(); | if (EndpointHandler.Instance == null) EndpointHandler.Instance = new EndpointHandler(); | ||||
| if (Json.Serializer == null) new Json(); | |||||
| Responses.Users.UserHandlers.Mode = Rest.Responses.Users.TestMode.User; | Responses.Users.UserHandlers.Mode = Rest.Responses.Users.TestMode.User; | ||||
| _client.Login(TokenType.User, "UserToken_Voltana").Wait(); | _client.Login(TokenType.User, "UserToken_Voltana").Wait(); | ||||
| } | } | ||||
| @@ -54,5 +55,12 @@ namespace Discord.Tests.Rest | |||||
| Assert.AreEqual("<@!96642168176807936>", user.NicknameMention, "Expected Mention '<@!96642168176807936>'"); | Assert.AreEqual("<@!96642168176807936>", user.NicknameMention, "Expected Mention '<@!96642168176807936>'"); | ||||
| Assert.AreEqual(new DateTime(635787084884180000), user.CreatedAt, "Expected Created At '635787084884180000'"); | Assert.AreEqual(new DateTime(635787084884180000), user.CreatedAt, "Expected Created At '635787084884180000'"); | ||||
| } | } | ||||
| [TestMethod] | |||||
| [TestCategory("Users")] | |||||
| public async Task Test_Get_Invalid_User() | |||||
| { | |||||
| var user = await _client.GetUser(1); | |||||
| Assert.IsNull(user, "Expected Invalid User to be 'null'"); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||