diff --git a/src/admin/Bootstrap.Admin/Controllers/AccountController.cs b/src/admin/Bootstrap.Admin/Controllers/AccountController.cs
index 0af1882b..badd20d0 100644
--- a/src/admin/Bootstrap.Admin/Controllers/AccountController.cs
+++ b/src/admin/Bootstrap.Admin/Controllers/AccountController.cs
@@ -158,22 +158,6 @@ namespace Bootstrap.Admin.Controllers
return Redirect(originUrl);
}
- ///
- /// 创建登录用户信息
- ///
- ///
- ///
- ///
- internal static void CreateLoginUser(IIPLocatorProvider ipLocator, HttpContext context, LoginUser loginUser)
- {
- loginUser.UserAgent = context.Request.Headers["User-Agent"];
- var agent = new UserAgent(loginUser.UserAgent);
- loginUser.Ip = context.Connection.RemoteIpAddress.ToIPv4String();
- loginUser.City = ipLocator.Locate(loginUser.Ip);
- loginUser.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}";
- loginUser.OS = $"{agent.OS?.Name} {agent.OS?.Version}";
- }
-
///
/// Logout this instance.
///
diff --git a/src/admin/Bootstrap.Admin/Query/QuerySQLOption.cs b/src/admin/Bootstrap.Admin/Query/QuerySQLOption.cs
index 01bbf00f..8b6c7840 100644
--- a/src/admin/Bootstrap.Admin/Query/QuerySQLOption.cs
+++ b/src/admin/Bootstrap.Admin/Query/QuerySQLOption.cs
@@ -30,6 +30,7 @@ namespace Bootstrap.Admin.Query
///
public QueryData RetrieveData()
{
+ if (string.IsNullOrEmpty(Order)) Order = "LogTime";
var data = LogHelper.RetrieveDBLogs(this, OperateTimeStart, OperateTimeEnd, UserName);
var ret = new QueryData();
ret.total = data.TotalItems;
diff --git a/test/UnitTest/Bootstrap.Admin/Api/MySql/SQLTest.cs b/test/UnitTest/Bootstrap.Admin/Api/MySql/SQLTest.cs
new file mode 100644
index 00000000..3b97fa5c
--- /dev/null
+++ b/test/UnitTest/Bootstrap.Admin/Api/MySql/SQLTest.cs
@@ -0,0 +1,10 @@
+using Xunit;
+
+namespace Bootstrap.Admin.Api.MySql
+{
+ [Collection("MySqlContext")]
+ public class SQLTest : SqlServer.SQLTest
+ {
+ public SQLTest(SQLiteBAWebHost factory) : base(factory) { }
+ }
+}
diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/LoginTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/LoginTest.cs
index 9926b5e2..df7d7e2d 100644
--- a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/LoginTest.cs
+++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/LoginTest.cs
@@ -32,6 +32,19 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.Equal("", _token);
}
+ [Fact]
+ public async void Put_Ok()
+ {
+ var resq = await Client.PutAsync("?phone=", new StringContent(""));
+ var _token = await resq.Content.ReadAsStringAsync();
+ Assert.Equal("false", _token);
+
+ // UNDONE: 重构短信登陆后完善
+ //resq = await Client.PutAsync("?phone=", new StringContent(""));
+ //_token = await resq.Content.ReadAsStringAsync();
+ //Assert.Equal("true", _token);
+ }
+
[Fact]
public async void Option_Ok()
{
diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLServer/SQLTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/SQLTest.cs
new file mode 100644
index 00000000..377a9996
--- /dev/null
+++ b/test/UnitTest/Bootstrap.Admin/Api/SQLServer/SQLTest.cs
@@ -0,0 +1,18 @@
+using Bootstrap.DataAccess;
+using Longbow.Web.Mvc;
+using Xunit;
+
+namespace Bootstrap.Admin.Api.SqlServer
+{
+ public class SQLTest : ControllerTest
+ {
+ public SQLTest(BAWebHost factory) : base(factory, "api/SQL") { }
+
+ [Fact]
+ public async void Get_Ok()
+ {
+ var resp = await Client.GetAsJsonAsync>("?userName=Admin&OperateTimeStart=&OperateTimeEnd=");
+ Assert.NotNull(resp);
+ }
+ }
+}
diff --git a/test/UnitTest/Bootstrap.Admin/Api/SQLite/SQLTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SQLite/SQLTest.cs
new file mode 100644
index 00000000..b835c01f
--- /dev/null
+++ b/test/UnitTest/Bootstrap.Admin/Api/SQLite/SQLTest.cs
@@ -0,0 +1,10 @@
+using Xunit;
+
+namespace Bootstrap.Admin.Api.SQLite
+{
+ [Collection("SQLiteContext")]
+ public class SQLTest : SqlServer.SQLTest
+ {
+ public SQLTest(SQLiteBAWebHost factory) : base(factory) { }
+ }
+}
diff --git a/test/UnitTest/Bootstrap.Admin/Controllers/SQLServer/AccountTest.cs b/test/UnitTest/Bootstrap.Admin/Controllers/SQLServer/AccountTest.cs
index 9ad8033e..1ebe11f9 100644
--- a/test/UnitTest/Bootstrap.Admin/Controllers/SQLServer/AccountTest.cs
+++ b/test/UnitTest/Bootstrap.Admin/Controllers/SQLServer/AccountTest.cs
@@ -1,7 +1,10 @@
using Bootstrap.DataAccess;
+using System;
+using System.Collections.Concurrent;
using System.Linq;
using System.Net;
using System.Net.Http;
+using System.Reflection;
using Xunit;
namespace Bootstrap.Admin.Controllers.SqlServer
@@ -105,5 +108,37 @@ namespace Bootstrap.Admin.Controllers.SqlServer
};
await Client.PostAsync("Lock", data);
}
+
+ [Theory]
+ [InlineData("Gitee")]
+ [InlineData("GitHub")]
+ [InlineData("WeChat")]
+ public async void OAuth_Ok(string url)
+ {
+ var client = Host.CreateClient();
+ var r = await client.GetAsync($"/Account/{url}");
+ Assert.True(r.IsSuccessStatusCode);
+ var content = await r.Content.ReadAsStringAsync();
+ Assert.Contains("登 录", content);
+ }
+
+ [Fact]
+ public void Mobile_Ok()
+ {
+ // UNDONE: Mobile 单元测试未完成
+
+ // 反射设置 SMSHelper 内部验证码保证 Validate 方法返回真
+ var validateCodeInstance = Activator.CreateInstance(Type.GetType("Bootstrap.DataAccess.SMSHelper+AutoExpireValidateCode, Bootstrap.DataAccess"), new object[] { "18910001000", "1234", TimeSpan.FromSeconds(10)});
+ var _poolInstance = typeof(SMSHelper).GetField("_pool", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
+ //_pool.AddOrUpdate(option.Phone, key => new AutoExpireValidateCode(option.Phone, result.Data, option.Expires), (key, v) => v.Reset(result.Data));
+ //var addMethod = _poolInstance.GetType().GetMethod("AddOrUpdate");
+ //addMethod.Invoke(_poolInstance, new object[] { "18910001000", validateCodeInstance, null });
+
+ //var client = Host.CreateClient();
+ //var r = await client.GetAsync($"/Account/Mobile?phone=18910001000&code=1234");
+ //Assert.True(r.IsSuccessStatusCode);
+ //var content = await r.Content.ReadAsStringAsync();
+ //Assert.Contains("登 录", content);
+ }
}
}
diff --git a/test/UnitTest/Bootstrap.Admin/Controllers/SQLServer/AdminTest.cs b/test/UnitTest/Bootstrap.Admin/Controllers/SQLServer/AdminTest.cs
index a62f152d..6b1eb118 100644
--- a/test/UnitTest/Bootstrap.Admin/Controllers/SQLServer/AdminTest.cs
+++ b/test/UnitTest/Bootstrap.Admin/Controllers/SQLServer/AdminTest.cs
@@ -29,6 +29,7 @@ namespace Bootstrap.Admin.Controllers.SqlServer
[InlineData("Tasks", "任务管理")]
[InlineData("Mobile", "客户端测试")]
[InlineData("Analyse", "网站分析")]
+ [InlineData("SQL", "SQL日志")]
public async void View_Ok(string view, string text)
{
var r = await Client.GetAsync(view);
diff --git a/test/UnitTest/appsettings.json b/test/UnitTest/appsettings.json
index 084fb0fd..3648254c 100644
--- a/test/UnitTest/appsettings.json
+++ b/test/UnitTest/appsettings.json
@@ -49,6 +49,25 @@
}
}
],
+ "GiteeHealthChecks": true,
+ "GiteeOptions": {
+ "Enabled": false
+ },
+ "GitHubOptions": {
+ "Enabled": false
+ },
+ "WeChatOptions": {
+ "Enabled": false
+ },
+ "SMSOptions": {
+ "CompanyCode": "",
+ "MD5Key": "MD5Key",
+ "Roles": [
+ "Administrators"
+ ],
+ "HomePath": "/Admin/Profiles",
+ "App": "0"
+ },
"LongbowCache": {
"Enabled": false
}