From d1e8e104c6d4c0a58aed5e7e5ac3669bfa74315c Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 28 Feb 2020 13:23:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=BA=94=E7=94=A8=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E4=BF=9D=E5=AD=98=E5=9C=B0=E5=9D=80=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20/=20=E7=AC=A6=E5=8F=B7=E5=8E=BB=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bootstrap.DataAccess/Helper/DictHelper.cs | 7 ++- .../Bootstrap.Admin/Api/SettingsTest.cs | 45 ++++++++++++++++--- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs b/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs index dccd2985..2735908b 100644 --- a/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs +++ b/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs @@ -169,7 +169,9 @@ namespace Bootstrap.DataAccess { Category = "网站设置", Name = cache[i.Name], - Code = i.Code + + // 后台网站配置不能以 / 号结尾 + Code = i.Name == "AppPath" ? i.Code.TrimEnd('/') : i.Code })); return ret; } @@ -377,6 +379,9 @@ namespace Bootstrap.DataAccess { // dict define == 1 时为新建前台应用 bool ret; + + // 前台网站配置地址 不允许以 / 结尾 + dict.Code = dict.Code.TrimEnd('/'); if (dict.Define == 0) { // Update diff --git a/test/UnitTest/Bootstrap.Admin/Api/SettingsTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SettingsTest.cs index 9aeba955..c7fd7e3e 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SettingsTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SettingsTest.cs @@ -39,35 +39,68 @@ namespace Bootstrap.Admin.Api var code = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "UnitTest-Settings").Code; Assert.Equal("0", code); - // Delete + // Delete ids = DictHelper.RetrieveDicts().Where(d => d.Category == "UnitTest-Settings").Select(d => d.Id); DictHelper.Delete(ids); } + [Fact] + public async void Post_Id_Ok() + { + // Demo + var resp = await Client.PostAsJsonAsync("Demo", new BootstrapDict() { Name = "1", Code = "UnitTest" }); + Assert.False(resp); + + // AppPath + var dict = new BootstrapDict() { Category = "UnitTest", Name = "UnitTest", Code = "http://localhost/AppPath/" }; + resp = await Client.PostAsJsonAsync("AppPath", dict); + Assert.True(resp); + + Assert.Equal(dict.Code.TrimEnd('/'), DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "应用首页" && d.Name == dict.Name)?.Code ?? ""); + + // update by set dict.Define = 0 + dict.Define = 0; + dict.Code = "http://127.0.0.1/UnitTest"; + resp = await Client.PostAsJsonAsync("AppPath", dict); + Assert.True(resp); + + Assert.Equal(dict.Code.TrimEnd('/'), DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "应用首页" && d.Name == dict.Name)?.Code ?? ""); + + // del + dict.Name = "UnitTest"; + dict.Code = "UnitTest"; + resp = await Client.DeleteAsJsonAsync("AppPath", dict); + Assert.True(resp); + + // Else + resp = await Client.PostAsJsonAsync("UnitTest", dict); + Assert.False(resp); + } + internal class CacheCorsItem : ICacheCorsItem { /// - /// + /// /// public bool Enabled { get; set; } /// - /// + /// /// public string Key { get; set; } /// - /// + /// /// public string Url { get; set; } /// - /// + /// /// public string Desc { get; set; } /// - /// + /// /// public bool Self { get; set; } }