!67 单元测试:重构单元测试

* test: 增加地理位置服务单元测试
* build: 依赖组件升级
* test: 增加健康检查代码覆盖率
* test: 增加启用默认应用后访问首页代码覆盖
* build: 移除 AutoDB 相关测试
* test: 修复 MongoDB 单元测试
* build: 单元测试移除 MySql
* test: 更新 Mobile 单元测试
* build: 更改单元测试脚本
* test: 整合其他数据库单元测试
* test: 增加首页链接单元测试
* test: 增加数据库回滚测试
* refactor: DBLogTask 移动到单独文件中
* build: 依赖组件升级
* test: 增加演示模式相关单元测试
* test: 增加 Serch 相关单元测试
* refactor: 移动 Blazor Model 到 Models 目录下
* build: 排除 healths 控制器的代码覆盖率
* refactor: 移除 ConfigurationHelperExtensions 文件
* refactor: 健康检查结果接口移动到单独文件中
* refactor: 新加 SQLite 单元测试
* build: 增加 Sqlite 单元测试
This commit is contained in:
Argo 2020-02-12 21:56:35 +08:00
parent 43fdbf1d03
commit bddefe3971
189 changed files with 1834 additions and 2139 deletions

View File

@ -38,18 +38,20 @@
function runUnitTest() {
write-host "dotnet test test\UnitTest" -ForegroundColor Cyan
dotnet test test\UnitTest --filter="FullyQualifiedName!~MySql" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[Bootstrap.Admin*]*%2c[Bootstrap.DataAccess*]*" /p:Exclude="[*]*Program%2c[*]*Startup%2c[Bootstrap.DataAccess]*AutoDB%2c[Bootstrap.DataAccess]*WeChatHelper" /p:ExcludeByFile="**/SMSExtensions.cs%2c**/Helper/OAuthHelper.cs%2c**/Extensions/CloudLoggerExtensions.cs%2c**/Extensions/AutoGenerateDatabaseExtensions.cs" /p:CoverletOutput=..\..\
dotnet test "test\UnitTest" --filter="FullyQualifiedName!~MySql" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[Bootstrap.Admin*]*%2c[Bootstrap.DataAccess*]*" /p:Exclude="[*]*Program%2c[*]*Startup%2c[Bootstrap.DataAccess*]*AutoDB*%2c[Bootstrap.DataAccess]*WeChatHelper" /p:ExcludeByFile="**/SMSExtensions.cs%2c**/Helper/OAuthHelper.cs%2c**/Extensions/CloudLoggerExtensions.cs%2c**/Extensions/AutoGenerateDatabaseExtensions.cs%2c**/Api/HealthsController.cs%2c**/Pages/**%2c**/DBLogTask.cs" /p:CoverletOutput=..\..\
}
function coverallUnitTest() {
function installCoveralls() {
write-host "install coveralls.net tools" -ForegroundColor Cyan
dotnet tool install coveralls.net --version 1.0.0 --tool-path ".\tools"
runUnitTest
}
function reportCoveralls() {
write-host "report UnitTest with Coveralls" -ForegroundColor Cyan
cmd.exe /c ".\tools\csmacnz.Coveralls.exe --opencover -i coverage.opencover.xml --useRelativePaths"
}
function codecovUnitTest() {
function installCodecov() {
Set-AppveyorBuildVariable COVERALLS_REPO_TOKEN $($env:COVERALLS_REPO_TOKEN)
Set-AppveyorBuildVariable CODECOV_TOKEN $($env:CODECOV_TOKEN)
@ -59,17 +61,22 @@ function codecovUnitTest() {
write-host "install codecov tools" -ForegroundColor Cyan
choco install codecov
}
}
function reportCodecov() {
$coverageFile = Test-Path coverage.opencover.xml
if (!$coverageFile) {
runUnitTest
write-host "report UnitTest with Codecov" -ForegroundColor Cyan
cmd.exe /c "$codecovCmd -f ""coverage.opencover.xml"""
}
write-host "report UnitTest with Codecov" -ForegroundColor Cyan
cmd.exe /c "$codecovCmd -f ""coverage.opencover.xml"""
}
$branch = $($env:APPVEYOR_REPO_BRANCH)
if ($branch -ne "dev") {
installDB
coverallUnitTest
codecovUnitTest
installCoveralls
installCodecov
runUnitTest
reportCoveralls
reportCodecov
}

View File

@ -34,7 +34,7 @@ build_script:
.\appveyor.build.ps1
test_script:
- ps: >-
#.\appveyor.test.ps1
.\appveyor.test.ps1
artifacts:
- path: src\admin\Bootstrap.Admin\bin\release\netcoreapp3.1\publish\
name: BootstrapAdmin

View File

@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="Longbow.Logging" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.1.1" />
<PackageReference Include="Sentry.AspNetCore" Version="2.0.1" />
<PackageReference Include="Sentry.AspNetCore" Version="2.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
</ItemGroup>

View File

@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System.Net.Http;
using System.Threading.Tasks;
namespace Bootstrap.Admin.Controllers.Api
{
/// <summary>
/// 健康检查控制器
/// </summary>
[Route("api/[controller]")]
[Authorize]
[ApiController]
public class HealthsController : ControllerBase
{
/// <summary>
/// 发送健康检查结果
/// </summary>
/// <param name="httpClient"></param>
/// <param name="config"></param>
/// <param name="message"></param>
/// <returns></returns>
[HttpPost]
public async Task<bool> Healths([FromServices]GiteeHttpClient httpClient, [FromServices]IConfiguration config, [FromBody]string message)
{
var ret = false;
var url = config.GetValue("HealthsCloudUrl", "");
if (!string.IsNullOrEmpty(url))
{
await httpClient.HttpClient.PostAsJsonAsync(url, message);
ret = true;
}
return ret;
}
}
}

View File

@ -3,10 +3,7 @@ using Bootstrap.Security;
using Bootstrap.Security.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
namespace Bootstrap.Admin.Controllers
{
@ -65,25 +62,5 @@ namespace Bootstrap.Admin.Controllers
/// <returns></returns>
[HttpPost]
public IEnumerable<BootstrapMenu> RetrieveAppMenus([FromBody]AppMenuOption args) => MenuHelper.RetrieveAppMenus(args.AppId, args.UserName, args.Url);
/// <summary>
/// 发送健康检查结果
/// </summary>
/// <param name="httpClient"></param>
/// <param name="config"></param>
/// <param name="message"></param>
/// <returns></returns>
[HttpPost]
public async Task<bool> Healths([FromServices]GiteeHttpClient httpClient, [FromServices]IConfiguration config, [FromBody]string message)
{
var ret = false;
var url = config.GetValue("HealthsCloudUrl", "");
if (!string.IsNullOrEmpty(url))
{
try { await httpClient.HttpClient.PostAsJsonAsync(url, message); ret = true; }
catch { }
}
return ret;
}
}
}

View File

@ -39,8 +39,8 @@ namespace Bootstrap.Admin.Controllers.Api
// SQL 日志任务特殊处理
if (scheName == "SQL日志")
{
if (operType == "pause") LogHelper.Pause();
else LogHelper.Run();
if (operType == "pause") DBLogTask.Pause();
else DBLogTask.Run();
}
return true;
}

