From 8cf2633a8d0b9b5a737f7391b935f4e218a73fd6 Mon Sep 17 00:00:00 2001 From: Argo-Surface Date: Wed, 16 Jan 2019 14:19:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=EF=BC=9A?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0LogsController=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/LogsController.cs | 14 ++------- UnitTest/Bootstrap.Admin/Api/LogsTest.cs | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 UnitTest/Bootstrap.Admin/Api/LogsTest.cs 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); + } + } +}