|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace HttpClientStudy.UnitTest
|
|
|
|
|
{
|
|
|
|
|
public class DelegatingHandlerTest
|
|
|
|
|
{
|
|
|
|
|
private readonly ITestOutputHelper _logger;
|
|
|
|
|
public DelegatingHandlerTest(ITestOutputHelper outputHelper)
|
|
|
|
|
{
|
|
|
|
|
_logger = outputHelper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Test()
|
|
|
|
|
{
|
|
|
|
|
//构建管道
|
|
|
|
|
var handler = new HandlerA()
|
|
|
|
|
{
|
|
|
|
|
//相当于下一个中间件(管道)
|
|
|
|
|
InnerHandler = new HandlerB()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HttpClient httpClient = new HttpClient(handler);
|
|
|
|
|
|
|
|
|
|
var sd = await httpClient.GetAsync(TestConfig.WebApiBaseUrl + "/api/");
|
|
|
|
|
var contentText = await sd.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
|
|
_logger.WriteLine(contentText);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|