using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Util.Http; namespace Util.Tests.Infrastructure; /// /// 控制器测试基类 /// public abstract class ControllerTestBase { /// /// 测试初始化 /// protected ControllerTestBase( IHttpClient client, IHttpContextAccessor accessor = null ) { Client = client; if ( accessor != null ) Context = accessor.HttpContext; } /// /// Http客户端 /// protected IHttpClient Client { get; } /// /// Http上下文 /// protected HttpContext Context { get; } /// /// Http Get操作 /// /// 服务地址 /// 参数 protected async Task> GetAsync( string url, object data = null ) { return await Client.Get>( url, data ).GetResultAsync(); } /// /// Http Get操作 /// /// 返回结果类型 /// 服务地址 /// 参数 protected async Task> GetAsync( string url, object data = null ) { return await Client.Get>( url,data ).GetResultAsync(); } /// /// Http Post操作 /// /// 服务地址 /// 参数 protected async Task> PostAsync( string url, object data ) { return await PostAsync( url, data ); } /// /// Http Post操作 /// /// 返回结果类型 /// 服务地址 /// 参数 protected async Task> PostAsync( string url, object data ) { return await Client.Post>( url, data ).GetResultAsync(); } /// /// Http Put操作 /// /// 服务地址 /// 参数 protected async Task> PutAsync( string url, object data ) { return await PutAsync( url, data ); } /// /// Http Put操作 /// /// 返回结果类型 /// 服务地址 /// 参数 protected async Task> PutAsync( string url, object data ) { return await Client.Put>( url, data ).GetResultAsync(); } /// /// Http Delete操作 /// /// 服务地址 protected async Task> DeleteAsync( string url ) { return await DeleteAsync( url ); } /// /// Http Delete操作 /// /// 返回结果类型 /// 服务地址 protected async Task> DeleteAsync( string url ) { return await Client.Delete>( url ).GetResultAsync(); } }