test: 增加单元测试

This commit is contained in:
Argo Zhang 2019-06-19 16:44:36 +08:00
parent a44a133d11
commit 767eeea572
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
9 changed files with 62 additions and 72 deletions

View File

@ -30,7 +30,7 @@ namespace Bootstrap.Admin.Query
/// <returns></returns> /// <returns></returns>
public QueryData<LoginUser> RetrieveData() public QueryData<LoginUser> RetrieveData()
{ {
if (string.IsNullOrEmpty(Order)) Order = "LoginTime desc"; if (string.IsNullOrEmpty(Order)) Order = "desc";
var data = LoginHelper.RetrievePages(this, StartTime, EndTime, LoginIP); var data = LoginHelper.RetrievePages(this, StartTime, EndTime, LoginIP);
return new QueryData<LoginUser> return new QueryData<LoginUser>
{ {

View File

@ -11,24 +11,19 @@ namespace Bootstrap.Admin.Api.SqlServer
{ {
public DictTest(BAWebHost factory) : base(factory, "api/Dicts") { } public DictTest(BAWebHost factory) : base(factory, "api/Dicts") { }
[Fact] [Theory()]
public async void Get_Ok() [InlineData("Category", "asc")]
[InlineData("Name", "asc")]
[InlineData("Code", "asc")]
[InlineData("Define", "asc")]
[InlineData("Category", "desc")]
[InlineData("Name", "desc")]
[InlineData("Code", "desc")]
[InlineData("Define", "desc")]
public async void Get_Ok(string query, string order)
{ {
// 菜单 系统菜单 系统使用条件 // 菜单 系统菜单 系统使用条件
var query = "?sort=Category&order=asc&offset=0&limit=20&category=%E8%8F%9C%E5%8D%95&name=%E7%B3%BB%E7%BB%9F%E8%8F%9C%E5%8D%95&define=0&_=1547608210979"; var qd = await Client.GetAsJsonAsync<QueryData<BootstrapDict>>($"?sort={query}&order={order}&offset=0&limit=20&category=%E8%8F%9C%E5%8D%95&name=%E7%B3%BB%E7%BB%9F%E8%8F%9C%E5%8D%95&define=0&_=1547608210979");
var qd = await Client.GetAsJsonAsync<QueryData<BootstrapDict>>(query);
Assert.Single(qd.rows);
query = "?sort=Name&order=asc&offset=0&limit=20&category=%E8%8F%9C%E5%8D%95&name=%E7%B3%BB%E7%BB%9F%E8%8F%9C%E5%8D%95&define=0&_=1547608210979";
qd = await Client.GetAsJsonAsync<QueryData<BootstrapDict>>(query);
Assert.Single(qd.rows);
query = "?sort=Code&order=asc&offset=0&limit=20&category=%E8%8F%9C%E5%8D%95&name=%E7%B3%BB%E7%BB%9F%E8%8F%9C%E5%8D%95&define=0&_=1547608210979";
qd = await Client.GetAsJsonAsync<QueryData<BootstrapDict>>(query);
Assert.Single(qd.rows);
query = "?sort=Define&order=asc&offset=0&limit=20&category=%E8%8F%9C%E5%8D%95&name=%E7%B3%BB%E7%BB%9F%E8%8F%9C%E5%8D%95&define=0&_=1547608210979";
qd = await Client.GetAsJsonAsync<QueryData<BootstrapDict>>(query);
Assert.Single(qd.rows); Assert.Single(qd.rows);
} }

View File

@ -16,6 +16,8 @@ namespace Bootstrap.Admin.Api.SqlServer
// 菜单 系统菜单 系统使用条件 // 菜单 系统菜单 系统使用条件
var query = "?sort=GroupName&order=asc&offset=0&limit=20&groupName=Admin&description=%E7%B3%BB%E7%BB%9F%E9%BB%98%E8%AE%A4%E7%BB%84&_=1547614230481"; var query = "?sort=GroupName&order=asc&offset=0&limit=20&groupName=Admin&description=%E7%B3%BB%E7%BB%9F%E9%BB%98%E8%AE%A4%E7%BB%84&_=1547614230481";
var qd = await Client.GetAsJsonAsync<QueryData<Group>>(query); var qd = await Client.GetAsJsonAsync<QueryData<Group>>(query);
query = "?sort=GroupName&order=desc&offset=0&limit=20&groupName=Admin&description=%E7%B3%BB%E7%BB%9F%E9%BB%98%E8%AE%A4%E7%BB%84&_=1547614230481";
qd = await Client.GetAsJsonAsync<QueryData<Group>>(query);
Assert.Single(qd.rows); Assert.Single(qd.rows);
} }

View File

@ -12,7 +12,7 @@ namespace Bootstrap.Admin.Api.SqlServer
[Fact] [Fact]
public async void Login_Get() public async void Login_Get()
{ {
var users = await Client.GetAsJsonAsync<QueryData<LoginUser>>(); var users = await Client.GetAsJsonAsync<QueryData<LoginUser>>("?sort=LoginTime&order=&offset=0&limit=20&startTime=&endTime=&loginIp=&_=1560933256621");
Assert.NotEmpty(users.rows); Assert.NotEmpty(users.rows);
} }

View File

@ -11,35 +11,24 @@ namespace Bootstrap.Admin.Api.SqlServer
{ {
public MenusTest(BAWebHost factory) : base(factory, "api/Menus") { } public MenusTest(BAWebHost factory) : base(factory, "api/Menus") { }
[Fact] [Theory]
public async void Get_Ok() [InlineData("Order", "asc")]
[InlineData("Name", "asc")]
[InlineData("ParentName", "asc")]
[InlineData("CategoryName", "asc")]
[InlineData("Target", "asc")]
[InlineData("IsResource", "asc")]
[InlineData("Application", "asc")]
[InlineData("Order", "desc")]
[InlineData("Name", "desc")]
[InlineData("ParentName", "desc")]
[InlineData("CategoryName", "desc")]
[InlineData("Target", "desc")]
[InlineData("IsResource", "desc")]
[InlineData("Application", "desc")]
public async void Get_Ok(string query, string order)
{ {
var query = "?sort=Order&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255"; var qd = await Client.GetAsJsonAsync<QueryData<object>>($"?sort={query}&order={order}&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255");
var qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
Assert.Single(qd.rows);
query = "?sort=Name&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
Assert.Single(qd.rows);
query = "?sort=ParentName&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
Assert.Single(qd.rows);
query = "?sort=CategoryName&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
Assert.Single(qd.rows);
query = "?sort=Target&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
Assert.Single(qd.rows);
query = "?sort=IsResource&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
Assert.Single(qd.rows);
query = "?sort=Application&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
Assert.Single(qd.rows); Assert.Single(qd.rows);
} }

View File

@ -10,12 +10,13 @@ namespace Bootstrap.Admin.Api.SqlServer
{ {
public RolesTest(BAWebHost factory) : base(factory, "api/Roles") { } public RolesTest(BAWebHost factory) : base(factory, "api/Roles") { }
[Fact] [Theory]
public async void Get_Ok() [InlineData("RoleName", "asc")]
[InlineData("RoleName", "desc")]
public async void Get_Ok(string query, string order)
{ {
// 菜单 系统菜单 系统使用条件 // 菜单 系统菜单 系统使用条件
var query = "?sort=RoleName&order=asc&offset=0&limit=20&roleName=Administrators&description=%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%91%98&_=1547625202230"; var qd = await Client.GetAsJsonAsync<QueryData<Group>>($"?sort={query}&order={order}&offset=0&limit=20&roleName=Administrators&description=%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%91%98&_=1547625202230");
var qd = await Client.GetAsJsonAsync<QueryData<Group>>(query);
Assert.Single(qd.rows); Assert.Single(qd.rows);
} }

View File

@ -16,7 +16,7 @@ namespace Bootstrap.Admin.Api.SqlServer
trac.Save(trac); trac.Save(trac);
// 菜单 系统菜单 系统使用条件 // 菜单 系统菜单 系统使用条件
var query = "?sort=LogTime&order=desc&offset=0&limit=20&operateType=&OperateTimeStart=&OperateTimeEnd=&_=1547617573596"; var query = "?sort=LogTime&order=desc&offset=0&limit=20&operateType=&OperateTimeStart=&OperateTimeEnd=&AccessIP=&_=1547617573596";
var qd = await Client.GetAsJsonAsync<QueryData<Trace>>(query); var qd = await Client.GetAsJsonAsync<QueryData<Trace>>(query);
Assert.NotEmpty(qd.rows); Assert.NotEmpty(qd.rows);

View File

@ -21,28 +21,21 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.Equal(HttpStatusCode.NoContent, resp.StatusCode); Assert.Equal(HttpStatusCode.NoContent, resp.StatusCode);
} }
[Fact] [Theory]
public async void Get_Ok() [InlineData("DisplayName", "asc")]
[InlineData("UserName", "asc")]
[InlineData("RegisterTime", "asc")]
[InlineData("ApprovedTime", "asc")]
[InlineData("ApprovedBy", "asc")]
[InlineData("DisplayName", "desc")]
[InlineData("UserName", "desc")]
[InlineData("RegisterTime", "desc")]
[InlineData("ApprovedTime", "desc")]
[InlineData("ApprovedBy", "desc")]
public async void Get_Ok(string query, string order)
{ {
// 菜单 系统菜单 系统使用条件 // 菜单 系统菜单 系统使用条件
var query = "?sort=DisplayName&order=asc&offset=0&limit=20&name=Admin&displayName=Administrator&_=1547628247338"; var qd = await Client.GetAsJsonAsync<QueryData<object>>($"?sort={query}&order={order}&offset=0&limit=20&name=Admin&displayName=Administrator&_=1547628247338");
var qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
Assert.Single(qd.rows);
query = "?sort=UserName&order=asc&offset=0&limit=20&name=Admin&displayName=Administrator&_=1547628247338";
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
Assert.Single(qd.rows);
query = "?sort=RegisterTime&order=asc&offset=0&limit=20&name=Admin&displayName=Administrator&_=1547628247338";
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
Assert.Single(qd.rows);
query = "?sort=ApprovedTime&order=asc&offset=0&limit=20&name=Admin&displayName=Administrator&_=1547628247338";
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
Assert.Single(qd.rows);
query = "?sort=ApprovedBy&order=asc&offset=0&limit=20&name=Admin&displayName=Administrator&_=1547628247338";
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
Assert.Single(qd.rows); Assert.Single(qd.rows);
} }

View File

@ -1,4 +1,5 @@
using Xunit; using Microsoft.AspNetCore.Authentication.Cookies;
using Xunit;
namespace Bootstrap.Admin.Controllers.SqlServer namespace Bootstrap.Admin.Controllers.SqlServer
{ {
@ -28,5 +29,14 @@ namespace Bootstrap.Admin.Controllers.SqlServer
Assert.Contains("服务器内部错误", content); Assert.Contains("服务器内部错误", content);
} }
} }
[Fact]
public async void Error_Redirect_Ok()
{
var r = await Client.GetAsync($"/Home/Error/404?{CookieAuthenticationDefaults.ReturnUrlParameter}=/Home/UnitTest");
Assert.True(r.IsSuccessStatusCode);
var content = await r.Content.ReadAsStringAsync();
Assert.Contains("/Home/UnitTest", content);
}
} }
} }