单元测试:增加SettingsController单元测试
This commit is contained in:
parent
3b55279c16
commit
4fd9fadc1b
|
@ -18,6 +18,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual bool Delete(IEnumerable<string> value)
|
public virtual bool Delete(IEnumerable<string> value)
|
||||||
{
|
{
|
||||||
|
if (!value.Any()) return true;
|
||||||
var ids = string.Join(",", value);
|
var ids = string.Join(",", value);
|
||||||
string sql = $"where ID in ({ids})";
|
string sql = $"where ID in ({ids})";
|
||||||
DbManager.Create().Delete<BootstrapDict>(sql);
|
DbManager.Create().Delete<BootstrapDict>(sql);
|
||||||
|
|
|
@ -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<IEnumerable<ICacheCorsItem>>();
|
||||||
|
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<BootstrapDict, bool>("", 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue