diff --git a/Bootstrap.Admin/Controllers/Api/LogsController.cs b/Bootstrap.Admin/Controllers/Api/LogsController.cs
index f7d177d2..1e702d48 100644
--- a/Bootstrap.Admin/Controllers/Api/LogsController.cs
+++ b/Bootstrap.Admin/Controllers/Api/LogsController.cs
@@ -3,6 +3,7 @@ using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
+using System.Net;
namespace Bootstrap.Admin.Controllers.Api
{
@@ -23,16 +24,7 @@ namespace Bootstrap.Admin.Controllers.Api
{
return value.RetrieveData();
}
- ///
- ///
- ///
- ///
- ///
- [HttpGet("{id}")]
- public Log Get(string id)
- {
- return LogHelper.Retrieves().FirstOrDefault(t => t.Id == id);
- }
+
///
///
///
@@ -42,7 +34,7 @@ namespace Bootstrap.Admin.Controllers.Api
public bool Post([FromBody]Log value)
{
value.ClientAgent = Request.Headers["User-Agent"];
- value.ClientIp = HttpContext.Connection.RemoteIpAddress.ToString();
+ value.ClientIp = (HttpContext.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString();
value.UserName = User.Identity.Name;
return LogHelper.Save(value);
}
diff --git a/UnitTest/Bootstrap.Admin/Api/LogsTest.cs b/UnitTest/Bootstrap.Admin/Api/LogsTest.cs
new file mode 100644
index 00000000..778915ca
--- /dev/null
+++ b/UnitTest/Bootstrap.Admin/Api/LogsTest.cs
@@ -0,0 +1,31 @@
+using Bootstrap.DataAccess;
+using Longbow.Web.Mvc;
+using Xunit;
+
+namespace Bootstrap.Admin.Api
+{
+ public class LogsTest : ApiTest
+ {
+ public LogsTest(BAWebHost factory) : base(factory, "Logs", true)
+ {
+
+ }
+
+ [Fact]
+ public async void Get_Ok()
+ {
+ // 菜单 系统菜单 系统使用条件
+ var query = "?sort=LogTime&order=desc&offset=0&limit=20&operateType=&OperateTimeStart=&OperateTimeEnd=&_=1547617573596";
+ var qd = await Client.GetAsJsonAsync>(query);
+ Assert.NotEmpty(qd.rows);
+ }
+
+ [Fact]
+ public async void Post_Ok()
+ {
+ Client.DefaultRequestHeaders.Add("user-agent", "UnitTest");
+ var resp = await Client.PostAsJsonAsync("", new Log() { CRUD = "UnitTest", RequestUrl = "~/UnitTest" });
+ Assert.True(resp);
+ }
+ }
+}