test: 重构更改系统模式方法增加单元测试
This commit is contained in:
parent
c0fab60865
commit
0cf1d3cb60
|
@ -33,7 +33,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
[HttpPost("{id}")]
|
||||
public bool Post(string id, [FromBody]BootstrapDict dict) => id switch
|
||||
{
|
||||
"Demo" => DictHelper.UpdateSystemModel(dict.Code == "1", dict.Name),
|
||||
"Demo" => DictHelper.UpdateSystemModel(dict.Code == "1", dict.Name, dict.Category),
|
||||
"AppPath" => DictHelper.SaveAppSettings(dict),
|
||||
_ => false
|
||||
};
|
||||
|
|
|
@ -244,7 +244,7 @@ namespace Bootstrap.Admin.Pages.Views.Admin.Components
|
|||
/// </summary>
|
||||
protected async System.Threading.Tasks.Task SaveSystemModel()
|
||||
{
|
||||
var ret = DictHelper.UpdateSystemModel(Model.EnableDemo, Model.AuthKey);
|
||||
var ret = DictHelper.UpdateSystemModel(Model.EnableDemo, Model.AuthKey, "/oEQLKLccvHA+MsDwCwmgaKddR0IEcOy9KgBmFsHXRs=");
|
||||
ShowMessage("保存演示系统设置", ret);
|
||||
if (ret)
|
||||
{
|
||||
|
|
|
@ -144,7 +144,7 @@ $(function () {
|
|||
var demo = $('#demo').prop('checked') ? "1" : "0";
|
||||
var authKey = $('#authKey').val();
|
||||
$.bc({
|
||||
url: Settings.url + '/Demo', data: { name: authKey, code: demo }, title: '演示系统设置', method: "post",
|
||||
url: Settings.url + '/Demo', data: { category: "/oEQLKLccvHA+MsDwCwmgaKddR0IEcOy9KgBmFsHXRs=", name: authKey, code: demo }, title: '演示系统设置', method: "post",
|
||||
callback: function (result) {
|
||||
if (result) {
|
||||
window.setTimeout(function () { window.location.reload(true); }, 1000);
|
||||
|
|
|
@ -287,11 +287,12 @@ namespace Bootstrap.DataAccess
|
|||
/// 设置 系统是否为演示系统 默认为 false 不是演示系统
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool UpdateSystemModel(bool isDemo, string authKey)
|
||||
public static bool UpdateSystemModel(bool isDemo, string authKey, string result)
|
||||
{
|
||||
var ret = false;
|
||||
// 检查授权码
|
||||
if (Longbow.Security.Cryptography.LgbCryptography.ComputeHash(authKey, "l9w+7loytBzNHYkKjGzpWzbhYpU7kWZenT1OeZxkor28wQJQ") == "/oEQLKLccvHA+MsDwCwmgaKddR0IEcOy9KgBmFsHXRs=")
|
||||
// 请求者提供 秘钥与结果 服务器端通过算法比对结果
|
||||
if (Longbow.Security.Cryptography.LgbCryptography.ComputeHash(authKey, "l9w+7loytBzNHYkKjGzpWzbhYpU7kWZenT1OeZxkor28wQJQ") == result)
|
||||
{
|
||||
ret = DbContextManager.Create<Dict>()?.UpdateSystemModel(isDemo) ?? false;
|
||||
}
|
||||
|
|
|
@ -48,9 +48,12 @@ namespace Bootstrap.Admin.Api
|
|||
public async void Post_Id_Ok()
|
||||
{
|
||||
// Demo
|
||||
var resp = await Client.PostAsJsonAsync<BootstrapDict, bool>("Demo", new BootstrapDict() { Name = "1", Code = "UnitTest" });
|
||||
var resp = await Client.PostAsJsonAsync<BootstrapDict, bool>("Demo", new BootstrapDict() { Name = "UnitTest", Code = "0", Category = "/oEQLKLccvHA+MsDwCwmgaKddR0IEcOy9KgBmFsHXRs=" });
|
||||
Assert.False(resp);
|
||||
|
||||
resp = await Client.PostAsJsonAsync<BootstrapDict, bool>("Demo", new BootstrapDict() { Name = "123456", Code = "0", Category = "BPtCMhaFngsDb6NsbnnSgQUn4Ej6PnsvaUV3bChYei8=" });
|
||||
Assert.True(resp);
|
||||
|
||||
// AppPath
|
||||
var dict = new BootstrapDict() { Category = "UnitTest", Name = "UnitTest", Code = "http://localhost/AppPath/" };
|
||||
resp = await Client.PostAsJsonAsync<BootstrapDict, bool>("AppPath", dict);
|
||||
|
|
|
@ -58,6 +58,13 @@ namespace Bootstrap.Admin.Api
|
|||
resp = await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>("/api/Tasks", new string[] { widget.Name });
|
||||
Assert.True(resp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DefaultTaskExecutor_Ok()
|
||||
{
|
||||
var executor = new DefaultTaskExecutor();
|
||||
executor.Execute(new System.Threading.CancellationToken());
|
||||
}
|
||||
}
|
||||
|
||||
[Collection("SystemModel")]
|
||||
|
|
|
@ -55,6 +55,20 @@ namespace Bootstrap.DataAccess
|
|||
Assert.NotEmpty(DictHelper.RetrieveCategories());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetrieveWebIcon_Ok()
|
||||
{
|
||||
var url = DictHelper.RetrieveWebIcon("Demo");
|
||||
Assert.Equal("http://localhost:49185/favicon.ico", url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetrieveWebLogo_Ok()
|
||||
{
|
||||
var url = DictHelper.RetrieveWebLogo("Demo");
|
||||
Assert.Equal("http://localhost:49185/favicon.png", url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetrieveWebTitle_Ok()
|
||||
{
|
||||
|
@ -353,12 +367,12 @@ namespace Bootstrap.DataAccess
|
|||
private class BaiduIP138Locator
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
///
|
||||
/// </summary>
|
||||
public string Status { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 地理位置结果
|
||||
/// 获得/设置 地理位置结果
|
||||
/// </summary>
|
||||
public IEnumerable<BaiDuIp138LocatorResult> Data { get; set; } = new BaiDuIp138LocatorResult[0];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue