From c4da4cc9dccca540a250f5987fef31d11576471c Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Sun, 25 Jul 2021 22:22:12 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bootstrap.Admin/Api/ExceptionsTest.cs | 6 ++-- .../UnitTest/Bootstrap.Admin/Api/GiteeTest.cs | 28 ------------------- .../Bootstrap.Admin/Api/InterfaceTest.cs | 5 ++-- .../UnitTest/Bootstrap.Admin/Api/LoginTest.cs | 4 ++- test/UnitTest/Bootstrap.Admin/Api/LogsTest.cs | 3 +- .../Bootstrap.Admin/Api/OnlineTest.cs | 3 +- .../UnitTest/Bootstrap.Admin/Api/TasksTest.cs | 3 +- .../Bootstrap.Admin/Api/TracesTest.cs | 4 +-- 8 files changed, 17 insertions(+), 39 deletions(-) diff --git a/test/UnitTest/Bootstrap.Admin/Api/ExceptionsTest.cs b/test/UnitTest/Bootstrap.Admin/Api/ExceptionsTest.cs index f9b04f7d..f42efd94 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/ExceptionsTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/ExceptionsTest.cs @@ -1,10 +1,11 @@ using Bootstrap.DataAccess; using Longbow.Web.Mvc; +using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Linq; -using System.Net.Http; using System.Net.Http.Json; +using System.Text.Json; using Xunit; using static Bootstrap.Admin.Controllers.Api.ExceptionsController; @@ -23,7 +24,8 @@ namespace Bootstrap.Admin.Api // 菜单 系统菜单 系统使用条件 var query = "?sort=LogTime&order=desc&offset=0&limit=20&StartTime=&EndTime=&_=1547610349796"; - var qd = await Client.GetFromJsonAsync>(query); + var option = new JsonSerializerOptions().AddDefaultConverters(); + var qd = await Client.GetFromJsonAsync>(query, option); Assert.NotEmpty(qd.rows); // clean diff --git a/test/UnitTest/Bootstrap.Admin/Api/GiteeTest.cs b/test/UnitTest/Bootstrap.Admin/Api/GiteeTest.cs index ffacca05..13c10166 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/GiteeTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/GiteeTest.cs @@ -39,33 +39,5 @@ namespace Bootstrap.Admin.Api var cates = await Client.GetFromJsonAsync("Builds"); Assert.NotNull(cates); } - - [Fact] - public void GetJsonAsync_Exception() - { - var t = typeof(GiteeController).GetMethod("GetJsonAsync", BindingFlags.NonPublic | BindingFlags.Static); - t = t.MakeGenericMethod(new Type[] { typeof(string) }); - - t.Invoke(null, new object[] { - "", - new Func>(url => - { - throw new TaskCanceledException(); - }), - new Func(content => { - return ""; - }) - }); - - t.Invoke(null, new object[] { - "", - new Func>(url => { - throw new Exception(); - }), - new Func(content => { - return ""; - }) - }); - } } } diff --git a/test/UnitTest/Bootstrap.Admin/Api/InterfaceTest.cs b/test/UnitTest/Bootstrap.Admin/Api/InterfaceTest.cs index 8cfe2211..9d7e3f5b 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/InterfaceTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/InterfaceTest.cs @@ -1,7 +1,9 @@ using Bootstrap.Security; +using Microsoft.Extensions.DependencyInjection; using System.Collections.Generic; using System.Net.Http; using System.Net.Http.Json; +using System.Text.Json; using Xunit; namespace Bootstrap.Admin.Api @@ -54,8 +56,7 @@ namespace Bootstrap.Admin.Api public async void Healths_Ok() { var req = await Client.PostAsJsonAsync("Healths", "UnitTest"); - var ret = await req.Content.ReadFromJsonAsync(); - Assert.False(ret); + Assert.False(req.IsSuccessStatusCode); } } } diff --git a/test/UnitTest/Bootstrap.Admin/Api/LoginTest.cs b/test/UnitTest/Bootstrap.Admin/Api/LoginTest.cs index f3b3a953..abac3036 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/LoginTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/LoginTest.cs @@ -1,8 +1,10 @@ using Bootstrap.DataAccess; using Longbow.Web.Mvc; using Longbow.Web.SMS; +using Microsoft.Extensions.DependencyInjection; using System.Net.Http; using System.Net.Http.Json; +using System.Text.Json; using Xunit; namespace Bootstrap.Admin.Api @@ -14,7 +16,7 @@ namespace Bootstrap.Admin.Api [Fact] public async void Login_Get() { - var users = await Client.GetFromJsonAsync>("?sort=LoginTime&order=&offset=0&limit=20&startTime=&endTime=&loginIp=&_=1560933256621"); + var users = await Client.GetFromJsonAsync>("?sort=LoginTime&order=&offset=0&limit=20&startTime=&endTime=&loginIp=&_=1560933256621", new JsonSerializerOptions().AddDefaultConverters()); Assert.NotEmpty(users.rows); } diff --git a/test/UnitTest/Bootstrap.Admin/Api/LogsTest.cs b/test/UnitTest/Bootstrap.Admin/Api/LogsTest.cs index 9a93992c..3a969a52 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/LogsTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/LogsTest.cs @@ -1,5 +1,6 @@ using Bootstrap.DataAccess; using Longbow.Web.Mvc; +using Microsoft.Extensions.DependencyInjection; using System; using System.Net.Http; using System.Net.Http.Json; @@ -19,7 +20,7 @@ namespace Bootstrap.Admin.Api // 菜单 系统菜单 系统使用条件 var query = "?sort=LogTime&order=desc&offset=0&limit=20&operateType=&OperateTimeStart=&OperateTimeEnd=&_=1547617573596"; - var qd = await Client.GetFromJsonAsync>(query); + var qd = await Client.GetFromJsonAsync>(query, new System.Text.Json.JsonSerializerOptions().AddDefaultConverters()); Assert.NotEmpty(qd.rows); // clean diff --git a/test/UnitTest/Bootstrap.Admin/Api/OnlineTest.cs b/test/UnitTest/Bootstrap.Admin/Api/OnlineTest.cs index d3d49033..31bfbcad 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/OnlineTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/OnlineTest.cs @@ -1,4 +1,5 @@ using Longbow.Web; +using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Net.Http.Json; @@ -13,7 +14,7 @@ namespace Bootstrap.Admin.Api [Fact] public async void Get_Ok() { - var users = await Client.GetFromJsonAsync>(""); + var users = await Client.GetFromJsonAsync>("", new System.Text.Json.JsonSerializerOptions().AddDefaultConverters()); Assert.Single(users); } diff --git a/test/UnitTest/Bootstrap.Admin/Api/TasksTest.cs b/test/UnitTest/Bootstrap.Admin/Api/TasksTest.cs index ce3ca526..07cc8f5f 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/TasksTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/TasksTest.cs @@ -51,8 +51,7 @@ namespace Bootstrap.Admin.Api widget.CronExpression = Longbow.Tasks.Cron.Secondly(5); widget.TaskExecutorName = "UnitTest-Widget"; resp = await Client.PostAsJsonAsync("/api/Tasks", widget); - ret = await resp.Content.ReadFromJsonAsync(); - Assert.False(ret); + Assert.False(resp.IsSuccessStatusCode); widget.TaskExecutorName = "Bootstrap.Admin.DefaultTaskExecutor"; widget.Name = "UnitTest-Task"; diff --git a/test/UnitTest/Bootstrap.Admin/Api/TracesTest.cs b/test/UnitTest/Bootstrap.Admin/Api/TracesTest.cs index 07479c0f..79ee4107 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/TracesTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/TracesTest.cs @@ -1,8 +1,8 @@ using Bootstrap.DataAccess; using Longbow.Web; using Longbow.Web.Mvc; +using Microsoft.Extensions.DependencyInjection; using System; -using System.Net.Http; using System.Net.Http.Json; using Xunit; @@ -20,7 +20,7 @@ namespace Bootstrap.Admin.Api // 菜单 系统菜单 系统使用条件 var query = "?sort=LogTime&order=desc&offset=0&limit=20&operateType=&OperateTimeStart=&OperateTimeEnd=&AccessIP=&_=1547617573596"; - var qd = await Client.GetFromJsonAsync>(query); + var qd = await Client.GetFromJsonAsync>(query, new System.Text.Json.JsonSerializerOptions().AddDefaultConverters()); Assert.NotEmpty(qd.rows); // clean