test: 修复失败的单元测试

This commit is contained in:
Argo-Tianyi 2021-07-25 22:22:12 +08:00
parent e1b1c3cbb1
commit c4da4cc9dc
8 changed files with 17 additions and 39 deletions

View File

@ -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<QueryData<Exceptions>>(query);
var option = new JsonSerializerOptions().AddDefaultConverters();
var qd = await Client.GetFromJsonAsync<QueryData<Exceptions>>(query, option);
Assert.NotEmpty(qd.rows);
// clean

View File

@ -39,33 +39,5 @@ namespace Bootstrap.Admin.Api
var cates = await Client.GetFromJsonAsync<object>("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<string, Task<string>>(url =>
{
throw new TaskCanceledException();
}),
new Func<string, string>(content => {
return "";
})
});
t.Invoke(null, new object[] {
"",
new Func<string, Task<string>>(url => {
throw new Exception();
}),
new Func<string, string>(content => {
return "";
})
});
}
}
}

View File

@ -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<string>("Healths", "UnitTest");
var ret = await req.Content.ReadFromJsonAsync<bool>();
Assert.False(ret);
Assert.False(req.IsSuccessStatusCode);
}
}
}

View File

@ -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<QueryData<LoginUser>>("?sort=LoginTime&order=&offset=0&limit=20&startTime=&endTime=&loginIp=&_=1560933256621");
var users = await Client.GetFromJsonAsync<QueryData<LoginUser>>("?sort=LoginTime&order=&offset=0&limit=20&startTime=&endTime=&loginIp=&_=1560933256621", new JsonSerializerOptions().AddDefaultConverters());
Assert.NotEmpty(users.rows);
}

View File

@ -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<QueryData<Log>>(query);
var qd = await Client.GetFromJsonAsync<QueryData<Log>>(query, new System.Text.Json.JsonSerializerOptions().AddDefaultConverters());
Assert.NotEmpty(qd.rows);
// clean

View File

@ -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<IEnumerable<OnlineUser>>("");
var users = await Client.GetFromJsonAsync<IEnumerable<OnlineUser>>("", new System.Text.Json.JsonSerializerOptions().AddDefaultConverters());
Assert.Single(users);
}

View File

@ -51,8 +51,7 @@ namespace Bootstrap.Admin.Api
widget.CronExpression = Longbow.Tasks.Cron.Secondly(5);
widget.TaskExecutorName = "UnitTest-Widget";
resp = await Client.PostAsJsonAsync<TaskWidget>("/api/Tasks", widget);
ret = await resp.Content.ReadFromJsonAsync<bool>();
Assert.False(ret);
Assert.False(resp.IsSuccessStatusCode);
widget.TaskExecutorName = "Bootstrap.Admin.DefaultTaskExecutor";
widget.Name = "UnitTest-Task";

View File

@ -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<QueryData<Trace>>(query);
var qd = await Client.GetFromJsonAsync<QueryData<Trace>>(query, new System.Text.Json.JsonSerializerOptions().AddDefaultConverters());
Assert.NotEmpty(qd.rows);
// clean