View File

@ -1,17 +0,0 @@
using Microsoft.Extensions.Configuration;
namespace Bootstrap.Admin.Extensions
{
/// <summary>
/// 配置文件静态操作类
/// </summary>
public static class ConfigurationHelperExtensions
{
/// <summary>
/// 获得本站 AppId
/// </summary>
/// <param name="configuration"></param>
/// <returns></returns>
public static string GetAppId(this IConfiguration configuration) => configuration.GetValue("AppId", "BA");
}
}

View File

@ -57,7 +57,7 @@ namespace Bootstrap.Admin.HealthChecks
};
// 检查 当前用户 账户权限
var loginUser = _httpContextAccessor.HttpContext.User.Identity.Name;
var loginUser = _httpContextAccessor.HttpContext?.User.Identity.Name;
var userName = loginUser ?? "Admin";
var dictsCount = 0;
var menusCount = 0;

View File

@ -7,7 +7,7 @@ using System.Linq;
namespace Bootstrap.Admin.Models
{
/// <summary>
///
/// 个人中心模型
/// </summary>
public class ProfilesModel : SettingsModel
{
@ -57,14 +57,5 @@ namespace Bootstrap.Admin.Models
// 设置 当前用户默认应用名称
AppName = Applications.FirstOrDefault(app => app.Key == AppId).Value;
}
/// <summary>
/// 构造函数 Blazor 页面调用
/// </summary>
public ProfilesModel(string? userName) :base(userName)
{
// 设置 当前用户默认应用名称
AppName = Applications.FirstOrDefault(app => app.Key == AppId).Value;
}
}
}

View File

@ -21,16 +21,6 @@ namespace Bootstrap.Admin.Models
DefaultApp = DictHelper.RetrieveDefaultApp();
}
/// <summary>
/// 构造函数 Blazor 使用
/// </summary>
public SettingsModel(string? userName) : base(userName)
{
Themes = DictHelper.RetrieveThemes();
AutoLockScreen = EnableAutoLockScreen;
DefaultApp = DictHelper.RetrieveDefaultApp();
}
/// <summary>
/// 获得 系统配置的所有样式表
/// </summary>

View File

