GroupsQueryTest.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using JCSoft.WX.Framework.Models.ApiRequests;
  3. using Xunit;
  4. using JCSoft.WX.Framework.Models.Exceptions;
  5. using System.Threading.Tasks;
  6. namespace FrameworkCoreTest
  7. {
  8. public class GroupsQueryTest : BaseTest
  9. {
  10. [Fact]
  11. public void GroupsQueryTestNoToken()
  12. {
  13. var request = new GroupsQueryRequest();
  14. Assert.Throws<WXApiException>(() =>
  15. {
  16. mock_client.Object.Execute(request);
  17. });
  18. }
  19. [Fact]
  20. public void MockGroupsQueryTest()
  21. {
  22. var request = new GroupsQueryRequest()
  23. {
  24. AccessToken = "asdf"
  25. };
  26. var doresult = @"{
  27. ""groups"": [
  28. {
  29. ""id"": 0,
  30. ""name"": ""未分组"",
  31. ""count"": 72596
  32. },
  33. {
  34. ""id"": 1,
  35. ""name"": ""黑名单"",
  36. ""count"": 36
  37. },
  38. {
  39. ""id"": 2,
  40. ""name"": ""星标组"",
  41. ""count"": 8
  42. },
  43. {
  44. ""id"": 104,
  45. ""name"": ""华东媒"",
  46. ""count"": 4
  47. },
  48. {
  49. ""id"": 106,
  50. ""name"": ""★不测试组★"",
  51. ""count"": 1
  52. }
  53. ]
  54. }";
  55. //mock_client.Setup(d => d.Execute(request)).Returns(new Task<string>(() => doresult));
  56. var response = mock_client.Object.Execute(request);
  57. foreach (var group in response.Groups)
  58. {
  59. Console.WriteLine("id:{0}, name:{1}, count:{2}", group.ID, group.Name, group.Count);
  60. }
  61. }
  62. [Fact]
  63. public void GrousQueryTest()
  64. {
  65. //ApiAccessTokenManager.Instance.SetAppIdentity(m_appIdentity);
  66. var token = GetCurrentToken();
  67. var request = new GroupsQueryRequest()
  68. {
  69. AccessToken = token
  70. };
  71. var response = mock_client.Object.Execute(request);
  72. if (!response.IsError)
  73. {
  74. foreach (var group in response.Groups)
  75. {
  76. Console.WriteLine("id:{0}, name:{1}, count:{2}", group.ID, group.Name, group.Count);
  77. }
  78. }
  79. else
  80. {
  81. Console.WriteLine(response.ErrorCode + ", " + response.ErrorMessage);
  82. }
  83. }
  84. }
  85. }