From 4fd9fadc1b9b509fde6d0bb8585248e38009d92e Mon Sep 17 00:00:00 2001 From: Argo-Surface Date: Wed, 16 Jan 2019 16:36:44 +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=A0SettingsController=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 --- Bootstrap.DataAccess/Dict.cs | 1 + UnitTest/Bootstrap.Admin/Api/SettingsTest.cs | 47 ++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 UnitTest/Bootstrap.Admin/Api/SettingsTest.cs diff --git a/Bootstrap.DataAccess/Dict.cs b/Bootstrap.DataAccess/Dict.cs index 9eb457ed..29049f2e 100644 --- a/Bootstrap.DataAccess/Dict.cs +++ b/Bootstrap.DataAccess/Dict.cs @@ -18,6 +18,7 @@ namespace Bootstrap.DataAccess /// public virtual bool Delete(IEnumerable value) { + if (!value.Any()) return true; var ids = string.Join(",", value); string sql = $"where ID in ({ids})"; DbManager.Create().Delete(sql); diff --git a/UnitTest/Bootstrap.Admin/Api/SettingsTest.cs b/UnitTest/Bootstrap.Admin/Api/SettingsTest.cs new file mode 100644 index 00000000..91341c68 --- /dev/null +++ b/UnitTest/Bootstrap.Admin/Api/SettingsTest.cs @@ -0,0 +1,47 @@ +using Bootstrap.DataAccess; +using Bootstrap.Security; +using Longbow.Cache; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace Bootstrap.Admin.Api +{ + public class SettingsTest : ApiTest + { + public SettingsTest(BAWebHost factory) : base(factory, "Settings", true) + { + + } + + [Fact] + public async void Get_Ok() + { + var resp = await Client.GetAsJsonAsync>(); + Assert.NotNull(resp); + } + + [Fact] + public async void Post_Ok() + { + var dict = new Dict(); + var dicts = dict.RetrieveDicts(); + + var ids = dicts.Where(d => d.Category == "UnitTest-Settings").Select(d => d.Id); + dict.Delete(ids); + + Assert.True(dict.Save(new Dict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "0", Define = 0 })); + + // 获得原来值 + var resp = await Client.PostAsJsonAsync("", new Dict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "UnitTest" }); + Assert.True(resp); + + var code = dict.RetrieveDicts().FirstOrDefault(d => d.Category == "UnitTest-Settings").Code; + Assert.Equal("UnitTest", code); + + // Delete + ids = dict.RetrieveDicts().Where(d => d.Category == "UnitTest-Settings").Select(d => d.Id); + dict.Delete(ids); + } + } +}