@ -1,8 +1,6 @@
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System;
using System.Linq.Expressions;
namespace Bootstrap.Admin.Pages.Components
{

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Components.Forms;
namespace Bootstrap.Admin.Pages.Components
{

View File

@ -1,5 +1,4 @@
using Bootstrap.Admin.Pages.Extensions;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;

View File

@ -1,5 +1,4 @@
using Bootstrap.Admin.Pages.Extensions;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.JSInterop;
using System;

View File

@ -0,0 +1,40 @@
using System.Linq;
namespace Bootstrap.Admin.Pages.Models
{
/// <summary>
/// 个人中心模型
/// </summary>
public class ProfilesModel : SettingsModel
{
/// <summary>
/// 获得 头像文件大小
/// </summary>
public long Size { get; }
/// <summary>
/// 获得 头像文件名称
/// </summary>
public string FileName { get; } = "";
/// <summary>
/// 获得 当前用户默认应用程序名称
/// </summary>
public string AppName { get; }
/// <summary>
/// 获得 是否为第三方用户
/// </summary>
/// <remarks>第三方用户不允许修改密码</remarks>
public bool External { get; }
/// <summary>
/// 构造函数 Blazor 页面调用
/// </summary>
public ProfilesModel(string? userName) : base(userName)
{
// 设置 当前用户默认应用名称
AppName = Applications.FirstOrDefault(app => app.Key == AppId).Value;
}
}
}

View File

@ -0,0 +1,39 @@
using Bootstrap.Admin.Models;
using Bootstrap.DataAccess;
using Bootstrap.Security;
using System.Collections.Generic;
namespace Bootstrap.Admin.Pages.Models
{
/// <summary>
/// 导航模型
/// </summary>
public class SettingsModel : NavigatorBarModel
{
/// <summary>
/// 构造函数 Blazor 使用
/// </summary>
public SettingsModel(string? userName) : base(userName)
{
Themes = DictHelper.RetrieveThemes();
AutoLockScreen = EnableAutoLockScreen;
DefaultApp = DictHelper.RetrieveDefaultApp();
}
/// <summary>
/// 获得 系统配置的所有样式表
/// </summary>
public IEnumerable<BootstrapDict> Themes { get; }
/// <summary>
/// 获得 是否开启自动锁屏
/// </summary>
public bool AutoLockScreen { get; }
/// <summary>
/// 获得 是否开启自动锁屏
/// </summary>
public bool DefaultApp { get; }
}
}

View File

@ -1,4 +1,6 @@
@inherits LayoutComponentBase
@using Bootstrap.Admin.Models
<div class="error-content">
<div class="error-wrapper text-center">
<img src="@model?.Image.ToBlazorLink()" />

View File

@ -1,5 +1,5 @@
using Bootstrap.Admin.Pages.Components;
using Bootstrap.Admin.Models;
using Bootstrap.Admin.Pages.Models;
using Bootstrap.Admin.Pages.Shared;
using Bootstrap.DataAccess;
using Bootstrap.Security;

View File

@ -2,10 +2,10 @@
@using Bootstrap.Admin.Pages
@using Bootstrap.Admin.Pages.Components
@using Bootstrap.Admin.Pages.Extensions
@using Bootstrap.Admin.Pages.Models
@using Bootstrap.Admin.Pages.Views
@using Bootstrap.Admin.Pages.Views.Admin.Components
@using Bootstrap.Admin.Pages.Shared
@using Bootstrap.Admin.Models
@using Bootstrap.Security
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization

View File

@ -51,7 +51,7 @@ namespace Microsoft.Extensions.DependencyInjection
TaskServicesManager.GetOrAdd("禁用任务", token => Task.Delay(1000)).Status = SchedulerStatus.Disabled;
// 真实任务负责批次写入数据执行脚本到日志中
TaskServicesManager.GetOrAdd<LogHelper.DbLogTask>("SQL日志", TriggerBuilder.Build(Cron.Minutely()));
TaskServicesManager.GetOrAdd<DBLogTask>("SQL日志", TriggerBuilder.Build(Cron.Minutely()));
});
}
}

View File

@ -1,7 +1,7 @@
$(function () {
$.extend({
sendHealths: function (data) {
$.bc({ url: 'api/Interface/Healths', data: JSON.stringify(data), method: 'post' });
$.bc({ url: 'api/Healths', data: JSON.stringify(data), method: 'post' });
}
});
var healthStatus = ['<button class="btn btn-danger"><i class="fa fa-times-circle"></i><span>不健康</span></button>', '<button class="btn btn-warning"><i class="fa fa-exclamation-circle"></i><span>亚健康</span></button>', '<button class="btn btn-success"><i class="fa fa-check-circle"></i><span>健康</span></button>'];

View File

@ -8,7 +8,7 @@
<PackageReference Include="Bootstrap.Security.DataAccess" Version="3.1.1" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.1.1" />
<PackageReference Include="Longbow" Version="3.1.0" />
<PackageReference Include="Longbow.Cache" Version="3.1.2-beta-01" />
<PackageReference Include="Longbow.Cache" Version="3.1.2-beta-02" />
<PackageReference Include="Longbow.Data" Version="3.1.0" />
<PackageReference Include="Longbow.GiteeAuth" Version="3.1.0" />
<PackageReference Include="Longbow.GitHubAuth" Version="3.1.0" />
@ -17,7 +17,7 @@
<PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" />
<PackageReference Include="Longbow.Tasks" Version="3.1.0" />
<PackageReference Include="Longbow.Web" Version="3.1.1" />
<PackageReference Include="Longbow.WeChatAuth" Version="3.1.0" />
<PackageReference Include="Longbow.WeChatAuth" Version="3.1.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="3.1.1" />
<PackageReference Include="PetaPoco.Extensions" Version="3.1.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.0" />

View File

@ -0,0 +1,60 @@
using Longbow.Tasks;
using PetaPoco;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace Bootstrap.DataAccess
{
/// <summary>
/// 数据库脚本执行日志任务实体类
/// </summary>
public class DBLogTask : ITask
{
private static readonly BlockingCollection<DBLog> _messageQueue = new BlockingCollection<DBLog>(new ConcurrentQueue<DBLog>());
/// <summary>
/// 添加数据库日志实体类到内部集合中
/// </summary>
/// <param name="log"></param>
public static System.Threading.Tasks.Task AddDBLog(DBLog log) => System.Threading.Tasks.Task.Run(() =>
{
if (!_messageQueue.IsAddingCompleted && !_pause)
{
_messageQueue.Add(log);
}
});
private static bool _pause;
/// <summary>
/// 暂停接收脚本执行日志
/// </summary>
public static void Pause() => _pause = true;
/// <summary>
/// 开始接收脚本执行日志
/// </summary>
public static void Run() => _pause = false;
/// <summary>
/// 任务执行方法
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public System.Threading.Tasks.Task Execute(CancellationToken cancellationToken)
{
var logs = new List<DBLog>();
while (_messageQueue.TryTake(out var log))
{
if (log != null) logs.Add(log);
if (logs.Count >= 100) break;
}
if (logs.Any())
{
using var db = DbManager.Create(enableLog: false);
db.InsertBatch(logs);
}
return System.Threading.Tasks.Task.CompletedTask;
}
}
}

View File

@ -37,7 +37,7 @@ namespace Bootstrap.DataAccess
SQL = db.LastCommand,
UserName = userName
};
await LogHelper.AddDBLog(log).ConfigureAwait(false);
await DBLogTask.AddDBLog(log).ConfigureAwait(false);
});
}
return db;

