test: 移除 HttpClient 扩展方法使用 Longbow.Web 组件方法

This commit is contained in:
Argo Zhang 2019-10-13 01:55:59 +08:00
parent d0b9ab62c9
commit 40a58144fd
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
26 changed files with 155 additions and 123 deletions

View File

@ -7,7 +7,7 @@
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="3.0.0-beta1" />
<PackageReference Include="Longbow" Version="3.0.0-beta6" />
<PackageReference Include="Longbow.Cache" Version="3.0.0-beta1" />
<PackageReference Include="Longbow.Cache" Version="3.0.0-beta2" />
<PackageReference Include="Longbow.Configuration" Version="3.0.0-beta1" />
<PackageReference Include="Longbow.Data" Version="3.0.0-beta1" />
<PackageReference Include="Longbow.GiteeAuth" Version="3.0.0-beta1" />
@ -16,7 +16,7 @@
<PackageReference Include="Longbow.PetaPoco" Version="1.0.2" />
<PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" />
<PackageReference Include="Longbow.Tasks" Version="3.0.0-beta2" />
<PackageReference Include="Longbow.Web" Version="3.0.0-beta5" />
<PackageReference Include="Longbow.Web" Version="3.0.0-beta6" />
<PackageReference Include="Longbow.WeChatAuth" Version="3.0.0-beta1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="3.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.7.0" />

View File

@ -7,10 +7,10 @@
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="3.0.0-beta1" />
<PackageReference Include="Longbow" Version="3.0.0-beta6" />
<PackageReference Include="Longbow.Cache" Version="3.0.0-beta1" />
<PackageReference Include="Longbow.Cache" Version="3.0.0-beta2" />
<PackageReference Include="Longbow.Configuration" Version="3.0.0-beta1" />
<PackageReference Include="Longbow.Data" Version="3.0.0-beta1" />
<PackageReference Include="Longbow.Web" Version="3.0.0-beta5" />
<PackageReference Include="Longbow.Web" Version="3.0.0-beta6" />
</ItemGroup>
</Project>

View File

@ -1,4 +1,5 @@
using Xunit;
using System.Net.Http;
using Xunit;
using static Bootstrap.Admin.Controllers.Api.AnalyseController;
namespace Bootstrap.Admin.Api

View File

@ -1,5 +1,6 @@
using Bootstrap.Admin.Controllers.Api;
using System;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;

View File

@ -1,6 +1,7 @@
using Bootstrap.DataAccess;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer

View File

@ -3,6 +3,7 @@ using Bootstrap.Security;
using Longbow.Web.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
@ -34,7 +35,7 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.True(ret);
var ids = DictHelper.RetrieveDicts().Where(d => d.Name == "UnitTest-Dict").Select(d => d.Id);
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>(ids));
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>("", ids));
}
}
}

View File

@ -3,6 +3,7 @@ using Longbow.Web.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Xunit;
using static Bootstrap.Admin.Controllers.Api.ExceptionsController;
@ -31,13 +32,13 @@ namespace Bootstrap.Admin.Api.SqlServer
[Fact]
public async void Post_Ok()
{
var files = await Client.PostAsJsonAsync<string, IEnumerable<string>>(string.Empty);
var files = await Client.PostAsJsonAsync<string, IEnumerable<string>>(string.Empty, "");
Assert.NotNull(files);
var fileName = files.FirstOrDefault();
if (!string.IsNullOrEmpty(fileName))
{
var resp = await Client.PutAsJsonAsync<ExceptionFileQuery, string>(new ExceptionFileQuery() { FileName = fileName });
var resp = await Client.PutAsJsonAsync<ExceptionFileQuery, string>("", new ExceptionFileQuery() { FileName = fileName });
Assert.NotNull(resp);
}

View File

@ -2,6 +2,7 @@
using Longbow.Web.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
@ -36,7 +37,7 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.True(ret);
var ids = GroupHelper.Retrieves().Where(d => d.GroupName == "UnitTest-Group").Select(d => d.Id);
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>(ids));
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>("", ids));
}
[Fact]

View File

@ -1,5 +1,6 @@
using Bootstrap.Security;
using System.Collections.Generic;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer

View File

@ -1,6 +1,7 @@
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using System;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer

