UserInfoTest.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using JCSoft.WX.Framework.Models.ApiRequests;
  7. using JCSoft.WX.Framework.Models.ApiResponses;
  8. using Xunit;
  9. namespace FrameworkCoreTest
  10. {
  11. public class UserInfoTest : MockPostApiBaseTest<UserInfoRequest, UserInfoResponse>
  12. {
  13. [Fact]
  14. public void MockUserInfoTest()
  15. {
  16. MockSetup(false);
  17. var response = mock_client.Object.Execute(Request);
  18. Assert.Equal(false, response.IsError);
  19. Assert.Equal("o6_bmjrPTlm6_2sgVt7hMZOPfL2M", response.OpenId);
  20. Assert.Equal("广州", response.City);
  21. Assert.Equal("o6_bmasdasdsad6_2sgVt7hMZOPfL", response.UnionID);
  22. }
  23. [Fact]
  24. public void MockUserInfoErrorTest()
  25. {
  26. MockSetup(true);
  27. var response = mock_client.Object.Execute(Request);
  28. Assert.Equal(true, response.IsError);
  29. Console.WriteLine(response);
  30. }
  31. protected override UserInfoRequest InitRequestObject()
  32. {
  33. return new UserInfoRequest
  34. {
  35. AccessToken = "asdf",
  36. Lang = "zh_cn",
  37. OpenId = "asdf"
  38. };
  39. }
  40. protected override string GetReturnResult(bool errResult)
  41. {
  42. if (errResult)
  43. return "{\"errcode\":40013,\"errmsg\":\"invalid appid\"}";
  44. return @"{
  45. ""subscribe"": 1,
  46. ""openid"": ""o6_bmjrPTlm6_2sgVt7hMZOPfL2M"",
  47. ""nickname"": ""Band"",
  48. ""sex"": 1,
  49. ""language"": ""zh_CN"",
  50. ""city"": ""广州"",
  51. ""province"": ""广东"",
  52. ""country"": ""中国"",
  53. ""headimgurl"": ""http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0"",
  54. ""subscribe_time"": 1382694957,
  55. ""unionid"": ""o6_bmasdasdsad6_2sgVt7hMZOPfL""
  56. }";
  57. }
  58. }
  59. }