View File

@ -1,11 +1,7 @@
using Longbow.Tasks;
using Longbow.Web.Mvc;
using Longbow.Web.Mvc;
using PetaPoco;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace Bootstrap.DataAccess
{
@ -41,31 +37,6 @@ namespace Bootstrap.DataAccess
return DbContextManager.Create<Log>()?.Save(log) ?? false;
}
#region
private static readonly BlockingCollection<DBLog> _messageQueue = new BlockingCollection<DBLog>(new ConcurrentQueue<DBLog>());
/// <summary>
/// 添加数据库日志实体类到内部集合中
/// </summary>
/// <param name="log"></param>
public static System.Threading.Tasks.Task AddDBLog(DBLog log) => System.Threading.Tasks.Task.Run(() =>
{
if (!_messageQueue.IsAddingCompleted && !_pause)
{
_messageQueue.Add(log);
}
});
private static bool _pause;
/// <summary>
/// 暂停接收脚本执行日志
/// </summary>
public static void Pause() => _pause = true;
/// <summary>
/// 开始接收脚本执行日志
/// </summary>
public static void Run() => _pause = false;
/// <summary>
/// 查询所有SQL日志信息
/// </summary>
@ -75,33 +46,5 @@ namespace Bootstrap.DataAccess
/// <param name="userName"></param>
/// <returns></returns>
public static Page<DBLog> RetrieveDBLogs(PaginationOption op, DateTime? startTime, DateTime? endTime, string? userName) => DbContextManager.Create<DBLog>()?.RetrievePages(op, startTime, endTime, userName) ?? new Page<DBLog>() { Items = new List<DBLog>() };
/// <summary>
/// 数据库脚本执行日志任务实体类
/// </summary>
public class DbLogTask : ITask
{
/// <summary>
/// 任务执行方法
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public System.Threading.Tasks.Task Execute(CancellationToken cancellationToken)
{
var logs = new List<DBLog>();
while (_messageQueue.TryTake(out var log))
{
if (log != null) logs.Add(log);
if (logs.Count >= 100) break;
}
if (logs.Any())
{
using var db = DbManager.Create(enableLog: false);
db.InsertBatch(logs);
}
return System.Threading.Tasks.Task.CompletedTask;
}
}
#endregion
}
}

View File

@ -2,8 +2,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;
namespace Bootstrap.Client.Controllers.Api

View File

@ -0,0 +1,29 @@
using Xunit;
namespace Bootstrap.Admin
{
/// <summary>
/// 正常系统
/// </summary>
[CollectionDefinition("Login")]
public class BootstrapAdminContext : ICollectionFixture<BALoginWebHost>
{
}
/// <summary>
///
/// </summary>
public class BALoginWebHost : BAWebHost
{
/// <summary>
///
/// </summary>
public BALoginWebHost()
{
var client = CreateClient("Account/Login");
var login = client.LoginAsync();
login.Wait();
}
}
}

View File

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using Xunit;
namespace Bootstrap.Admin
{
[CollectionDefinition("MongoContext")]
public class MongoContext : ICollectionFixture<BAMongoDBWebHost>
{
}
/// <summary>
///
/// </summary>
public class BAMongoDBWebHost : BALoginWebHost
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);
builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair<string, string>[] {
new KeyValuePair<string, string>("DB:0:Enabled", "false"),
new KeyValuePair<string, string>("DB:1:Enabled", "false"),
new KeyValuePair<string, string>("DB:2:Enabled", "false"),
new KeyValuePair<string, string>("DB:3:Enabled", "false"),
new KeyValuePair<string, string>("DB:4:Enabled", "true")
}));
}
}
}

View File

