test: 根据 Longbow 最新组件更新 Configure 方法

#Issue
link #I12XTD
This commit is contained in:
Argo Zhang 2019-10-03 19:07:56 +08:00
parent 0992abc556
commit 1f4cad6cd6
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
1 changed files with 22 additions and 11 deletions

View File

@ -6,10 +6,13 @@ using System.Threading.Tasks;
namespace Bootstrap.Admin
{
/// <summary>
/// HttpClient 扩展操作类
/// </summary>
public static class HttpClientExtensions
{
/// <summary>
///
/// GetJson 异步方法
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="client"></param>
@ -19,11 +22,11 @@ namespace Bootstrap.Admin
{
var resp = await client.GetAsync(requestUri);
var json = await resp.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<T>(json, new JsonSerializerOptions().Configure());
return JsonSerializer.Deserialize<T>(json, new JsonSerializerOptions().AddDefaultConverters());
}
/// <summary>
///
/// PostJson 异步方法
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <typeparam name="TRet"></typeparam>
@ -35,11 +38,11 @@ namespace Bootstrap.Admin
{
var resp = await client.PostAsJsonAsync(requestUri, t);
var json = await resp.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().Configure());
return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().AddDefaultConverters());
}
/// <summary>
///
/// PostJson 异步方法
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <typeparam name="TRet"></typeparam>
@ -49,7 +52,7 @@ namespace Bootstrap.Admin
public static async Task<TRet> PostAsJsonAsync<TValue, TRet>(this HttpClient client, TValue t) => await PostAsJsonAsync<TValue, TRet>(client, string.Empty, t);
/// <summary>
///
/// DeleteJson 异步方法
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <typeparam name="TRet"></typeparam>
@ -65,11 +68,11 @@ namespace Bootstrap.Admin
var resp = await client.SendAsync(req);
var json = await resp.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().Configure());
return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().AddDefaultConverters());
}
/// <summary>
///
/// DeleteJson 异步方法
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <typeparam name="TRet"></typeparam>
@ -79,7 +82,7 @@ namespace Bootstrap.Admin
public static async Task<TRet> DeleteAsJsonAsync<TValue, TRet>(this HttpClient client, TValue t) => await DeleteAsJsonAsync<TValue, TRet>(client, string.Empty, t);
/// <summary>
///
/// PutJson 异步方法
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <typeparam name="TRet"></typeparam>
@ -91,11 +94,11 @@ namespace Bootstrap.Admin
{
var resp = await client.PutAsJsonAsync(requestUri, t);
var json = await resp.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().Configure());
return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().AddDefaultConverters());
}
/// <summary>
///
/// PutJson 异步方法
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <typeparam name="TRet"></typeparam>
@ -104,6 +107,14 @@ namespace Bootstrap.Admin
/// <returns></returns>
public static async Task<TRet> PutAsJsonAsync<TValue, TRet>(this HttpClient client, TValue t) => await PutAsJsonAsync<TValue, TRet>(client, string.Empty, t);
/// <summary>
/// LoginAsync 异步方法
/// </summary>
/// <param name="client"></param>
/// <param name="userName"></param>
/// <param name="password"></param>
/// <returns></returns>
public static async Task LoginAsync(this HttpClient client, string userName = "Admin", string password = "123789")
{
var r = await client.GetAsync("/Account/Login");