View File

@ -3,6 +3,7 @@ using Bootstrap.Security;
using Longbow.Web.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
@ -35,7 +36,7 @@ namespace Bootstrap.Admin.Api.SqlServer
[Fact]
public async void PostAndDelete_Ok()
{
var ret = await Client.PostAsJsonAsync<BootstrapMenu, bool>(new BootstrapMenu() { Name = "UnitTest-Menu", Application = "0", Category = "0", ParentId = "0", Url = "#", Target = "_self", IsResource = 0 });
var ret = await Client.PostAsJsonAsync<BootstrapMenu, bool>("", new BootstrapMenu() { Name = "UnitTest-Menu", Application = "0", Category = "0", ParentId = "0", Url = "#", Target = "_self", IsResource = 0 });
Assert.True(ret);
var ids = MenuHelper.RetrieveAllMenus("Admin").Where(d => d.Name == "UnitTest-Menu").Select(d => d.Id);

View File

@ -1,6 +1,7 @@
using Bootstrap.Admin.Models;
using Bootstrap.DataAccess;
using System.Collections.Generic;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer

View File

@ -1,6 +1,7 @@
using Bootstrap.DataAccess;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
@ -29,7 +30,7 @@ namespace Bootstrap.Admin.Api.SqlServer
// Approve
nusr.UserStatus = UserStates.ApproveUser;
var resp = await Client.PutAsJsonAsync<User, bool>(nusr);
var resp = await Client.PutAsJsonAsync<User, bool>("", nusr);
Assert.True(resp);
// 删除新用户
@ -38,7 +39,7 @@ namespace Bootstrap.Admin.Api.SqlServer
// Reject
nusr = InsertNewUser();
nusr.UserStatus = UserStates.RejectUser;
resp = await Client.PutAsJsonAsync<User, bool>(nusr);
resp = await Client.PutAsJsonAsync<User, bool>("", nusr);
Assert.True(resp);
// 删除新用户

View File

@ -1,4 +1,5 @@
using Xunit;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
{

View File

@ -1,6 +1,7 @@
using Longbow.Web;
using System;
using System.Collections.Generic;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
@ -27,10 +28,10 @@ namespace Bootstrap.Admin.Api.SqlServer
public async void Put_Ok()
{
// 三次 Put 请求后返回真
var ret = await Client.PutAsJsonAsync<string, bool>("");
ret = await Client.PutAsJsonAsync<string, bool>("");
ret = await Client.PutAsJsonAsync<string, bool>("");
ret = await Client.PutAsJsonAsync<string, bool>("");
var ret = await Client.PutAsJsonAsync<string, bool>("", "");
ret = await Client.PutAsJsonAsync<string, bool>("", "");
ret = await Client.PutAsJsonAsync<string, bool>("", "");
ret = await Client.PutAsJsonAsync<string, bool>("", "");
Assert.True(ret);
}
}

View File

@ -19,7 +19,7 @@ namespace Bootstrap.Admin.Api.SqlServer
// change theme
usr.Css = "blue.css";
usr.UserStatus = UserStates.ChangeTheme;
var resp = await Client.PutAsJsonAsync<User, bool>(usr);
var resp = await Client.PutAsJsonAsync<User, bool>("", usr);
Assert.True(resp);
}
@ -31,7 +31,7 @@ namespace Bootstrap.Admin.Api.SqlServer
usr.UserStatus = UserStates.ChangePassword;
usr.NewPassword = "123789";
usr.Password = "123789";
var resp = await Client.PutAsJsonAsync<User, bool>(usr);
var resp = await Client.PutAsJsonAsync<User, bool>("", usr);
Assert.True(resp);
}
@ -42,7 +42,7 @@ namespace Bootstrap.Admin.Api.SqlServer
// change displayname
usr.UserStatus = UserStates.ChangeDisplayName;
usr.DisplayName = "Administrator";
var resp = await Client.PutAsJsonAsync<User, bool>(usr);
var resp = await Client.PutAsJsonAsync<User, bool>("", usr);
Assert.True(resp);
}
@ -53,7 +53,7 @@ namespace Bootstrap.Admin.Api.SqlServer
// change app
usr.App = "UnitTest";
usr.UserStatus = UserStates.SaveApp;
var resp = await Client.PutAsJsonAsync<User, bool>(usr);
var resp = await Client.PutAsJsonAsync<User, bool>("", usr);
Assert.True(resp);
}

