UserGetTest.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using Xunit;
  3. using JCSoft.WX.Framework.Models.ApiResponses;
  4. using JCSoft.WX.Framework.Models.ApiRequests;
  5. namespace FrameworkCoreTest
  6. {
  7. public class UserGetTest : MockPostApiBaseTest<UserGetRequest, UserGetResponse>
  8. {
  9. [Fact]
  10. public void MockUserGetTest()
  11. {
  12. MockSetup(false);
  13. var response = mock_client.Object.Execute(Request);
  14. Assert.Equal(2, response.Total);
  15. Assert.Equal(2, response.Count);
  16. Assert.Equal(2, response.Data.OpenIds.Length);
  17. Assert.Equal("NEXT_OPENID", response.NextOpenId);
  18. }
  19. [Fact]
  20. public void MockUserGetErrorTest()
  21. {
  22. MockSetup(true);
  23. var response = mock_client.Object.Execute(Request);
  24. Assert.Equal(40013, response.ErrorCode);
  25. }
  26. [Fact]
  27. public void ReallyUserGetTest()
  28. {
  29. var request = new UserGetRequest
  30. {
  31. AccessToken = GetCurrentToken(),
  32. NextOpenId = "oI1_vjreLbQfGy79Thnsh4ziJZNo"
  33. };
  34. var response = mock_client.Object.Execute(request);
  35. if (!response.IsError)
  36. {
  37. foreach (var user in response.Data.OpenIds)
  38. {
  39. Console.WriteLine(user);
  40. }
  41. }
  42. }
  43. protected override UserGetRequest InitRequestObject()
  44. {
  45. return new UserGetRequest
  46. {
  47. AccessToken = GetCurrentToken(),
  48. NextOpenId = ""
  49. };
  50. }
  51. protected override string GetReturnResult(bool errResult)
  52. {
  53. if (errResult)
  54. {
  55. return "{\"errcode\":40013,\"errmsg\":\"invalid appid\"}";
  56. }
  57. return "{\"total\":2,\"count\":2,\"data\":{\"openid\":[\"OPENID1\",\"OPENID2\"]},\"next_openid\":\"NEXT_OPENID\"}";
  58. }
  59. }
  60. }