test: 增加任务管理单元测试
This commit is contained in:
parent
2454ea3684
commit
dd85f12e79
|
@ -56,7 +56,10 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
{
|
{
|
||||||
// 判断 Cron 表达式
|
// 判断 Cron 表达式
|
||||||
if (string.IsNullOrEmpty(widget.CronExpression)) return false;
|
if (string.IsNullOrEmpty(widget.CronExpression)) return false;
|
||||||
if (_tasks.Any(t => t.Equals(widget.Name, StringComparison.OrdinalIgnoreCase))) return false;
|
|
||||||
|
// 系统内置任务禁止更改
|
||||||
|
// 演示模式下禁止删除内置任务
|
||||||
|
if (DictHelper.RetrieveSystemModel() && _tasks.Any(t => t.Equals(widget.Name, StringComparison.OrdinalIgnoreCase))) return false;
|
||||||
|
|
||||||
// 加载任务执行体
|
// 加载任务执行体
|
||||||
// 此处可以扩展为任意 DLL 中的任意继承 ITask 接口的实体类
|
// 此处可以扩展为任意 DLL 中的任意继承 ITask 接口的实体类
|
||||||
|
|
|
@ -33,5 +33,64 @@ namespace Bootstrap.Admin.Api
|
||||||
var recv = await Client.PutAsJsonAsync<string, bool>("/api/Tasks/SQL日志?operType=run", "");
|
var recv = await Client.PutAsJsonAsync<string, bool>("/api/Tasks/SQL日志?operType=run", "");
|
||||||
Assert.True(recv);
|
Assert.True(recv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void Post_Ok()
|
||||||
|
{
|
||||||
|
var widget = new TaskWidget();
|
||||||
|
|
||||||
|
// widget Cron 表达式为 ”“
|
||||||
|
var resp = await Client.PostAsJsonAsync<TaskWidget, bool>("/api/Tasks", widget);
|
||||||
|
Assert.False(resp);
|
||||||
|
|
||||||
|
// task executor 不合法
|
||||||
|
widget.CronExpression = Longbow.Tasks.Cron.Secondly(5);
|
||||||
|
widget.TaskExecutorName = "UnitTest-Widget";
|
||||||
|
resp = await Client.PostAsJsonAsync<TaskWidget, bool>("/api/Tasks", widget);
|
||||||
|
Assert.False(resp);
|
||||||
|
|
||||||
|
widget.TaskExecutorName = "Bootstrap.Admin.DefaultTaskExecutor";
|
||||||
|
widget.Name = "UnitTest-Task";
|
||||||
|
resp = await Client.PostAsJsonAsync<TaskWidget, bool>("/api/Tasks", widget);
|
||||||
|
Assert.True(resp);
|
||||||
|
|
||||||
|
// Delete
|
||||||
|
resp = await Client.DeleteAsJsonAsync<IEnumerable<string>, bool>("/api/Tasks", new string[] { widget.Name });
|
||||||
|
Assert.True(resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Collection("SystemModel")]
|
||||||
|
public class TasksSystemModelTest
|
||||||
|
{
|
||||||
|
private HttpClient client;
|
||||||
|
|
||||||
|
public TasksSystemModelTest(BASystemModelWebHost factory)
|
||||||
|
{
|
||||||
|
client = factory.CreateClient("/api/Tasks");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void Post_Ok()
|
||||||
|
{
|
||||||
|
var widget = new TaskWidget();
|
||||||
|
widget.CronExpression = Longbow.Tasks.Cron.Secondly(5);
|
||||||
|
widget.Name = "单次任务";
|
||||||
|
widget.TaskExecutorName = "Bootstrap.Admin.DefaultTaskExecutor";
|
||||||
|
|
||||||
|
// 演示模式下禁止移除系统内置任务
|
||||||
|
var resp = await client.PostAsJsonAsync<TaskWidget, bool>("/api/Tasks", widget);
|
||||||
|
Assert.False(resp);
|
||||||
|
|
||||||
|
resp = await client.DeleteAsJsonAsync<IEnumerable<string>, bool>("/api/Tasks", new string[] { widget.Name });
|
||||||
|
Assert.False(resp);
|
||||||
|
|
||||||
|
widget.Name = "Test-Widget";
|
||||||
|
resp = await client.PostAsJsonAsync<TaskWidget, bool>("/api/Tasks", widget);
|
||||||
|
Assert.True(resp);
|
||||||
|
|
||||||
|
resp = await client.DeleteAsJsonAsync<IEnumerable<string>, bool>("/api/Tasks", new string[] { widget.Name });
|
||||||
|
Assert.True(resp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue