test: 更新单元测试
This commit is contained in:
parent
601edacebe
commit
22ba715cc4
|
@ -38,7 +38,7 @@
|
|||
|
||||
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" /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" /p:CoverletOutput=..\..\
|
||||
}
|
||||
|
||||
function coverallUnitTest() {
|
||||
|
|
|
@ -118,9 +118,9 @@ namespace Bootstrap.Admin.Controllers
|
|||
{
|
||||
// 根据配置文件设置默认角色
|
||||
var roles = RoleHelper.Retrieves().Where(r => provider.Options.Roles.Any(rl => rl.Equals(r.RoleName, StringComparison.OrdinalIgnoreCase))).Select(r => r.Id);
|
||||
#pragma warning disable CS8620 // 由于引用类型的可为 null 性差异,实参不能用于形参。
|
||||
#nullable disable
|
||||
RoleHelper.SaveByUserId(user.Id, roles);
|
||||
#pragma warning restore CS8620 // 由于引用类型的可为 null 性差异,实参不能用于形参。
|
||||
#nullable restore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,10 +56,10 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
{
|
||||
var filePath = Path.Combine(AppContext.BaseDirectory, "Error");
|
||||
var logName = $"{Path.Combine(filePath, exceptionFile.FileName)}.log";
|
||||
if (!System.IO.File.Exists(logName)) return new JsonResult("无此日志文件");
|
||||
var sb = new StringBuilder();
|
||||
using (var reader = new StreamReader(logName))
|
||||
if (System.IO.File.Exists(logName))
|
||||
{
|
||||
using var reader = new StreamReader(logName);
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
var line = reader.ReadLine()?.Replace("<", "<").Replace(">", ">");
|
||||
|
|
|
@ -64,11 +64,7 @@ namespace Bootstrap.Admin.Controllers
|
|||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IEnumerable<BootstrapMenu> RetrieveAppMenus([FromBody]AppMenuOption args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(args.AppId) || string.IsNullOrEmpty(args.UserName)) return new BootstrapMenu[0];
|
||||
return MenuHelper.RetrieveAppMenus(args.AppId, args.UserName, args.Url);
|
||||
}
|
||||
public IEnumerable<BootstrapMenu> RetrieveAppMenus([FromBody]AppMenuOption args) => MenuHelper.RetrieveAppMenus(args.AppId, args.UserName, args.Url);
|
||||
|
||||
/// <summary>
|
||||
/// 发送健康检查结果
|
||||
|
|
|
@ -84,9 +84,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
var webSiteUrl = DictHelper.RetrieveIconFolderPath();
|
||||
fileName = $"{userName}{Path.GetExtension(uploadFile.FileName)}";
|
||||
var filePath = Path.Combine(env.WebRootPath, webSiteUrl.Replace("~", string.Empty).Replace('/', Path.DirectorySeparatorChar).TrimStart(Path.DirectorySeparatorChar) + fileName);
|
||||
var fileFolder = Path.GetDirectoryName(filePath);
|
||||
fileSize = uploadFile.Length;
|
||||
if (!Directory.Exists(fileFolder)) Directory.CreateDirectory(fileFolder);
|
||||
using (var fs = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
await uploadFile.CopyToAsync(fs);
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Bootstrap.Admin.Models
|
|||
/// <summary>
|
||||
/// 获得 是否为第三方用户
|
||||
/// </summary>
|
||||
/// <remarks>第三方用户不允许修改密码</remarks>
|
||||
public bool External { get; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -32,7 +33,7 @@ namespace Bootstrap.Admin.Models
|
|||
public string AppName { get; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="host"></param>
|
||||
/// <param name="controller"></param>
|
||||
|
|
|
@ -38,8 +38,6 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
/// <returns></returns>
|
||||
public override bool Log(Exception ex, NameValueCollection additionalInfo)
|
||||
{
|
||||
if (ex == null) return true;
|
||||
|
||||
var excep = new DataAccess.Exceptions
|
||||
{
|
||||
Id = null,
|
||||
|
|
|
@ -104,9 +104,6 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
/// <returns></returns>
|
||||
public override bool Save(DataAccess.User user)
|
||||
{
|
||||
// 已经存在或者已经在新用户中了
|
||||
if (UserHelper.RetrieveUserByUserName(user.UserName) != null || UserHelper.RetrieveNewUsers().Any(u => u.UserName == user.UserName)) return false;
|
||||
|
||||
user.PassSalt = LgbCryptography.GenerateSalt();
|
||||
user.Password = LgbCryptography.ComputeHash(user.Password, user.PassSalt);
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
<PackageReference Include="Longbow.Web" Version="3.1.1" />
|
||||
<PackageReference Include="Longbow.WeChatAuth" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="3.1.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.0" />
|
||||
<PackageReference Include="PetaPoco.Extensions" Version="3.1.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -119,7 +119,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="userName"></param>
|
||||
/// <param name="activeUrl"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<BootstrapMenu> RetrieveAppMenus(string appId, string userName, string? activeUrl)
|
||||
public static IEnumerable<BootstrapMenu> RetrieveAppMenus(string? appId, string? userName, string? activeUrl)
|
||||
{
|
||||
if (string.IsNullOrEmpty(appId) || string.IsNullOrEmpty(userName)) return new BootstrapMenu[0];
|
||||
|
||||
|
|
|
@ -105,6 +105,10 @@ namespace Bootstrap.DataAccess
|
|||
public static bool Save(User user)
|
||||
{
|
||||
if (!UserChecker(user)) return false;
|
||||
|
||||
// 已经存在或者已经在新用户中了
|
||||
if (string.IsNullOrEmpty(user.Id) && (RetrieveUserByUserName(user.UserName) != null || RetrieveNewUsers().Any(u => u.UserName == user.UserName))) return false;
|
||||
|
||||
if (DictHelper.RetrieveSystemModel() && !string.IsNullOrEmpty(user.Id) && RetrieveConstUsers().Any(u => u.Id == user.Id)) return true;
|
||||
|
||||
var ret = DbContextManager.Create<User>()?.Save(user) ?? false;
|
||||
|
|
|
@ -136,10 +136,17 @@ namespace Bootstrap.Admin
|
|||
/// </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; } = new SMSOptions();
|
||||
public SMSOptions Options { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下发验证码方法
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
using Xunit;
|
||||
|
||||
namespace Bootstrap.Admin.Api.MySql
|
||||
{
|
||||
[Collection("MySqlContext")]
|
||||
public class AnalyseTest : SqlServer.AnalyseTest
|
||||
{
|
||||
public AnalyseTest(MySqlBAWebHost factory) : base(factory) { }
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
using Xunit;
|
||||
using static Bootstrap.Admin.Controllers.Api.AnalyseController;
|
||||
|
||||
namespace Bootstrap.Admin.Api
|
||||
namespace Bootstrap.Admin.Api.SqlServer
|
||||
{
|
||||
public class AnalyseTest : ControllerTest
|
||||
{
|
|
@ -21,6 +21,7 @@ namespace Bootstrap.Admin.Api.SqlServer
|
|||
[InlineData("Name", "desc")]
|
||||
[InlineData("Code", "desc")]
|
||||
[InlineData("Define", "desc")]
|
||||
[InlineData("", "")]
|
||||
public async void Get_Ok(string query, string order)
|
||||
{
|
||||
// 菜单 系统菜单 系统使用条件
|
||||
|
|
|
@ -64,5 +64,12 @@ namespace Bootstrap.Admin.Api.SqlServer
|
|||
var ret = await Client.PutAsJsonAsync<IEnumerable<string>, bool>($"{rid}", ids);
|
||||
Assert.True(ret);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetrieveAppMenus_Ok()
|
||||
{
|
||||
Assert.Empty(MenuHelper.RetrieveAppMenus("", "", ""));
|
||||
Assert.NotEmpty(MenuHelper.RetrieveAppMenus("Demo", "Admin", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace Bootstrap.Admin.Api.SqlServer
|
|||
{
|
||||
var iconFile = TestHelper.RetrievePath(string.Format("..{0}src{0}admin{0}Bootstrap.Admin{0}wwwroot{0}images{0}logo.jpg", Path.DirectorySeparatorChar));
|
||||
var adminFile = TestHelper.RetrievePath(string.Format("..{0}src{0}admin{0}Bootstrap.Admin{0}wwwroot{0}images{0}uploader{0}Admin.jpg", Path.DirectorySeparatorChar));
|
||||
FileInfo fi = new FileInfo(iconFile);
|
||||
var fi = new FileInfo(iconFile);
|
||||
string fileName = fi.Name;
|
||||
byte[] fileContents = File.ReadAllBytes(fi.FullName);
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ namespace Bootstrap.Admin.Api.SqlServer
|
|||
{
|
||||
var resp = await Client.GetAsJsonAsync<bool>("?userName=Admin");
|
||||
Assert.False(resp);
|
||||
resp = await Client.GetAsJsonAsync<bool>("?userName=Admin1");
|
||||
Assert.True(resp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -23,6 +25,8 @@ namespace Bootstrap.Admin.Api.SqlServer
|
|||
var nusr = new User() { UserName = "U_Register", DisplayName = "UnitTest", Password = "1", Description = "UnitTest" };
|
||||
var resp = await Client.PostAsJsonAsync<User, bool>("", nusr);
|
||||
Assert.True(resp);
|
||||
resp = await Client.GetAsJsonAsync<bool>($"?userName={nusr.UserName}");
|
||||
Assert.False(resp);
|
||||
UserHelper.Delete(nusr.RetrieveNewUsers().Where(u => u.UserName == nusr.UserName).Select(u => u.Id));
|
||||
}
|
||||
|
||||
|
|
|
@ -68,8 +68,18 @@ namespace Bootstrap.Admin.Api.SqlServer
|
|||
ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>($"{gid}?type=group", string.Empty);
|
||||
Assert.NotNull(ret);
|
||||
|
||||
ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>("UnitTest?type=reset", string.Empty);
|
||||
// 创建用户
|
||||
var nusr = new User { UserName = "UnitTest_Reset", Password = "1", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = "default.jpg" };
|
||||
UserHelper.Save(nusr);
|
||||
|
||||
// 申请重置
|
||||
UserHelper.ForgotPassword(new ResetUser() { DisplayName = nusr.DisplayName, Reason = "UnitTest", ResetTime = DateTime.Now, UserName = nusr.UserName });
|
||||
|
||||
// 重置操作
|
||||
ret = await Client.PostAsJsonAsync<string, IEnumerable<object>>($"{nusr.UserName}?type=reset", string.Empty);
|
||||
Assert.NotNull(ret);
|
||||
|
||||
UserHelper.Delete(UserHelper.Retrieves().Where(usr => usr.UserName == nusr.UserName).Select(usr => usr.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
using Xunit;
|
||||
|
||||
namespace Bootstrap.Admin.Api.SQLite
|
||||
{
|
||||
[Collection("SQLiteContext")]
|
||||
public class AnalyseTest : SqlServer.AnalyseTest
|
||||
{
|
||||
public AnalyseTest(SQLiteBAWebHost factory) : base(factory) { }
|
||||
}
|
||||
}
|
|
@ -27,6 +27,36 @@ namespace Bootstrap.Admin.Controllers.SqlServer
|
|||
Assert.Contains("演示系统", source);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Login_Empty()
|
||||
{
|
||||
var client = Host.CreateClient();
|
||||
var r = await client.GetAsync("/Account/Login");
|
||||
Assert.True(r.IsSuccessStatusCode);
|
||||
var content = await r.Content.ReadAsStringAsync();
|
||||
Assert.Contains("登 录", content);
|
||||
|
||||
r = await client.GetAsync("/Account/Login");
|
||||
var view = await r.Content.ReadAsStringAsync();
|
||||
var tokenTag = "<input name=\"__RequestVerificationToken\" type=\"hidden\" value=\"";
|
||||
var index = view.IndexOf(tokenTag);
|
||||
view = view.Substring(index + tokenTag.Length);
|
||||
index = view.IndexOf("\" /></form>");
|
||||
var antiToken = view.Substring(0, index);
|
||||
|
||||
var loginContent = new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent(""), "userName" },
|
||||
{ new StringContent(""), "password" },
|
||||
{ new StringContent(""), "remember" },
|
||||
{ new StringContent(antiToken), "__RequestVerificationToken" }
|
||||
};
|
||||
var req = await client.PostAsync("/Account/Login", loginContent);
|
||||
Assert.Equal(HttpStatusCode.OK, req.StatusCode);
|
||||
content = await req.Content.ReadAsStringAsync();
|
||||
Assert.Contains("登 录", content);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Login_Fail()
|
||||
{
|
||||
|
@ -51,16 +81,29 @@ namespace Bootstrap.Admin.Controllers.SqlServer
|
|||
{ new StringContent("true"), "remember" },
|
||||
{ new StringContent(antiToken), "__RequestVerificationToken" }
|
||||
};
|
||||
var req = await client.PostAsync("/Account/Login", loginContent);
|
||||
Assert.Equal(HttpStatusCode.OK, req.StatusCode);
|
||||
}
|
||||
r = await client.PostAsync("/Account/Login", loginContent);
|
||||
Assert.Equal(HttpStatusCode.OK, r.StatusCode);
|
||||
content = await r.Content.ReadAsStringAsync();
|
||||
Assert.Contains("登 录", content);
|
||||
|
||||
[Fact]
|
||||
public async void Login_Admin()
|
||||
{
|
||||
var resp = await Client.GetAsync("Login");
|
||||
var context = await resp.Content.ReadAsStringAsync();
|
||||
Assert.Contains("注销", context);
|
||||
// 空密码登陆
|
||||
view = await r.Content.ReadAsStringAsync();
|
||||
tokenTag = "<input name=\"__RequestVerificationToken\" type=\"hidden\" value=\"";
|
||||
index = view.IndexOf(tokenTag);
|
||||
view = view.Substring(index + tokenTag.Length);
|
||||
index = view.IndexOf("\" /></form>");
|
||||
antiToken = view.Substring(0, index);
|
||||
loginContent = new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent(""), "userName" },
|
||||
{ new StringContent(""), "password" },
|
||||
{ new StringContent(""), "remember" },
|
||||
{ new StringContent(antiToken), "__RequestVerificationToken" }
|
||||
};
|
||||
r = await client.PostAsync("/Account/Login", loginContent);
|
||||
Assert.Equal(HttpStatusCode.OK, r.StatusCode);
|
||||
content = await r.Content.ReadAsStringAsync();
|
||||
Assert.Contains("登 录", content);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -97,11 +140,22 @@ namespace Bootstrap.Admin.Controllers.SqlServer
|
|||
content = await r.Content.ReadAsStringAsync();
|
||||
Assert.Contains("登 录", content);
|
||||
|
||||
// 调用Post
|
||||
// 调用 Post Mobile
|
||||
var data = new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent("13800010001"), "userName" },
|
||||
{ new StringContent("1234"), "password" },
|
||||
{ new StringContent("Mobile"), "authType" }
|
||||
};
|
||||
await Client.PostAsync("Lock", data);
|
||||
UserHelper.Delete(UserHelper.Retrieves().Where(u => u.UserName == "13800010001").Select(u => u.Id));
|
||||
|
||||
// 调用Post
|
||||
data = new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent("Admin"), "userName" },
|
||||
{ new StringContent("123789"), "password" }
|
||||
{ new StringContent("123789"), "password" },
|
||||
{ new StringContent("Cookie"), "authType" }
|
||||
};
|
||||
await Client.PostAsync("Lock", data);
|
||||
}
|
||||
|
@ -139,9 +193,21 @@ namespace Bootstrap.Admin.Controllers.SqlServer
|
|||
{ new StringContent(antiToken), "__RequestVerificationToken" }
|
||||
};
|
||||
var m = await client.PostAsync("/Account/Mobile", content);
|
||||
Assert.False(m.IsSuccessStatusCode);
|
||||
var payload = await r.Content.ReadAsStringAsync();
|
||||
Assert.Contains("登 录", payload);
|
||||
Assert.True(m.IsSuccessStatusCode);
|
||||
var payload = await m.Content.ReadAsStringAsync();
|
||||
Assert.DoesNotContain("登 录", payload);
|
||||
|
||||
// login as cookie
|
||||
// 调用Post
|
||||
var data = new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent("Admin"), "userName" },
|
||||
{ new StringContent("123789"), "password" },
|
||||
{ new StringContent("Cookie"), "authType" }
|
||||
};
|
||||
m = await Client.PostAsync("Lock", data);
|
||||
payload = await m.Content.ReadAsStringAsync();
|
||||
Assert.DoesNotContain("登 录", payload);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -166,7 +232,7 @@ namespace Bootstrap.Admin.Controllers.SqlServer
|
|||
};
|
||||
var m = await client.PostAsync("/Account/Mobile?AppId=0", content);
|
||||
Assert.True(m.IsSuccessStatusCode);
|
||||
var payload = await r.Content.ReadAsStringAsync();
|
||||
var payload = await m.Content.ReadAsStringAsync();
|
||||
Assert.Contains("登 录", payload);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,13 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
[Collection("MongoContext")]
|
||||
public class UsersTest : SqlServer.UsersTest
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public void RejectUser_Ok()
|
||||
{
|
||||
var user = new RejectUser()
|
||||
{
|
||||
Id = ""
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
Assert.NotNull(ExceptionsHelper.RetrievePages(new PaginationOption() { Offset = 0, Limit = 20, Sort = "ErrorPage", Order = "desc" }, null, null));
|
||||
Assert.NotNull(ExceptionsHelper.RetrievePages(new PaginationOption() { Offset = 0, Limit = 20, Sort = "UserId", Order = "desc" }, null, null));
|
||||
Assert.NotNull(ExceptionsHelper.RetrievePages(new PaginationOption() { Offset = 0, Limit = 20, Sort = "UserIp", Order = "desc" }, null, null));
|
||||
Assert.NotNull(ExceptionsHelper.RetrievePages(new PaginationOption() { Offset = 0, Limit = 20, Sort = "UserIp", Order = "desc" }, DateTime.Now.AddDays(-1), DateTime.Now));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Longbow.Web.Mvc;
|
||||
using Xunit;
|
||||
using System;
|
||||
|
||||
namespace Bootstrap.DataAccess.SqlServer
|
||||
{
|
||||
|
@ -25,7 +26,8 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
Assert.NotNull(LogHelper.RetrievePages(new PaginationOption() { Limit = 20, Sort = "UserName", Order = "desc" }, null, null, null));
|
||||
Assert.NotNull(LogHelper.RetrievePages(new PaginationOption() { Limit = 20, Sort = "Ip", Order = "desc" }, null, null, null));
|
||||
Assert.NotNull(LogHelper.RetrievePages(new PaginationOption() { Limit = 20, Sort = "RequestUrl", Order = "desc" }, null, null, null));
|
||||
Assert.NotEmpty(LogHelper.RetrieveAll(null, null, null));
|
||||
Assert.NotNull(LogHelper.RetrievePages(new PaginationOption() { Limit = 20, Sort = "RequestUrl", Order = "desc" }, DateTime.Now.AddDays(-1), DateTime.Now, "UnitTest"));
|
||||
Assert.NotEmpty(LogHelper.RetrieveAll(DateTime.Now.AddDays(-1), DateTime.Now, "UnitTest"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
public void RetrieveAllMenus_Ok()
|
||||
{
|
||||
Assert.NotEmpty(MenuHelper.RetrieveAllMenus("Admin"));
|
||||
Assert.Empty(MenuHelper.RetrieveAllMenus("_UnitTest"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Bootstrap.Security.Mvc;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
|
@ -82,6 +83,12 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
var id = RoleHelper.Retrieves().FirstOrDefault(r => r.RoleName == "Administrators").Id;
|
||||
UserHelper.SaveByRoleId(id, UserHelper.Retrieves().Select(u => u.Id));
|
||||
Assert.NotEmpty(RoleHelper.RetrievesByUserName("Admin"));
|
||||
|
||||
// 新建用户 默认角色为 Default
|
||||
var user = new User { UserName = "UserForRoleTest", Password = "123", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = "" };
|
||||
Assert.True(UserHelper.Save(user));
|
||||
Assert.Single(RoleHelper.RetrievesByUserName(user.UserName));
|
||||
Assert.True(UserHelper.Delete(UserHelper.Retrieves().Where(usr => usr.UserName == user.UserName).Select(usr => usr.Id)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -28,7 +28,8 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
Assert.NotNull(TraceHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0, Order = "desc", Sort = "Browser" }, null, null, null).Items);
|
||||
Assert.NotNull(TraceHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0, Order = "desc", Sort = "OS" }, null, null, null).Items);
|
||||
Assert.NotNull(TraceHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0, Order = "desc", Sort = "RequestUrl" }, null, null, null).Items);
|
||||
Assert.NotEmpty(TraceHelper.RetrieveAll(null, null, null));
|
||||
Assert.NotNull(TraceHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0, Order = "desc", Sort = "RequestUrl" }, DateTime.Now.AddDays(-1), DateTime.Now, "::1").Items);
|
||||
Assert.NotEmpty(TraceHelper.RetrieveAll(DateTime.Now.AddDays(-1), DateTime.Now, "::1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
public void Authenticate_Fail()
|
||||
{
|
||||
Assert.False(UserHelper.Authenticate("Admin-NotExists", "123789"));
|
||||
Assert.False(UserHelper.Authenticate("", ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -73,6 +74,10 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
var user = new User { UserName = "UnitTestDelete", Password = "123", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = "default.jpg" };
|
||||
Assert.Equal($"{user.UserName} ({user.DisplayName})", user.ToString());
|
||||
Assert.True(UserHelper.Save(user));
|
||||
|
||||
// 二次保存时返回 false
|
||||
user.Id = null;
|
||||
Assert.False(UserHelper.Save(user));
|
||||
Assert.True(UserHelper.Delete(UserHelper.Retrieves().Where(usr => usr.UserName == user.UserName).Select(usr => usr.Id)));
|
||||
}
|
||||
|
||||
|
@ -136,6 +141,13 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
{
|
||||
var usr = UserHelper.RetrieveUserByUserName("Admin");
|
||||
Assert.Equal("Administrator", usr.DisplayName);
|
||||
|
||||
// 新建用户 默认角色为 Default
|
||||
var user = new User { UserName = "UnitTest_ICON", Password = "123", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = "" };
|
||||
Assert.True(UserHelper.Save(user));
|
||||
var u = UserHelper.RetrieveUserByUserName(user.UserName);
|
||||
Assert.Equal("default.jpg", u.Icon);
|
||||
Assert.True(UserHelper.Delete(UserHelper.Retrieves().Where(usr => usr.UserName == user.UserName).Select(usr => usr.Id)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -169,7 +181,7 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
[Fact]
|
||||
public void RetrieveLoginUsers_Ok()
|
||||
{
|
||||
var data = LoginHelper.RetrieveAll(null, null, "");
|
||||
var data = LoginHelper.RetrieveAll(DateTime.Now.AddDays(-1), DateTime.Now, "::1");
|
||||
Assert.NotNull(data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,8 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
SetSystemMode();
|
||||
var user = UserHelper.Retrieves().FirstOrDefault(m => m.UserName == "User");
|
||||
user.DisplayName = "UnitTest";
|
||||
|
||||
// 演示模式下不允许更改 Admin User 账户信息
|
||||
Assert.True(UserHelper.Save(user));
|
||||
|
||||
CacheManager.Clear(UserHelper.RetrieveUsersDataKey);
|
||||
|
|
|
@ -7,11 +7,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.msbuild" Version="2.8.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="1.2.0">
|
||||
<PackageReference Include="coverlet.msbuild" Version="2.7.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
],
|
||||
"AppId": "BA",
|
||||
"GiteeHealthChecks": true,
|
||||
"HealthsCloudUrl": "api/Interface/Healths",
|
||||
"HealthsCloudUrl": "",
|
||||
"GiteeOptions": {
|
||||
"Enabled": false
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue