OAuthAccessTokenTest.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 OAuthAccessTokenTest : MockPostApiBaseTest<SnsOAuthAccessTokenRequest, SnsOAuthAccessTokenResponse>
  12. {
  13. [Fact]
  14. public void MockSnsOAuthAccessTokenTest()
  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 MockSnsOAuthAccessTokenErrorTest()
  26. {
  27. MockSetup(true);
  28. var response = mock_client.Object.Execute(Request);
  29. Console.WriteLine(response);
  30. }
  31. protected override SnsOAuthAccessTokenRequest InitRequestObject()
  32. {
  33. return new SnsOAuthAccessTokenRequest
  34. {
  35. AppID = "AppID",
  36. AppSecret = "SECRET",
  37. Code = "CODE"
  38. };
  39. }
  40. protected override string GetReturnResult(bool errResult)
  41. {
  42. if (errResult)
  43. {
  44. return "{\"errcode\":40029,\"errmsg\":\"invalid code\"}";
  45. }
  46. return @"{
  47. ""access_token"":""ACCESS_TOKEN"",
  48. ""expires_in"":7200,
  49. ""refresh_token"":""REFRESH_TOKEN"",
  50. ""openid"":""OPENID"",
  51. ""scope"":""SCOPE""
  52. }";
  53. }
  54. }
  55. }