OAuthRefreshTokenTest.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 OAuthRefreshTokenTest : MockPostApiBaseTest<SnsOauthRefreshTokenRequest, SnsOAuthAccessTokenResponse>
  12. {
  13. [Fact]
  14. public void MockSnsOAuthRefreshTokenTest()
  15. {
  16. MockSetup(false);
  17. var response = mock_client.Object.Execute(Request);
  18. Assert.Equal("ACCESS_TOKEN", response.AccessToken);
  19. Assert.Equal(7200, response.ExpiresIn);
  20. Assert.Equal("OPENID", response.OpenId);
  21. Assert.Equal("REFRESH_TOKEN", response.RefreshToken);
  22. Assert.Equal("SCOPE", response.Scope);
  23. }
  24. [Fact]
  25. public void MockSnsOAuthRefreshTokenErrorTest()
  26. {
  27. MockSetup(true);
  28. var response = mock_client.Object.Execute(Request);
  29. Console.WriteLine(response);
  30. }
  31. protected override SnsOauthRefreshTokenRequest InitRequestObject()
  32. {
  33. return new SnsOauthRefreshTokenRequest
  34. {
  35. AppID = "APPID",
  36. RefreshToken = "REFRESH_TOKEN"
  37. };
  38. }
  39. protected override string GetReturnResult(bool errResult)
  40. {
  41. if (errResult)
  42. {
  43. return "{\"errcode\":40029,\"errmsg\":\"invalid code\"}";
  44. }
  45. return @"{
  46. ""access_token"":""ACCESS_TOKEN"",
  47. ""expires_in"":7200,
  48. ""refresh_token"":""REFRESH_TOKEN"",
  49. ""openid"":""OPENID"",
  50. ""scope"":""SCOPE""
  51. }";
  52. }
  53. public override SnsOAuthAccessTokenResponse GetResponse()
  54. {
  55. return mock_client.Object.Execute(Request);
  56. }
  57. }
  58. }