You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

GuildTests.cs 4.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using Discord;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Discord.Tests.Framework;
  9. namespace Discord.Tests.Rest
  10. {
  11. [TestClass]
  12. public class GuildTests
  13. {
  14. public static TestContext Context;
  15. private static DiscordClient _client;
  16. [ClassInitialize]
  17. public static void Initialize(TestContext context)
  18. {
  19. Context = context;
  20. _client = new DiscordClient(new DiscordConfig() { RestClientProvider = (url, ct) => new TestRestClient(url, ct) });
  21. if (EndpointHandler.Instance == null) EndpointHandler.Instance = new EndpointHandler();
  22. if (Json.Serializer == null) new Json();
  23. Framework.Responses.Users.UserHandlers.Mode = Framework.Responses.Users.TestMode.User;
  24. _client.LoginAsync(TokenType.User, "UserToken_Voltana").GetAwaiter().GetResult();
  25. }
  26. [TestMethod]
  27. [TestCategory("Guilds")]
  28. public async Task Test_Get_Guild()
  29. {
  30. var guild = await _client.GetGuildAsync(66078535390867456);
  31. Assert.AreEqual(66078535390867456UL, guild.Id, "Expected ID '66078535390867456'");
  32. Assert.AreEqual("Discord API", guild.Name, "Expected Name 'Discord API'");
  33. // Cannot Verify Guild URL, ID not publicly exposed.
  34. Assert.IsNull(guild.SplashUrl, "Expected SplashUrl 'null'");
  35. Assert.AreEqual(66078337084162048UL, guild.OwnerId, "Expected OwnerId '66078337084162048'");
  36. Assert.AreEqual(3600, guild.AFKTimeout, "Expected AFKTimeout '3600'");
  37. Assert.AreEqual(true, guild.IsEmbeddable, "Expected Embeddable 'true'");
  38. Assert.IsNull(guild.EmbedChannelId, "Expected EmbedChannelId 'null'");
  39. Assert.AreEqual(0, guild.VerificationLevel, "Expected VerificationLevel '0'");
  40. }
  41. [TestMethod]
  42. [TestCategory("Guilds")]
  43. public async Task Test_Get_Guild_Invalid_Id()
  44. {
  45. var guild = await _client.GetGuildAsync(1);
  46. Assert.IsNull(guild);
  47. }
  48. [TestMethod]
  49. [TestCategory("Guilds")]
  50. public async Task Test_Get_Guilds()
  51. {
  52. var guilds = await _client.GetGuildsAsync();
  53. Assert.AreEqual(2, guilds.Count(), "Expected 2 Guilds");
  54. }
  55. [TestMethod]
  56. [TestCategory("Guilds")]
  57. public async Task Test_Guild_Get_Bans()
  58. {
  59. var guild = await _client.GetGuildAsync(66078535390867456);
  60. var bans = await guild.GetBansAsync();
  61. Assert.AreEqual(2, bans.Count());
  62. }
  63. [TestMethod]
  64. [TestCategory("Guilds")]
  65. public async Task Test_Guild_Get_User()
  66. {
  67. var guild = await _client.GetGuildAsync(66078535390867456);
  68. var user = await guild.GetUserAsync(66078337084162048);
  69. // TODO: Asserts
  70. }
  71. [TestMethod]
  72. [TestCategory("Guilds")]
  73. public async Task Test_Guild_Get_Invalid_User()
  74. {
  75. var guild = await _client.GetGuildAsync(66078535390867456);
  76. var user = await guild.GetUserAsync(1);
  77. Assert.IsNull(user, "Expected returned user to be null");
  78. }
  79. [TestMethod]
  80. [TestCategory("Guilds")]
  81. public async Task Test_Guild_Get_Users()
  82. {
  83. var guild = await _client.GetGuildAsync(66078535390867456);
  84. var users = await guild.GetUsersAsync();
  85. Assert.AreEqual(2, users.Count());
  86. }
  87. [TestMethod]
  88. [TestCategory("Guilds")]
  89. public async Task Test_Guild_Get_Role()
  90. {
  91. var guild = await _client.GetGuildAsync(66078535390867456);
  92. var role = guild.GetRole(1);
  93. }
  94. [TestMethod]
  95. [TestCategory("Guilds")]
  96. public async Task Test_Guild_Get_Invalid_Role()
  97. {
  98. var guild = await _client.GetGuildAsync(66078535390867456);
  99. var role = guild.GetRole(1);
  100. Assert.IsNull(role, "Expected returned role to be null.");
  101. }
  102. [TestMethod]
  103. [TestCategory("Guilds")]
  104. public async Task Test_Guild_Get_Roles()
  105. {
  106. var guild = await _client.GetGuildAsync(66078535390867456);
  107. var roles = guild.Roles;
  108. }
  109. [TestMethod]
  110. [TestCategory("Guilds")]
  111. public async Task Test_Guild_Get_Invites()
  112. {
  113. var guild = await _client.GetGuildAsync(66078535390867456);
  114. var invites = await guild.GetInvitesAsync();
  115. }
  116. }
  117. }