AccessTokenTest.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using JCSoft.Core.Net.Http;
  2. using JCSoft.WX.Framework.Api;
  3. using JCSoft.WX.Framework.Models;
  4. using JCSoft.WX.Framework.Models.ApiRequests;
  5. using JCSoft.WX.Framework.Models.ApiResponses;
  6. using JCSoft.WX.FrameworkTest.MockObject;
  7. using Microsoft.Extensions.Logging;
  8. using Moq;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Xunit;
  14. namespace JCSoft.WX.FrameworkTest.Api
  15. {
  16. public class AccessTokenTest
  17. {
  18. [Fact]
  19. public void GetResponseTest()
  20. {
  21. var request = new AccessTokenRequest(new AppIdentication("james", "mySecret"));
  22. var factory = new HttpFactory();
  23. var logger = new MockLogger();
  24. var mockLogger = new Mock<ILogger>();
  25. var client = new Mock<DefaultApiClient>(logger, factory);
  26. client.Setup(api => api.DoExecute(request))
  27. .Returns(new Task<string>(() => "{\"access_token\":\"ACCESS_TOKEN\",\"expires_in\":7200}"));
  28. var response = client.Object.Execute(request);
  29. Assert.Equal(0, response.ErrorCode);
  30. Assert.Equal("ACCESS_TOKEN", response.Access_Token);
  31. Assert.Equal(7200, response.Expires_In);
  32. }
  33. }
  34. }