@ -0,0 +1,32 @@
using Longbow.Data;
using Microsoft.AspNetCore.Hosting;
using Xunit;
namespace Bootstrap.Admin
{
/// <summary>
///
/// </summary>
[CollectionDefinition("MySqlContext")]
public class MySqlContext : ICollectionFixture<BAMySqlWebHost>
{
}
/// <summary>
///
/// </summary>
public class BAMySqlWebHost : BALoginWebHost
{
/// <summary>
///
/// </summary>
/// <param name="builder"></param>
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);
builder.ConfigureDatabase(DatabaseProviderType.MySql);
}
}
}

View File

@ -0,0 +1,32 @@
using Longbow.Data;
using Microsoft.AspNetCore.Hosting;
using Xunit;
namespace Bootstrap.Admin
{
/// <summary>
///
/// </summary>
[CollectionDefinition("SQLServerContext")]
public class BootstrapAdminTestContext : ICollectionFixture<BASQLServerWebHost>
{
}
/// <summary>
///
/// </summary>
public class BASQLServerWebHost : BALoginWebHost
{
/// <summary>
///
/// </summary>
/// <param name="builder"></param>
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);
builder.ConfigureDatabase(DatabaseProviderType.SqlServer);
}
}
}

View File

@ -0,0 +1,51 @@
using System.Threading.Tasks;
using Xunit;
namespace Bootstrap.Admin
{
/// <summary>
/// 演示系统
/// </summary>
[CollectionDefinition("SystemModel")]
public class BootstrapAdminDemoContext : ICollectionFixture<BASystemModelWebHost>
{
}
/// <summary>
///
/// </summary>
public class BASystemModelWebHost : BALoginWebHost
{
public BASystemModelWebHost() : base()
{
// 设置系统为演示模式
using var db = Longbow.Data.DbManager.Create();
db.Execute("Update Dicts Set Code = @2 where Category = @0 and Name = @1", "网站设置", "演示系统", "1");
do
{
var task = Task.Delay(500);
task.Wait();
var dict = DataAccess.DictHelper.RetrieveSystemModel();
if (dict) break;
}
while (true);
}
protected override void Dispose(bool disposing)
{
using var db = Longbow.Data.DbManager.Create();
db.Execute("Update Dicts Set Code = @2 where Category = @0 and Name = @1", "网站设置", "演示系统", "0");
do
{
var task = Task.Delay(500);
task.Wait();
var dict = DataAccess.DictHelper.RetrieveSystemModel();
if (!dict) break;
}
while (true);
}
}
}

View File

@ -1,93 +1,31 @@
using Longbow.Data;
using Longbow.Web.SMS;
using Longbow.Web.SMS;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.Mvc.Testing.Handlers;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using UnitTest;
using Xunit;
namespace Bootstrap.Admin
{
[CollectionDefinition("SQLServerContext")]
public class BootstrapAdminTestContext : ICollectionFixture<BAWebHost>
/// <summary>
/// 未登录
/// </summary>
[CollectionDefinition("BA-Logout")]
public class BootstrapAdminLogoutContext : ICollectionFixture<BAWebHost>
{
}
[CollectionDefinition("SQLiteContext")]
public class SQLiteContext : ICollectionFixture<SQLiteBAWebHost>
{
}
[CollectionDefinition("MySqlContext")]
public class MySqlContext : ICollectionFixture<MySqlBAWebHost>
{
}
[CollectionDefinition("MongoContext")]
public class MongoContext : ICollectionFixture<MongoBAWebHost>
{
}
public class MySqlBAWebHost : BAWebHost
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);
TestHelper.ConfigureWebHost(builder, DatabaseProviderType.MySql);
}
}
public class SQLiteBAWebHost : BAWebHost
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);
TestHelper.ConfigureWebHost(builder, DatabaseProviderType.SQLite);
}
}
public class MongoBAWebHost : BAWebHost
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);
builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair<string, string>[] {
new KeyValuePair<string, string>("DB:0:Enabled", "false"),
new KeyValuePair<string, string>("DB:1:Enabled", "false"),
new KeyValuePair<string, string>("DB:2:Enabled", "false"),
new KeyValuePair<string, string>("DB:3:Enabled", "false"),
new KeyValuePair<string, string>("DB:4:Enabled", "true")
}));
}
}
/// <summary>
///
/// </summary>
public class BAWebHost : WebApplicationFactory<Startup>
{
public BAWebHost()
{
var client = CreateClient("Account/Login");
var login = client.LoginAsync();
login.Wait();
}
/// <summary>
/// 获得已经登录的HttpClient
/// </summary>
@ -121,7 +59,6 @@ namespace Bootstrap.Admin
{
builder.ConfigureAppConfiguration(app => app.AddJsonFile(TestHelper.RetrievePath($"UnitTest{Path.DirectorySeparatorChar}appsettings.appveyor.json"), false, true));
}
TestHelper.ConfigureWebHost(builder);
// 替换 SMS 服务
builder.ConfigureServices(services =>
@ -129,39 +66,5 @@ namespace Bootstrap.Admin
services.AddTransient<ISMSProvider, DefaultSMSProvider>();
});
}
/// <summary>
/// 手机号登陆帮助类
/// </summary>
class DefaultSMSProvider : ISMSProvider
{
public DefaultSMSProvider()
{
Options = new SMSOptions();
Options.Roles.Add("Administrators");
Options.Roles.Add("Default");
}
/// <summary>
/// 获得 短信配置信息
/// </summary>
public SMSOptions Options { get; protected set; }
/// <summary>
/// 下发验证码方法
/// </summary>
/// <param name="phoneNumber"></param>
/// <returns></returns>
public Task<SMSResult> SendCodeAsync(string phoneNumber) => Task.FromResult(new SMSResult() { Result = true });
/// <summary>
/// 验证验证码方法
/// </summary>
/// <param name="phone">手机号</param>
/// <param name="code">验证码</param>
/// <returns></returns>
public bool Validate(string phone, string code) => code == "1234";
}
}
}

