You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB
C#

8 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
8 months ago
namespace HttpClientStudy.UnitTest.HttpClients
8 months ago
{
public class PipelineClientTest
{
8 months ago
private readonly ITestOutputHelper _logger;
8 months ago
8 months ago
public PipelineClientTest(ITestOutputHelper outputHelper)
{
_logger = outputHelper;
}
/// <summary>
/// 手动处理
/// </summary>
8 months ago
[Fact]
8 months ago
public async Task Delegating_Test()
8 months ago
{
8 months ago
//构建管道
var handler = new HandlerA()
{
//相当于下一个中间件(管道)
InnerHandler = new HandlerB()
};
8 months ago
8 months ago
//构造中传入管道对象
HttpClient httpClient = new HttpClient(handler);
8 months ago
var sd = await httpClient.GetAsync(WebApiConfigManager.GetWebApiConfig().BaseUrl + "/api/health");
8 months ago
var contentText = await sd.Content.ReadAsStringAsync();
8 months ago
8 months ago
_logger.WriteLine(contentText);
}
[Fact]
public async Task CreateHttpClient_Test()
{
HttpClient client = new PipelineHttpClient().CreateHttpClient();
8 months ago
8 months ago
var r = await client.GetAsync(WebApiConfigManager.GetWebApiConfig().BaseUrl + "/api/health");
8 months ago
r.EnsureSuccessStatusCode();
8 months ago
}
}
}