SNSUserInfoTest.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Linq;
  3. using JCSoft.WX.Framework.Models.ApiRequests;
  4. using JCSoft.WX.Framework.Models.ApiResponses;
  5. using Xunit;
  6. using JCSoft.WX.Framework.Models;
  7. namespace FrameworkCoreTest
  8. {
  9. public class SNSUserInfoTest : MockPostApiBaseTest<SnsUserInfoRequest, SnsUserInfoResponse>
  10. {
  11. [Fact]
  12. public void MockSNSUserInfoTest()
  13. {
  14. MockSetup(false);
  15. var response = mock_client.Object.Execute(Request);
  16. Assert.Equal("NICKNAME", response.NickName);
  17. Assert.Equal("1", response.Sex);
  18. Assert.Equal(2, response.Privilege.Count());
  19. }
  20. [Fact]
  21. public void MockSNSUserInfoErrorTest()
  22. {
  23. MockSetup(true);
  24. var response = mock_client.Object.Execute(Request);
  25. Console.WriteLine(response);
  26. }
  27. protected override SnsUserInfoRequest InitRequestObject()
  28. {
  29. return new SnsUserInfoRequest
  30. {
  31. Lang = Language.CN,
  32. OAuthToken = "ACCESS_TOKEN",
  33. OpenId = "OPENID"
  34. };
  35. }
  36. protected override string GetReturnResult(bool errResult)
  37. {
  38. if (errResult)
  39. return "{\"errcode\":40003,\"errmsg\":\" invalid openid \"}";
  40. return @"{
  41. ""openid"":"" OPENID"",
  42. ""nickname"": ""NICKNAME"",
  43. ""sex"":""1"",
  44. ""province"":""PROVINCE"",
  45. ""city"":""CITY"",
  46. ""country"":""COUNTRY"",
  47. ""headimgurl"":""http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/46"",
  48. ""privilege"":[
  49. ""PRIVILEGE1"",
  50. ""PRIVILEGE2""
  51. ]
  52. }";
  53. }
  54. public override SnsUserInfoResponse GetResponse()
  55. {
  56. return mock_client.Object.Execute(Request);
  57. }
  58. }
  59. }