BaseTest.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using JCSoft.Core.Net.Http;
  2. using JCSoft.WX.Framework.Api;
  3. using JCSoft.WX.FrameworkTest.MockObject;
  4. using Microsoft.Extensions.Logging;
  5. using Moq;
  6. using System;
  7. using System.IO;
  8. using System.Text;
  9. namespace FrameworkCoreTest
  10. {
  11. public abstract class BaseTest
  12. {
  13. private static string tokenfile = "token.txt";
  14. static BaseTest()
  15. {
  16. //ApiAccessTokenManager.Instance.SetAppIdentity(m_appIdentity);
  17. }
  18. public BaseTest()
  19. {
  20. var factory = new HttpFactory();
  21. var logger = new MockLogger();
  22. var mockLogger = new Mock<ILogger>();
  23. mock_client = new Mock<IApiClient>();
  24. }
  25. //protected IApiClient m_client = new DefaultApiClient();
  26. protected Mock<IApiClient> mock_client = null;
  27. // protected Mock<ILogger> mock_logger = new Mock<ILogger>();
  28. public virtual string GetCurrentToken()
  29. {
  30. if (File.Exists(tokenfile))
  31. {
  32. var strs = File.ReadAllText(tokenfile, Encoding.UTF8);
  33. var splitstrs = strs.Split(new char[] { '|' });
  34. var token = splitstrs[0];
  35. var expirtime = DateTime.Parse(splitstrs[1]);
  36. if (expirtime <= DateTime.Now)
  37. {
  38. return GetToken();
  39. }
  40. return token;
  41. }
  42. else
  43. {
  44. return GetToken();
  45. }
  46. }
  47. private string GetToken()
  48. {
  49. var token = GetCurrentToken();
  50. var expirtime = "7200";
  51. File.WriteAllText(tokenfile, token + "|" + expirtime.ToString(), Encoding.UTF8);
  52. return token;
  53. }
  54. }
  55. }