BootstrapAdmin/UnitTest/Bootstrap.Admin/Api/SettingsTest.cs

73 lines
2.1 KiB
C#

using Bootstrap.DataAccess;
using Bootstrap.Security;
using Longbow.Cache;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
{
public class SettingsTest : ControllerTest
{
public SettingsTest(BAWebHost factory) : base(factory, "api/Settings") { }
[Fact]
public async void Get_Ok()
{
var resp = await Client.GetAsJsonAsync<IEnumerable<CacheCorsItem>>();
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);
}
internal class CacheCorsItem : ICacheCorsItem
{
/// <summary>
///
/// </summary>
public bool Enabled { get; set; }
/// <summary>
///
/// </summary>
public string Key { get; set; }
/// <summary>
///
/// </summary>
public string Url { get; set; }
/// <summary>
///
/// </summary>
public string Desc { get; set; }
/// <summary>
///
/// </summary>
public bool Self { get; set; }
}
}
}