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.

LoginTests.cs 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Discord;
  8. using Discord.Tests.Framework;
  9. using Discord.Tests.Framework.Responses;
  10. namespace Discord.Tests.Rest
  11. {
  12. [TestClass]
  13. public class LoginTests
  14. {
  15. public static TestContext Context;
  16. private static DiscordClient _client;
  17. [ClassInitialize]
  18. public static void Initialize(TestContext context)
  19. {
  20. Context = context;
  21. _client = new DiscordClient(new DiscordConfig() { RestClientProvider = (url, ct) => new TestRestClient(url, ct) });
  22. if (EndpointHandler.Instance == null) EndpointHandler.Instance = new EndpointHandler();
  23. if (Json.Serializer == null) new Json();
  24. }
  25. [TestMethod]
  26. [TestCategory("Login")]
  27. public async Task Test_Login_As_User()
  28. {
  29. Framework.Responses.Users.UserHandlers.Mode = Framework.Responses.Users.TestMode.User;
  30. await _client.LoginAsync(TokenType.User, "UserToken_Voltana");
  31. }
  32. [TestMethod]
  33. [ExpectedException(typeof(Net.HttpException))]
  34. [TestCategory("Login")]
  35. public async Task Test_Login_As_User_With_Invalid_Token()
  36. {
  37. Framework.Responses.Users.UserHandlers.Mode = Framework.Responses.Users.TestMode.User;
  38. await _client.LoginAsync(TokenType.User, "UserToken-NotVoltana");
  39. }
  40. [TestMethod]
  41. [TestCategory("Login")]
  42. public async Task Test_Login_As_Bot()
  43. {
  44. Framework.Responses.Users.UserHandlers.Mode = Framework.Responses.Users.TestMode.Bot;
  45. await _client.LoginAsync(TokenType.Bot, "UserToken_VoltanaBot");
  46. }
  47. [TestMethod]
  48. [ExpectedException(typeof(Net.HttpException))]
  49. [TestCategory("Login")]
  50. public async Task Test_Login_As_Bot_With_Invalid_Token()
  51. {
  52. Framework.Responses.Users.UserHandlers.Mode = Framework.Responses.Users.TestMode.Bot;
  53. await _client.LoginAsync(TokenType.Bot, "UserToken-NotVoltanaBot");
  54. }
  55. }
  56. }