HttpFactoryTest.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using JCSoft.Core.Net.Http;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Xunit;
  6. namespace JCSoft.WX.FrameworkTest.HttpClient
  7. {
  8. public class HttpFactoryTest
  9. {
  10. public HttpFactoryTest()
  11. {
  12. // _factory = new HttpFactory();
  13. }
  14. [Fact]
  15. public async System.Threading.Tasks.Task CreateHttpActionTestAsync()
  16. {
  17. var options = new HttpOptions();
  18. options.AddFileExtAsContentType(".txt", "is txt file");
  19. var factory = new HttpFactory(options);
  20. var httpGet = factory.CreateHttp(HttpRequestActionType.Get)
  21. .Setup()
  22. .SetUrl("http://www.baidu.com");
  23. var response = await httpGet.GetResponseAsync();
  24. Assert.NotEmpty(response);
  25. }
  26. [Fact]
  27. public void CreateNotSupportActionTest()
  28. {
  29. var factory = new HttpFactory();
  30. Assert.Throws(typeof(ArgumentOutOfRangeException), () =>
  31. {
  32. factory.CreateHttp(HttpRequestActionType.None)
  33. .Setup()
  34. .SetUrl("http://localhost")
  35. .SetContent("");
  36. });
  37. }
  38. }
  39. }