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.

UserHandlers.cs 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Newtonsoft.Json;
  3. using Discord.Net;
  4. using System.Net;
  5. using System;
  6. namespace Discord.Tests.Framework.Responses.Users
  7. {
  8. public static class UserHandlers
  9. {
  10. public static TestMode Mode;
  11. public static string Me_Handler(string method, string json)
  12. {
  13. switch (Mode)
  14. {
  15. case TestMode.User:
  16. return Me_User_Valid(method, json);
  17. case TestMode.Bot:
  18. return Me_Bot_Valid(method, json);
  19. default:
  20. throw new ArgumentException("TestMode was set incorrectly.");
  21. }
  22. }
  23. public static string Me_User_Valid(string method, string json)
  24. {
  25. Assert.AreEqual("GET", method, "Expected method to '/users/@me' is GET.");
  26. if (TestRestClient.Headers["authorization"] != "UserToken_Voltana") throw new HttpException((HttpStatusCode)401);
  27. return Json.SerializeObject(User_Mocks.Me_User);
  28. }
  29. public static string Me_Bot_Valid(string method, string json)
  30. {
  31. Assert.AreEqual("GET", method, "Expected method to '/users/@me' is GET.");
  32. if (TestRestClient.Headers["authorization"] != "Bot UserToken_VoltanaBot") throw new HttpException((HttpStatusCode)401);
  33. return Json.SerializeObject(User_Mocks.Bot_User);
  34. }
  35. public static string Id_User_Valid(string method, string json)
  36. {
  37. Assert.AreEqual("GET", method, "Expected method to '/users/:id' is GET");
  38. return Json.SerializeObject(User_Mocks.Public_User);
  39. }
  40. public static string Id_User_Invalid(string method, string json)
  41. {
  42. Assert.AreEqual("GET", method, "Expected method to '/users/:id' is GET");
  43. throw new HttpException((HttpStatusCode)404);
  44. }
  45. public static string Me_Guilds(string method, string json)
  46. {
  47. Assert.AreEqual("GET", method, "Expected method to '/users/@me/guilds' is GET");
  48. return Json.SerializeObject(Guilds.Guild_Mocks.UserGuildsList());
  49. }
  50. }
  51. public enum TestMode
  52. {
  53. User,
  54. Bot
  55. }
  56. }