View File

@ -1,5 +1,6 @@
using Bootstrap.DataAccess;
using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
@ -20,7 +21,7 @@ namespace Bootstrap.Admin.Api.SqlServer
{
// register new user
var nusr = new User() { UserName = "U_Register", DisplayName = "UnitTest", Password = "1", Description = "UnitTest" };
var resp = await Client.PostAsJsonAsync<User, bool>(nusr);
var resp = await Client.PostAsJsonAsync<User, bool>("", nusr);
Assert.True(resp);
UserHelper.Delete(nusr.RetrieveNewUsers().Where(u => u.UserName == nusr.UserName).Select(u => u.Id));
}
@ -29,7 +30,7 @@ namespace Bootstrap.Admin.Api.SqlServer
public async void Put_Ok()
{
var user = new ResetUser() { DisplayName = "UnitTest", UserName = "UnitTest", Reason = "UnitTest" };
var resp = await Client.PutAsJsonAsync<ResetUser, bool>(user);
var resp = await Client.PutAsJsonAsync<ResetUser, bool>("", user);
Assert.True(resp);
}
@ -41,7 +42,7 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.False(resp);
// 重置Admin密码
await Client.PutAsJsonAsync<ResetUser, bool>(new ResetUser { UserName = "Admin", DisplayName = "Administrator", Reason = "UnitTest" });
await Client.PutAsJsonAsync<ResetUser, bool>("", new ResetUser { UserName = "Admin", DisplayName = "Administrator", Reason = "UnitTest" });
resp = await Client.PutAsJsonAsync<User, bool>("Admin", new User() { Password = "123789" });
Assert.True(resp);
}

View File

@ -2,6 +2,7 @@
using Longbow.Web.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
@ -23,11 +24,11 @@ namespace Bootstrap.Admin.Api.SqlServer
[Fact]
public async void PostAndDelete_Ok()
{
var ret = await Client.PostAsJsonAsync<Role, bool>(new Role() { RoleName = "UnitTest-Role", Description = "UnitTest-Desc" });
var ret = await Client.PostAsJsonAsync<Role, bool>("", new Role() { RoleName = "UnitTest-Role", Description = "UnitTest-Desc" });
Assert.True(ret);
var ids = RoleHelper.Retrieves().Where(d => d.RoleName == "UnitTest-Role").Select(d => d.Id);
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>(ids));
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>("", ids));
}
[Fact]

View File

@ -1,5 +1,6 @@
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer

View File

@ -3,6 +3,7 @@ using Bootstrap.Security;
using Longbow.Cache;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
@ -29,7 +30,7 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.True(DictHelper.Save(new BootstrapDict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "0", Define = 0 }));
// 获得原来值
var resp = await Client.PostAsJsonAsync<BootstrapDict, bool>(new BootstrapDict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "UnitTest" });
var resp = await Client.PostAsJsonAsync<BootstrapDict, bool>("", new BootstrapDict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "UnitTest" });
Assert.True(resp);
var code = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "UnitTest-Settings").Code;

View File

@ -1,5 +1,6 @@
using Bootstrap.DataAccess;
using System.Collections.Generic;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer

View File

@ -2,6 +2,7 @@
using Longbow.Web;
using Longbow.Web.Mvc;
using System;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
@ -38,7 +39,7 @@ namespace Bootstrap.Admin.Api.SqlServer
OS = "UniTest",
UserAgent = "UniTest"
};
var result = await Client.PostAsJsonAsync<OnlineUser, bool>(onlineUser);
var result = await Client.PostAsJsonAsync<OnlineUser, bool>("", onlineUser);
Assert.True(result);
}
}

View File

@ -49,11 +49,11 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.True(resp);
nusr.Id = UserHelper.Retrieves().First(u => u.UserName == nusr.UserName).Id;
resp = await Client.PostAsJsonAsync<User, bool>(nusr);
resp = await Client.PostAsJsonAsync<User, bool>("", nusr);
Assert.True(resp);
var ids = UserHelper.Retrieves().Where(d => d.UserName == nusr.UserName).Select(d => d.Id);
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>(ids));
Assert.True(await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>("", ids));
}
[Fact]