View File

@ -2,11 +2,11 @@
using Xunit;
using static Bootstrap.Admin.Controllers.Api.AnalyseController;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class AnalyseTest : ControllerTest
{
public AnalyseTest(BAWebHost factory) : base(factory, "api/Analyse") { }
public AnalyseTest(BALoginWebHost factory) : base(factory, "api/Analyse") { }
[Fact]
public async void Get_Ok()

View File

@ -4,11 +4,11 @@ using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class AppsTest : ControllerTest
{
public AppsTest(BAWebHost factory) : base(factory, "api/Apps") { }
public AppsTest(BALoginWebHost factory) : base(factory, "api/Apps") { }
[Fact]
public async void Get_Ok()

View File

@ -4,11 +4,11 @@ using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class CategoryTest : ControllerTest
{
public CategoryTest(BAWebHost factory) : base(factory, "api/Category") { }
public CategoryTest(BALoginWebHost factory) : base(factory, "api/Category") { }
[Fact]
public async void DictCategorys_Ok()

View File

@ -6,11 +6,11 @@ using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class DictTest : ControllerTest
{
public DictTest(BAWebHost factory) : base(factory, "api/Dicts") { }
public DictTest(BALoginWebHost factory) : base(factory, "api/Dicts") { }
[Theory()]
[InlineData("Category", "asc")]
@ -29,6 +29,17 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.Single(qd.rows);
}
[Theory()]
[InlineData("地理")]
[InlineData("Baidu")]
[InlineData("api")]
public async void Search_Ok(string search)
{
// 菜单 系统菜单 系统使用条件
var qd = await Client.GetAsJsonAsync<QueryData<BootstrapDict>>($"?search={search}&sort=&order=&offset=0&limit=20&category=&name=&define=0&_=1547608210979");
Assert.NotEmpty(qd.rows);
}
[Fact]
public async void PostAndDelete_Ok()
{

View File

@ -7,11 +7,11 @@ using System.Net.Http;
using Xunit;
using static Bootstrap.Admin.Controllers.Api.ExceptionsController;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class ExceptionsTest : ControllerTest
{
public ExceptionsTest(BAWebHost factory) : base(factory, "api/Exceptions") { }
public ExceptionsTest(BALoginWebHost factory) : base(factory, "api/Exceptions") { }
[Fact]
public async void Get_Ok()

View File

@ -9,7 +9,7 @@ namespace Bootstrap.Admin.Api
{
public class GiteeTest : ControllerTest
{
public GiteeTest(BAWebHost factory) : base(factory, "api/Gitee") { }
public GiteeTest(BALoginWebHost factory) : base(factory, "api/Gitee") { }
[Fact]
public async void Issues_Ok()

View File

@ -5,11 +5,11 @@ using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class GroupsTest : ControllerTest
{
public GroupsTest(BAWebHost factory) : base(factory, "api/Groups") { }
public GroupsTest(BALoginWebHost factory) : base(factory, "api/Groups") { }
[Fact]
public async void Get_Ok()
@ -22,6 +22,15 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.Single(qd.rows);
}
[Theory()]
[InlineData("Admin")]
[InlineData("系统默认")]
public async void Search_Ok(string search)
{
var qd = await Client.GetAsJsonAsync<QueryData<Group>>($"?search={search}&sort=&order=&offset=0&limit=20&category=&name=&define=0&_=1547608210979");
Assert.NotEmpty(qd.rows);
}
[Fact]
public async void PostAndDelete_Ok()
{

View File

@ -3,11 +3,11 @@ using System.Collections.Generic;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class InterfaceTest : ControllerTest
{
public InterfaceTest(BAWebHost factory) : base(factory, "api/Interface") { }
public InterfaceTest(BALoginWebHost factory) : base(factory, "api/Interface") { }
[Fact]
public async void RetrieveDicts_Ok()

View File

@ -4,11 +4,11 @@ using Longbow.Web.SMS;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class LoginTest : ControllerTest
{
public LoginTest(BAWebHost factory) : base(factory, "api/Login") { }
public LoginTest(BALoginWebHost factory) : base(factory, "api/Login") { }
[Fact]
public async void Login_Get()

View File

@ -4,11 +4,11 @@ using System;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class LogsTest : ControllerTest
{
public LogsTest(BAWebHost factory) : base(factory, "api/Logs") { }
public LogsTest(BALoginWebHost factory) : base(factory, "api/Logs") { }
[Fact]
public async void Get_Ok()

View File

@ -6,11 +6,11 @@ using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class MenusTest : ControllerTest
{
public MenusTest(BAWebHost factory) : base(factory, "api/Menus") { }
public MenusTest(BALoginWebHost factory) : base(factory, "api/Menus") { }
[Theory]
[InlineData("Order", "asc")]
@ -33,6 +33,16 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.Single(qd.rows);
}
[Theory()]
[InlineData("个人中心")]
[InlineData("首页")]
public async void Search_Ok(string search)
{
// 菜单 系统菜单 系统使用条件
var qd = await Client.GetAsJsonAsync<QueryData<object>>($"?search={search}&sort=&order=&offset=0&limit=20&category=&name=&define=0&_=1547608210979");
Assert.NotEmpty(qd.rows);
}
[Fact]
public async void PostAndDelete_Ok()
{

View File

@ -4,11 +4,11 @@ using System.Collections.Generic;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class MessagesTest : ControllerTest
{
public MessagesTest(BAWebHost factory) : base(factory, "api/Messages") { }
public MessagesTest(BALoginWebHost factory) : base(factory, "api/Messages") { }
[Theory]
[InlineData("inbox")]

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class AnalyseTest : SqlServer.AnalyseTest
{
public AnalyseTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class AppsTest : SqlServer.AppsTest
{
public AppsTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class CategoryTest : SqlServer.CategoryTest
{
public CategoryTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class DictTest : SqlServer.DictTest
{
public DictTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class ExceptionsTest : SqlServer.ExceptionsTest
{
public ExceptionsTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class GroupsTest : SqlServer.GroupsTest
{
public GroupsTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class InterfaceTest : SqlServer.InterfaceTest
{
public InterfaceTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class LoginTest : SqlServer.LoginTest
{
public LoginTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class LogsTest : SqlServer.LogsTest
{
public LogsTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class MenusTest : SqlServer.MenusTest
{
public MenusTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class MessagesTest : SqlServer.MessagesTest
{
public MessagesTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class NewTest : SqlServer.NewTest
{
public NewTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class NotificationsTest : SqlServer.NotificationsTest
{
public NotificationsTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class OnlineTest : SqlServer.OnlineTest
{
public OnlineTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class ProfilesTest : SqlServer.ProfilesTest
{
public ProfilesTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class RegisterTest : SqlServer.RegisterTest
{
public RegisterTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class RolesTest : SqlServer.RolesTest
{
public RolesTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class SQLTest : SqlServer.SQLTest
{
public SQLTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class SettingsTest : SqlServer.SettingsTest
{
public SettingsTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class TasksTest : SqlServer.TasksTest
{
public TasksTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class TracesTest : SqlServer.TracesTest
{
public TracesTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.MySql
{
[Collection("MySqlContext")]
public class UsersTest : SqlServer.UsersTest
{
public UsersTest(MySqlBAWebHost factory) : base(factory) { }
}
}

View File

@ -4,11 +4,11 @@ using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class NewTest : ControllerTest
{
public NewTest(BAWebHost factory) : base(factory, "api/New") { }
public NewTest(BALoginWebHost factory) : base(factory, "api/New") { }
[Fact]
public async void Get_Ok()

View File

@ -1,11 +1,11 @@
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class NotificationsTest : ControllerTest
{
public NotificationsTest(BAWebHost factory) : base(factory, "api/Notifications") { }
public NotificationsTest(BALoginWebHost factory) : base(factory, "api/Notifications") { }
[Fact]
public async void Get_Ok()

View File

@ -4,11 +4,11 @@ using System.Collections.Generic;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class OnlineTest : ControllerTest
{
public OnlineTest(BAWebHost factory) : base(factory, "api/OnlineUsers") { }
public OnlineTest(BALoginWebHost factory) : base(factory, "api/OnlineUsers") { }
[Fact]
public async void Get_Ok()

View File

@ -6,11 +6,11 @@ using System.Net.Http.Headers;
using UnitTest;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class ProfilesTest : ControllerTest
{
public ProfilesTest(BAWebHost factory) : base(factory, "api/Profiles") { }
public ProfilesTest(BALoginWebHost factory) : base(factory, "api/Profiles") { }
[Fact]
public async void Put_SaveTheme()

View File

@ -3,11 +3,11 @@ using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class RegisterTest : ControllerTest
{
public RegisterTest(BAWebHost factory) : base(factory, "api/Register") { }
public RegisterTest(BALoginWebHost factory) : base(factory, "api/Register") { }
[Fact]
public async void Get_Ok()

View File

@ -5,11 +5,11 @@ using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class RolesTest : ControllerTest
{
public RolesTest(BAWebHost factory) : base(factory, "api/Roles") { }
public RolesTest(BALoginWebHost factory) : base(factory, "api/Roles") { }
[Theory]
[InlineData("RoleName", "asc")]
@ -21,6 +21,16 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.Single(qd.rows);
}
[Theory()]
[InlineData("Administrators")]
[InlineData("系统管理员")]
public async void Search_Ok(string search)
{
// 菜单 系统菜单 系统使用条件
var qd = await Client.GetAsJsonAsync<QueryData<Role>>($"?search={search}&sort=&order=&offset=0&limit=20&category=&name=&define=0&_=1547608210979");
Assert.NotEmpty(qd.rows);
}
[Fact]
public async void PostAndDelete_Ok()
{

View File

@ -3,11 +3,11 @@ using Longbow.Web.Mvc;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class SQLTest : ControllerTest
{
public SQLTest(BAWebHost factory) : base(factory, "api/SQL") { }
public SQLTest(BALoginWebHost factory) : base(factory, "api/SQL") { }
[Fact]
public async void Get_Ok()

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class AnalyseTest : SqlServer.AnalyseTest
{
public AnalyseTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class AppsTest : SqlServer.AppsTest
{
public AppsTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class CategoryTest : SqlServer.CategoryTest
{
public CategoryTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class DictTest : SqlServer.DictTest
{
public DictTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class ExceptionsTest : SqlServer.ExceptionsTest
{
public ExceptionsTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class GroupsTest : SqlServer.GroupsTest
{
public GroupsTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class InterfaceTest : SqlServer.InterfaceTest
{
public InterfaceTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class LoginTest : SqlServer.LoginTest
{
public LoginTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class LogsTest : SqlServer.LogsTest
{
public LogsTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class MenusTest : SqlServer.MenusTest
{
public MenusTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class MessagesTest : SqlServer.MessagesTest
{
public MessagesTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class NewTest : SqlServer.NewTest
{
public NewTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class NotificationsTest : SqlServer.NotificationsTest
{
public NotificationsTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class OnlineTest : SqlServer.OnlineTest
{
public OnlineTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class ProfilesTest : SqlServer.ProfilesTest
{
public ProfilesTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class RegisterTest : SqlServer.RegisterTest
{
public RegisterTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class RolesTest : SqlServer.RolesTest
{
public RolesTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class SQLTest : SqlServer.SQLTest
{
public SQLTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class SettingsTest : SqlServer.SettingsTest
{
public SettingsTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class TasksTest : SqlServer.TasksTest
{
public TasksTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class TracesTest : SqlServer.TracesTest
{
public TracesTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -1,10 +0,0 @@
using Xunit;
namespace Bootstrap.Admin.Api.SQLite
{
[Collection("SQLiteContext")]
public class UsersTest : SqlServer.UsersTest
{
public UsersTest(SQLiteBAWebHost factory) : base(factory) { }
}
}

View File

@ -6,11 +6,11 @@ using System.Linq;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class SettingsTest : ControllerTest
{
public SettingsTest(BAWebHost factory) : base(factory, "api/Settings") { }
public SettingsTest(BALoginWebHost factory) : base(factory, "api/Settings") { }
[Fact]
public async void Get_Ok()
@ -30,7 +30,9 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.True(DictHelper.Save(new BootstrapDict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "0", Define = 0 }));
// 获得原来值
var resp = await Client.PostAsJsonAsync<BootstrapDict, bool>("", new BootstrapDict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "UnitTest" });
var resp = await Client.PostAsJsonAsync<IEnumerable<BootstrapDict>, bool>("", new BootstrapDict[]{
new BootstrapDict() { Category = "UnitTest-Settings", Name = "UnitTest", Code = "UnitTest" }
});
Assert.True(resp);
var code = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "UnitTest-Settings").Code;

View File

@ -3,11 +3,11 @@ using System.Collections.Generic;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class TasksTest : ControllerTest
{
public TasksTest(BAWebHost factory) : base(factory, "api/Tasks") { }
public TasksTest(BALoginWebHost factory) : base(factory, "api/Tasks") { }
[Fact]
public async void Get_Ok()

View File

@ -5,11 +5,11 @@ using System;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class TracesTest : ControllerTest
{
public TracesTest(BAWebHost factory) : base(factory, "api/Traces") { }
public TracesTest(BALoginWebHost factory) : base(factory, "api/Traces") { }
[Fact]
public async void Get_Ok()

View File

@ -7,11 +7,11 @@ using System.Net;
using System.Net.Http;
using Xunit;
namespace Bootstrap.Admin.Api.SqlServer
namespace Bootstrap.Admin.Api
{
public class UsersTest : ControllerTest
{
public UsersTest(BAWebHost factory) : base(factory, "api/Users") { }
public UsersTest(BALoginWebHost factory) : base(factory, "api/Users") { }
[Fact]
public async void Option_Ok()
@ -39,6 +39,17 @@ namespace Bootstrap.Admin.Api.SqlServer
Assert.Single(qd.rows);
}
[Theory()]
[InlineData("Administrator")]
[InlineData("Admin")]
[InlineData("系统默认创建")]
public async void Search_Ok(string search)
{
// 菜单 系统菜单 系统使用条件
var qd = await Client.GetAsJsonAsync<QueryData<object>>($"?search={search}&sort=&order=&offset=0&limit=20&category=&name=&define=0&_=1547608210979");
Assert.NotEmpty(qd.rows);
}
[Fact]
public async void PostAndDelete_Ok()
{

View File

@ -3,21 +3,18 @@ using Xunit;
namespace Bootstrap.Admin
{
[Collection("SQLServerContext")]
[Collection("Login")]
public class ControllerTest
{
protected HttpClient Client { get; set; }
protected BAWebHost Host { get; set; }
/// <summary>
///
/// </summary>
/// <param name="factory"></param>
/// <param name="baseAddress"></param>
public ControllerTest(BAWebHost factory, string baseAddress = "api")
public ControllerTest(BALoginWebHost factory, string baseAddress = "api")
{
Host = factory;
Client = factory.CreateClient(baseAddress);
}
}

Some files were not shown because too many files have changed in this diff Show More