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.6 kB

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