View File

@ -11,102 +11,101 @@ namespace Bootstrap.Admin
/// </summary>
public static class HttpClientExtensions
{
/// <summary>
/// GetJson 异步方法
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="client"></param>
/// <param name="requestUri"></param>
/// <returns></returns>
public static async Task<T> GetAsJsonAsync<T>(this HttpClient client, string requestUri = null)
{
var resp = await client.GetAsync(requestUri);
var json = await resp.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<T>(json, new JsonSerializerOptions().AddDefaultConverters());
}
///// <summary>
///// GetJson 异步方法
///// </summary>
///// <typeparam name="T"></typeparam>
///// <param name="client"></param>
///// <param name="requestUri"></param>
///// <returns></returns>
//public static async Task<T> GetAsJsonAsync<T>(this HttpClient client, string requestUri = null)
//{
// var resp = await client.GetAsync(requestUri);
// var json = await resp.Content.ReadAsStringAsync();
// return JsonSerializer.Deserialize<T>(json, new JsonSerializerOptions().AddDefaultConverters());
//}
/// <summary>
/// PostJson 异步方法
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <typeparam name="TRet"></typeparam>
/// <param name="client"></param>
/// <param name="requestUri"></param>
/// <param name="t"></param>
/// <returns></returns>
public static async Task<TRet> PostAsJsonAsync<TValue, TRet>(this HttpClient client, string requestUri, TValue t)
{
var resp = await client.PostAsJsonAsync(requestUri, t);
var json = await resp.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().AddDefaultConverters());
}
///// <summary>
///// PostJson 异步方法
///// </summary>
///// <typeparam name="TValue"></typeparam>
///// <typeparam name="TRet"></typeparam>
///// <param name="client"></param>
///// <param name="requestUri"></param>
///// <param name="t"></param>
///// <returns></returns>
//public static async Task<TRet> PostAsJsonAsync<TValue, TRet>(this HttpClient client, string requestUri, TValue t)
//{
// var resp = await client.PostAsJsonAsync(requestUri, t);
// var json = await resp.Content.ReadAsStringAsync();
// return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().AddDefaultConverters());
//}
/// <summary>
/// PostJson 异步方法
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <typeparam name="TRet"></typeparam>
/// <param name="client"></param>
/// <param name="t"></param>
/// <returns></returns>
public static async Task<TRet> PostAsJsonAsync<TValue, TRet>(this HttpClient client, TValue t) => await PostAsJsonAsync<TValue, TRet>(client, string.Empty, t);
///// <summary>
///// PostJson 异步方法
///// </summary>
///// <typeparam name="TValue"></typeparam>
///// <typeparam name="TRet"></typeparam>
///// <param name="client"></param>
///// <param name="t"></param>
///// <returns></returns>
//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>
/// <param name="client"></param>
/// <param name="requestUri"></param>
/// <param name="t"></param>
/// <returns></returns>
public static async Task<TRet> DeleteAsJsonAsync<TValue, TRet>(this HttpClient client, string requestUri, TValue t)
{
var req = new HttpRequestMessage(HttpMethod.Delete, requestUri);
req.Content = new StringContent(JsonSerializer.Serialize(t));
req.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
///// <summary>
///// DeleteJson 异步方法
///// </summary>
///// <typeparam name="TValue"></typeparam>
///// <typeparam name="TRet"></typeparam>
///// <param name="client"></param>
///// <param name="requestUri"></param>
///// <param name="t"></param>
///// <returns></returns>
//public static async Task<TRet> DeleteAsJsonAsync<TValue, TRet>(this HttpClient client, string requestUri, TValue t)
//{
// var req = new HttpRequestMessage(HttpMethod.Delete, requestUri);
// req.Content = new StringContent(JsonSerializer.Serialize(t));
// req.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var resp = await client.SendAsync(req);
var json = await resp.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().AddDefaultConverters());
}
// var resp = await client.SendAsync(req);
// var json = await resp.Content.ReadAsStringAsync();
// return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().AddDefaultConverters());
//}
/// <summary>
/// DeleteJson 异步方法
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <typeparam name="TRet"></typeparam>
/// <param name="client"></param>
/// <param name="t"></param>
/// <returns></returns>
public static async Task<TRet> DeleteAsJsonAsync<TValue, TRet>(this HttpClient client, TValue t) => await DeleteAsJsonAsync<TValue, TRet>(client, string.Empty, t);
///// <summary>
///// DeleteJson 异步方法
///// </summary>
///// <typeparam name="TValue"></typeparam>
///// <typeparam name="TRet"></typeparam>
///// <param name="client"></param>
///// <param name="t"></param>
///// <returns></returns>
//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>
/// <param name="client"></param>
/// <param name="requestUri"></param>
/// <param name="t"></param>
/// <returns></returns>
public static async Task<TRet> PutAsJsonAsync<TValue, TRet>(this HttpClient client, string requestUri, TValue t)
{
var resp = await client.PutAsJsonAsync(requestUri, t);
var json = await resp.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().AddDefaultConverters());
}
/// <summary>
/// PutJson 异步方法
/// </summary>
/// <typeparam name="TValue"></typeparam>
/// <typeparam name="TRet"></typeparam>
/// <param name="client"></param>
/// <param name="t"></param>
/// <returns></returns>
public static async Task<TRet> PutAsJsonAsync<TValue, TRet>(this HttpClient client, TValue t) => await PutAsJsonAsync<TValue, TRet>(client, string.Empty, t);
///// <summary>
///// PutJson 异步方法
///// </summary>
///// <typeparam name="TValue"></typeparam>
///// <typeparam name="TRet"></typeparam>
///// <param name="client"></param>
///// <param name="requestUri"></param>
///// <param name="t"></param>
///// <returns></returns>
//public static async Task<TRet> PutAsJsonAsync<TValue, TRet>(this HttpClient client, string requestUri, TValue t)
//{
// var resp = await client.PutAsJsonAsync(requestUri, t);
// var json = await resp.Content.ReadAsStringAsync();
// return JsonSerializer.Deserialize<TRet>(json, new JsonSerializerOptions().AddDefaultConverters());
//}
///// <summary>
///// PutJson 异步方法
///// </summary>
///// <typeparam name="TValue"></typeparam>
///// <typeparam name="TRet"></typeparam>
///// <param name="client"></param>
///// <param name="t"></param>
///// <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 异步方法

