diff --git a/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 041a9a6e..51aa25c4 100644 --- a/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -7,7 +7,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/src/client/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj b/src/client/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj index 39072197..85fa4786 100644 --- a/src/client/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj +++ b/src/client/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj @@ -7,10 +7,10 @@ - + - + diff --git a/test/UnitTest/Bootstrap.Admin/Api/AnalyseTest.cs b/test/UnitTest/Bootstrap.Admin/Api/AnalyseTest.cs index 9738b16a..961e03d1 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/AnalyseTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/AnalyseTest.cs @@ -1,4 +1,5 @@ -using Xunit; +using System.Net.Http; +using Xunit; using static Bootstrap.Admin.Controllers.Api.AnalyseController; namespace Bootstrap.Admin.Api diff --git a/test/UnitTest/Bootstrap.Admin/Api/GiteeTest.cs b/test/UnitTest/Bootstrap.Admin/Api/GiteeTest.cs index 3aab9279..21366d90 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/GiteeTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/GiteeTest.cs @@ -1,5 +1,6 @@ using Bootstrap.Admin.Controllers.Api; using System; +using System.Net.Http; using System.Reflection; using System.Threading.Tasks; using Xunit; diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/AppsTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/AppsTest.cs index 5d1e98ad..3406bdc5 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/AppsTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/AppsTest.cs @@ -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 diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/CategoryTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/CategoryTest.cs index 8b3fe4b0..66644500 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/CategoryTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/CategoryTest.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Net.Http; using Xunit; namespace Bootstrap.Admin.Api.SqlServer diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/DictTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/DictTest.cs index eabee8d6..e7b39cdb 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/DictTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/DictTest.cs @@ -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, bool>(ids)); + Assert.True(await Client.DeleteAsJsonAsync, bool>("", ids)); } } } diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/ExceptionsTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/ExceptionsTest.cs index c400adfc..44137c01 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/ExceptionsTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/ExceptionsTest.cs @@ -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.Empty); + var files = await Client.PostAsJsonAsync>(string.Empty, ""); Assert.NotNull(files); var fileName = files.FirstOrDefault(); if (!string.IsNullOrEmpty(fileName)) { - var resp = await Client.PutAsJsonAsync(new ExceptionFileQuery() { FileName = fileName }); + var resp = await Client.PutAsJsonAsync("", new ExceptionFileQuery() { FileName = fileName }); Assert.NotNull(resp); } diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/GroupsTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/GroupsTest.cs index eb81e1ef..77a095fd 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/GroupsTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/GroupsTest.cs @@ -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, bool>(ids)); + Assert.True(await Client.DeleteAsJsonAsync, bool>("", ids)); } [Fact] diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/InterfaceTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/InterfaceTest.cs index 7bcdf1e3..9b3c696b 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/InterfaceTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/InterfaceTest.cs @@ -1,5 +1,6 @@ using Bootstrap.Security; using System.Collections.Generic; +using System.Net.Http; using Xunit; namespace Bootstrap.Admin.Api.SqlServer diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/LogsTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/LogsTest.cs index 2a61d533..03079b3b 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/LogsTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/LogsTest.cs @@ -1,6 +1,7 @@ using Bootstrap.DataAccess; using Longbow.Web.Mvc; using System; +using System.Net.Http; using Xunit; namespace Bootstrap.Admin.Api.SqlServer diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/MenusTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/MenusTest.cs index 5579ef8e..b3a947a5 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/MenusTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/MenusTest.cs @@ -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(new BootstrapMenu() { Name = "UnitTest-Menu", Application = "0", Category = "0", ParentId = "0", Url = "#", Target = "_self", IsResource = 0 }); + var ret = await Client.PostAsJsonAsync("", 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); diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/MessagesTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/MessagesTest.cs index 32a03214..7a7904df 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/MessagesTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/MessagesTest.cs @@ -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 diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/NewTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/NewTest.cs index bde47d4c..31fe4d4e 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/NewTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/NewTest.cs @@ -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(nusr); + var resp = await Client.PutAsJsonAsync("", nusr); Assert.True(resp); // 删除新用户 @@ -38,7 +39,7 @@ namespace Bootstrap.Admin.Api.SqlServer // Reject nusr = InsertNewUser(); nusr.UserStatus = UserStates.RejectUser; - resp = await Client.PutAsJsonAsync(nusr); + resp = await Client.PutAsJsonAsync("", nusr); Assert.True(resp); // 删除新用户 diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/NotificationsTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/NotificationsTest.cs index 4c19f55e..aaa1c67d 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/NotificationsTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/NotificationsTest.cs @@ -1,4 +1,5 @@ -using Xunit; +using System.Net.Http; +using Xunit; namespace Bootstrap.Admin.Api.SqlServer { diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/OnlineTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/OnlineTest.cs index b1faacdf..5bdbdb77 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/OnlineTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/OnlineTest.cs @@ -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(""); - ret = await Client.PutAsJsonAsync(""); - ret = await Client.PutAsJsonAsync(""); - ret = await Client.PutAsJsonAsync(""); + var ret = await Client.PutAsJsonAsync("", ""); + ret = await Client.PutAsJsonAsync("", ""); + ret = await Client.PutAsJsonAsync("", ""); + ret = await Client.PutAsJsonAsync("", ""); Assert.True(ret); } } diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/ProfilesTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/ProfilesTest.cs index 052294b8..210592a1 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/ProfilesTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/ProfilesTest.cs @@ -19,7 +19,7 @@ namespace Bootstrap.Admin.Api.SqlServer // change theme usr.Css = "blue.css"; usr.UserStatus = UserStates.ChangeTheme; - var resp = await Client.PutAsJsonAsync(usr); + var resp = await Client.PutAsJsonAsync("", 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(usr); + var resp = await Client.PutAsJsonAsync("", 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(usr); + var resp = await Client.PutAsJsonAsync("", 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(usr); + var resp = await Client.PutAsJsonAsync("", usr); Assert.True(resp); } diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/RegisterTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/RegisterTest.cs index d246b4bd..c14bf310 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/RegisterTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/RegisterTest.cs @@ -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(nusr); + var resp = await Client.PostAsJsonAsync("", 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(user); + var resp = await Client.PutAsJsonAsync("", user); Assert.True(resp); } @@ -41,7 +42,7 @@ namespace Bootstrap.Admin.Api.SqlServer Assert.False(resp); // 重置Admin密码 - await Client.PutAsJsonAsync(new ResetUser { UserName = "Admin", DisplayName = "Administrator", Reason = "UnitTest" }); + await Client.PutAsJsonAsync("", new ResetUser { UserName = "Admin", DisplayName = "Administrator", Reason = "UnitTest" }); resp = await Client.PutAsJsonAsync("Admin", new User() { Password = "123789" }); Assert.True(resp); } diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/RolesTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/RolesTest.cs index 6f3bf1db..0b7566b0 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/RolesTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/RolesTest.cs @@ -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(new Role() { RoleName = "UnitTest-Role", Description = "UnitTest-Desc" }); + var ret = await Client.PostAsJsonAsync("", 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, bool>(ids)); + Assert.True(await Client.DeleteAsJsonAsync, bool>("", ids)); } [Fact] diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/SQLTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/SQLTest.cs index 377a9996..c865ffcf 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/SQLTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/SQLTest.cs @@ -1,5 +1,6 @@ using Bootstrap.DataAccess; using Longbow.Web.Mvc; +using System.Net.Http; using Xunit; namespace Bootstrap.Admin.Api.SqlServer diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/SettingsTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/SettingsTest.cs index 6379736d..21367299 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/SettingsTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/SettingsTest.cs @@ -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(new BootstrapDict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "UnitTest" }); + var resp = await Client.PostAsJsonAsync("", new BootstrapDict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "UnitTest" }); Assert.True(resp); var code = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "UnitTest-Settings").Code; diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/TasksTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/TasksTest.cs index f7c828f4..f5e1a2c6 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/TasksTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/TasksTest.cs @@ -1,5 +1,6 @@ using Bootstrap.DataAccess; using System.Collections.Generic; +using System.Net.Http; using Xunit; namespace Bootstrap.Admin.Api.SqlServer diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/TracesTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/TracesTest.cs index 7d23f39e..c7eaed47 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/TracesTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/TracesTest.cs @@ -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); + var result = await Client.PostAsJsonAsync("", onlineUser); Assert.True(result); } } diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/UsersTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/UsersTest.cs index 41353e74..11cd360f 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/UsersTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/UsersTest.cs @@ -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(nusr); + resp = await Client.PostAsJsonAsync("", nusr); Assert.True(resp); var ids = UserHelper.Retrieves().Where(d => d.UserName == nusr.UserName).Select(d => d.Id); - Assert.True(await Client.DeleteAsJsonAsync, bool>(ids)); + Assert.True(await Client.DeleteAsJsonAsync, bool>("", ids)); } [Fact] diff --git a/test/UnitTest/Bootstrap.Admin/HttpClientExtensions.cs b/test/UnitTest/Bootstrap.Admin/HttpClientExtensions.cs index 46d61c8a..20064f71 100644 --- a/test/UnitTest/Bootstrap.Admin/HttpClientExtensions.cs +++ b/test/UnitTest/Bootstrap.Admin/HttpClientExtensions.cs @@ -11,102 +11,101 @@ namespace Bootstrap.Admin /// public static class HttpClientExtensions { - /// - /// GetJson 异步方法 - /// - /// - /// - /// - /// - public static async Task GetAsJsonAsync(this HttpClient client, string requestUri = null) - { - var resp = await client.GetAsync(requestUri); - var json = await resp.Content.ReadAsStringAsync(); - return JsonSerializer.Deserialize(json, new JsonSerializerOptions().AddDefaultConverters()); - } + ///// + ///// GetJson 异步方法 + ///// + ///// + ///// + ///// + ///// + //public static async Task GetAsJsonAsync(this HttpClient client, string requestUri = null) + //{ + // var resp = await client.GetAsync(requestUri); + // var json = await resp.Content.ReadAsStringAsync(); + // return JsonSerializer.Deserialize(json, new JsonSerializerOptions().AddDefaultConverters()); + //} - /// - /// PostJson 异步方法 - /// - /// - /// - /// - /// - /// - /// - public static async Task PostAsJsonAsync(this HttpClient client, string requestUri, TValue t) - { - var resp = await client.PostAsJsonAsync(requestUri, t); - var json = await resp.Content.ReadAsStringAsync(); - return JsonSerializer.Deserialize(json, new JsonSerializerOptions().AddDefaultConverters()); - } + ///// + ///// PostJson 异步方法 + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static async Task PostAsJsonAsync(this HttpClient client, string requestUri, TValue t) + //{ + // var resp = await client.PostAsJsonAsync(requestUri, t); + // var json = await resp.Content.ReadAsStringAsync(); + // return JsonSerializer.Deserialize(json, new JsonSerializerOptions().AddDefaultConverters()); + //} - /// - /// PostJson 异步方法 - /// - /// - /// - /// - /// - /// - public static async Task PostAsJsonAsync(this HttpClient client, TValue t) => await PostAsJsonAsync(client, string.Empty, t); + ///// + ///// PostJson 异步方法 + ///// + ///// + ///// + ///// + ///// + ///// + //public static async Task PostAsJsonAsync(this HttpClient client, TValue t) => await PostAsJsonAsync(client, string.Empty, t); - /// - /// DeleteJson 异步方法 - /// - /// - /// - /// - /// - /// - /// - public static async Task DeleteAsJsonAsync(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"); + ///// + ///// DeleteJson 异步方法 + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static async Task DeleteAsJsonAsync(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(json, new JsonSerializerOptions().AddDefaultConverters()); - } + // var resp = await client.SendAsync(req); + // var json = await resp.Content.ReadAsStringAsync(); + // return JsonSerializer.Deserialize(json, new JsonSerializerOptions().AddDefaultConverters()); + //} - /// - /// DeleteJson 异步方法 - /// - /// - /// - /// - /// - /// - public static async Task DeleteAsJsonAsync(this HttpClient client, TValue t) => await DeleteAsJsonAsync(client, string.Empty, t); + ///// + ///// DeleteJson 异步方法 + ///// + ///// + ///// + ///// + ///// + ///// + //public static async Task DeleteAsJsonAsync(this HttpClient client, TValue t) => await DeleteAsJsonAsync(client, string.Empty, t); - /// - /// PutJson 异步方法 - /// - /// - /// - /// - /// - /// - /// - public static async Task PutAsJsonAsync(this HttpClient client, string requestUri, TValue t) - { - var resp = await client.PutAsJsonAsync(requestUri, t); - var json = await resp.Content.ReadAsStringAsync(); - return JsonSerializer.Deserialize(json, new JsonSerializerOptions().AddDefaultConverters()); - } - - /// - /// PutJson 异步方法 - /// - /// - /// - /// - /// - /// - public static async Task PutAsJsonAsync(this HttpClient client, TValue t) => await PutAsJsonAsync(client, string.Empty, t); + ///// + ///// PutJson 异步方法 + ///// + ///// + ///// + ///// + ///// + ///// + ///// + //public static async Task PutAsJsonAsync(this HttpClient client, string requestUri, TValue t) + //{ + // var resp = await client.PutAsJsonAsync(requestUri, t); + // var json = await resp.Content.ReadAsStringAsync(); + // return JsonSerializer.Deserialize(json, new JsonSerializerOptions().AddDefaultConverters()); + //} + ///// + ///// PutJson 异步方法 + ///// + ///// + ///// + ///// + ///// + ///// + //public static async Task PutAsJsonAsync(this HttpClient client, TValue t) => await PutAsJsonAsync(client, string.Empty, t); /// /// LoginAsync 异步方法 diff --git a/test/UnitTest/Bootstrap.DataAccess/SQLServer/DictsTest.cs b/test/UnitTest/Bootstrap.DataAccess/SQLServer/DictsTest.cs index 5b60372c..1c8d66bb 100644 --- a/test/UnitTest/Bootstrap.DataAccess/SQLServer/DictsTest.cs +++ b/test/UnitTest/Bootstrap.DataAccess/SQLServer/DictsTest.cs @@ -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(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($"{ipUri}207.148.111.94"); - Assert.NotEqual("0", locator.Status); + Assert.NotEqual(0, locator.Status); // 四川成都 locator = await client.GetAsJsonAsync($"{ipUri}182.148.123.196"); - Assert.Equal("0", locator.Status); + Assert.Equal(0, locator.Status); } } @@ -206,7 +219,7 @@ namespace Bootstrap.DataAccess.SqlServer /// /// 结果状态返回码 /// - public string Status { get; set; } + public int Status { get; set; } /// /// @@ -214,7 +227,7 @@ namespace Bootstrap.DataAccess.SqlServer /// 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"; } }