BaseApiTest.cs 1002 B

123456789101112131415161718192021222324252627282930313233
  1. using JCSoft.Core.Net.Http;
  2. using JCSoft.WX.Framework.Api;
  3. using JCSoft.WX.Framework.Models.ApiRequests;
  4. using JCSoft.WX.Framework.Models.ApiResponses;
  5. using Microsoft.Extensions.Logging;
  6. using Moq;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace JCSoft.WX.FrameworkTest.Api
  12. {
  13. public abstract class BaseApiTest<T>
  14. where T : ApiResponse
  15. {
  16. protected readonly IHttpFactory _factory;
  17. protected readonly ILogger _logger;
  18. protected readonly Mock<DefaultApiClient> _client;
  19. public BaseApiTest()
  20. {
  21. _factory = new HttpFactory();
  22. _logger = new Mock<ILogger>().Object;
  23. _client = new Mock<DefaultApiClient>(_logger, _factory);
  24. _client.Setup(api => api.DoExecute(Request)).Returns(new Task<string>(() => GetResponse()));
  25. }
  26. protected abstract ApiRequest<T> Request { get; }
  27. protected abstract string GetResponse();
  28. }
  29. }