View File

@ -1,7 +1,10 @@
using Bootstrap.Security;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using Xunit;
namespace Bootstrap.DataAccess.SqlServer
@ -146,6 +149,16 @@ namespace Bootstrap.DataAccess.SqlServer
Assert.NotNull(ipUri);
}
[Fact]
public void Test()
{
var payload = "{\"status\":1,\"message\":\"Internal Service Error: ip[207.148.111.94] loc failed\"}";
var options = new JsonSerializerOptions().AddDefaultConverters();
var state = JsonSerializer.Deserialize<BaiDuIPLocator>(payload, options);
Assert.Equal(1, state.Status);
}
[Fact]
public async void BaiduIPSvr_Ok()
{
@ -155,11 +168,11 @@ namespace Bootstrap.DataAccess.SqlServer
{
// 日本东京
var locator = await client.GetAsJsonAsync<BaiDuIPLocator>($"{ipUri}207.148.111.94");
Assert.NotEqual("0", locator.Status);
Assert.NotEqual(0, locator.Status);
// 四川成都
locator = await client.GetAsJsonAsync<BaiDuIPLocator>($"{ipUri}182.148.123.196");
Assert.Equal("0", locator.Status);
Assert.Equal(0, locator.Status);
}
}
@ -206,7 +219,7 @@ namespace Bootstrap.DataAccess.SqlServer
/// <summary>
/// 结果状态返回码
/// </summary>
public string Status { get; set; }
public int Status { get; set; }
/// <summary>
///
@ -214,7 +227,7 @@ namespace Bootstrap.DataAccess.SqlServer
/// <returns></returns>
public override string ToString()
{
return Status == "0" ? string.Join(" ", Address.SpanSplit("|").Skip(1).Take(2)) : "XX XX";
return Status == 0 ? string.Join(" ", Address.SpanSplit("|").Skip(1).Take(2)) : "XX XX";
}
}