test(AppTest): 增加单元测试覆盖率
This commit is contained in:
parent
bd8a0d518c
commit
db942d6621
|
@ -31,29 +31,20 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
var previewUrl = string.Empty;
|
||||
long fileSize = 0;
|
||||
var userName = User.Identity.Name;
|
||||
var error = string.Empty;
|
||||
var fileName = files.Key;
|
||||
|
||||
fileName = Path.Combine(env.WebRootPath, $"images{Path.DirectorySeparatorChar}uploader{Path.DirectorySeparatorChar}{fileName}");
|
||||
try
|
||||
{
|
||||
if (System.IO.File.Exists(fileName)) System.IO.File.Delete(fileName);
|
||||
fileName = "default.jpg";
|
||||
var webSiteUrl = DictHelper.RetrieveIconFolderPath();
|
||||
var filePath = Path.Combine(env.WebRootPath, webSiteUrl.Replace("~", string.Empty).Replace('/', Path.DirectorySeparatorChar).TrimStart(Path.DirectorySeparatorChar) + fileName);
|
||||
fileSize = new FileInfo(filePath).Length;
|
||||
var iconName = $"{fileName}?v={DateTime.Now.Ticks}";
|
||||
previewUrl = Url.Content($"{webSiteUrl}{iconName}");
|
||||
UserHelper.SaveUserIconByName(userName, iconName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.Message;
|
||||
}
|
||||
if (System.IO.File.Exists(fileName)) System.IO.File.Delete(fileName);
|
||||
fileName = "default.jpg";
|
||||
var webSiteUrl = DictHelper.RetrieveIconFolderPath();
|
||||
var filePath = Path.Combine(env.WebRootPath, webSiteUrl.Replace("~", string.Empty).Replace('/', Path.DirectorySeparatorChar).TrimStart(Path.DirectorySeparatorChar) + fileName);
|
||||
fileSize = new FileInfo(filePath).Length;
|
||||
var iconName = $"{fileName}?v={DateTime.Now.Ticks}";
|
||||
previewUrl = Url.Content($"{webSiteUrl}{iconName}");
|
||||
UserHelper.SaveUserIconByName(userName, iconName);
|
||||
|
||||
return new JsonResult(new
|
||||
{
|
||||
error = string.IsNullOrEmpty(error) ? error : $"服务器端错误-{error}",
|
||||
initialPreview = new string[] { previewUrl },
|
||||
initialPreviewConfig = new object[] {
|
||||
new { caption = "", size = fileSize, showZoom = true, key = "default.jpg" }
|
||||
|
@ -86,7 +77,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
var previewUrl = string.Empty;
|
||||
long fileSize = 0;
|
||||
var userName = User.Identity.Name;
|
||||
var error = string.Empty;
|
||||
var fileName = string.Empty;
|
||||
if (files.Files.Count > 0)
|
||||
{
|
||||
|
@ -107,7 +97,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
}
|
||||
return new JsonResult(new
|
||||
{
|
||||
error = string.IsNullOrEmpty(error) ? error : $"服务器端错误-{error}",
|
||||
initialPreview = new string[] { previewUrl },
|
||||
initialPreviewConfig = new object[] {
|
||||
new { caption = "新头像", size = fileSize, showZoom = true, key = fileName }
|
||||
|
|
|
@ -58,8 +58,6 @@ namespace Bootstrap.Admin.Query
|
|||
case "Define":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.Define) : data.OrderByDescending(t => t.Define);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ret.rows = data.Skip(Offset).Take(Limit);
|
||||
return ret;
|
||||
|
|
|
@ -52,8 +52,6 @@ namespace Bootstrap.Admin.Query
|
|||
case "ApprovedBy":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.ApprovedBy) : data.OrderByDescending(t => t.ApprovedBy);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ret.rows = data.Skip(Offset).Take(Limit).Select(u => new
|
||||
{
|
||||
|
|
|
@ -16,10 +16,11 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
private static IMongoDatabase _db = null;
|
||||
private static bool _register = false;
|
||||
private static readonly object _locker = new object();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static IMongoDatabase DBAccess
|
||||
private static IMongoDatabase DBAccess
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -160,6 +161,28 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
return DBAccess.GetCollection<RejectUser>("RejectUsers");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static IMongoCollection<DataAccess.Message> Messages
|
||||
{
|
||||
get
|
||||
{
|
||||
return DBAccess.GetCollection<DataAccess.Message>("Messages");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static IMongoCollection<DataAccess.Task> Tasks
|
||||
{
|
||||
get
|
||||
{
|
||||
return DBAccess.GetCollection<DataAccess.Task>("Tasks");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private static void InitDb()
|
||||
|
@ -235,24 +258,6 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
md.UnmapMember(role => role.Checked);
|
||||
});
|
||||
}
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Task)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DataAccess.Task>(md =>
|
||||
{
|
||||
md.AutoMap();
|
||||
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
|
||||
md.IdMemberMap.SetIgnoreIfDefault(true);
|
||||
});
|
||||
}
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Message)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DataAccess.Message>(md =>
|
||||
{
|
||||
md.AutoMap();
|
||||
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
|
||||
md.IdMemberMap.SetIgnoreIfDefault(true);
|
||||
});
|
||||
}
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Exceptions)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DataAccess.Exceptions>(md =>
|
||||
|
@ -307,6 +312,29 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
md.IdMemberMap.SetIgnoreIfDefault(true);
|
||||
});
|
||||
}
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Message)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DataAccess.Message>(md =>
|
||||
{
|
||||
md.AutoMap();
|
||||
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
|
||||
md.IdMemberMap.SetIgnoreIfDefault(true);
|
||||
md.UnmapMember(t => t.LabelName);
|
||||
md.UnmapMember(t => t.Period);
|
||||
md.UnmapMember(t => t.FromIcon);
|
||||
md.UnmapMember(t => t.FromDisplayName);
|
||||
});
|
||||
}
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Task)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DataAccess.Task>(md =>
|
||||
{
|
||||
md.AutoMap();
|
||||
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
|
||||
md.IdMemberMap.SetIgnoreIfDefault(true);
|
||||
md.UnmapMember(t => t.AssignDisplayName);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
{
|
||||
p.Id = null;
|
||||
DbManager.Dicts.InsertOne(p);
|
||||
return true;
|
||||
p.Id = DbManager.Dicts.Find(d => d.Name == p.Name && d.Category == p.Category && d.Define == p.Define && d.Code == p.Code).FirstOrDefault().Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -51,8 +51,8 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
.Set(md => md.Define, p.Define)
|
||||
.Set(md => md.Name, p.Name)
|
||||
.Set(md => md.Code, p.Code));
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -32,13 +32,13 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
{
|
||||
if (string.IsNullOrEmpty(p.Id))
|
||||
{
|
||||
p.Id = null;
|
||||
DbManager.Groups.InsertOne(new Group()
|
||||
{
|
||||
GroupName = p.GroupName,
|
||||
Description = p.Description,
|
||||
Roles = new List<string>()
|
||||
});
|
||||
p.Id = DbManager.Groups.Find(g => g.GroupName == p.GroupName && g.Description == p.Description).FirstOrDefault().Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -68,6 +68,7 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
private static void DeleteLogAsync() => System.Threading.Tasks.Task.Run(() => DbManager.Logs.DeleteMany(log => log.LogTime < DateTime.Now.AddDays(-7)));
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -75,8 +76,8 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
/// <returns></returns>
|
||||
public override bool Save(DataAccess.Log log)
|
||||
{
|
||||
log.LogTime = DateTime.Now;
|
||||
DbManager.Logs.InsertOne(log);
|
||||
DeleteLogAsync();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
{
|
||||
p.Id = null;
|
||||
DbManager.Menus.InsertOne(p);
|
||||
return true;
|
||||
p.Id = DbManager.Menus.Find(m => m.Name == p.Name && m.Category == p.Category && m.ParentId == p.ParentId && m.Url == p.Url).FirstOrDefault().Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -53,8 +53,8 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
.Set(md => md.IsResource, p.IsResource)
|
||||
.Set(md => md.Application, p.Application);
|
||||
DbManager.Menus.UpdateOne(md => md.Id == p.Id, update);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -15,8 +15,18 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
/// <returns></returns>
|
||||
protected override IEnumerable<DataAccess.Message> Retrieves(string userName)
|
||||
{
|
||||
var msg = DbManager.DBAccess.GetCollection<DataAccess.Message>("Messages");
|
||||
return msg.Find(message => message.To == userName || message.From == userName).ToList();
|
||||
return DbManager.Messages.Find(message => message.To.ToLowerInvariant() == userName.ToLowerInvariant() || message.From.ToLowerInvariant() == userName.ToLowerInvariant()).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
/// <returns></returns>
|
||||
public override bool Save(DataAccess.Message msg)
|
||||
{
|
||||
DbManager.Messages.InsertOne(msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,10 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override bool Save()
|
||||
public override bool Save(DataAccess.ResetUser user)
|
||||
{
|
||||
DbManager.ResetUsers.InsertOne(this);
|
||||
DbManager.Users.UpdateOne(md => md.UserName.ToLowerInvariant() == user.UserName.ToLowerInvariant(), Builders<User>.Update.Set(md => md.IsReset, 1));
|
||||
DbManager.ResetUsers.InsertOne(user);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
{
|
||||
if (string.IsNullOrEmpty(p.Id))
|
||||
{
|
||||
p.Id = null;
|
||||
DbManager.Roles.InsertOne(new Role()
|
||||
{
|
||||
RoleName = p.RoleName,
|
||||
|
@ -46,13 +45,13 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
Menus = new List<string>(),
|
||||
Apps = new List<string>()
|
||||
});
|
||||
return true;
|
||||
p.Id = DbManager.Roles.Find(r => r.RoleName == p.RoleName && r.Description == p.Description).FirstOrDefault().Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbManager.Roles.UpdateOne(md => md.Id == p.Id, Builders<Role>.Update.Set(md => md.RoleName, p.RoleName).Set(md => md.Description, p.Description));
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -12,10 +12,17 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override IEnumerable<DataAccess.Task> Retrieves()
|
||||
public override IEnumerable<DataAccess.Task> Retrieves() => DbManager.Tasks.Find(FilterDefinition<DataAccess.Task>.Empty).SortByDescending(task => task.AssignTime).ToList();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="task"></param>
|
||||
/// <returns></returns>
|
||||
public override bool Save(DataAccess.Task task)
|
||||
{
|
||||
var users = DbManager.DBAccess.GetCollection<DataAccess.Task>("Tasks");
|
||||
return users.Find(FilterDefinition<DataAccess.Task>.Empty).SortByDescending(task => task.AssignTime).ToList();
|
||||
DbManager.Tasks.InsertOne(task);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
public override bool SaveApp(string userName, string app)
|
||||
{
|
||||
var update = Builders<User>.Update.Set(u => u.App, app);
|
||||
DbManager.Users.FindOneAndUpdate(u => u.UserName.ToLowerInvariant() == UserName.ToLowerInvariant(), update);
|
||||
DbManager.Users.FindOneAndUpdate(u => u.UserName.ToLowerInvariant() == userName.ToLowerInvariant(), update);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -253,19 +253,6 @@ namespace Bootstrap.DataAccess.MongoDB
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public override bool ForgotPassword(DataAccess.ResetUser user)
|
||||
{
|
||||
DbManager.Users.UpdateOne(md => md.UserName.ToLowerInvariant() == user.UserName.ToLowerInvariant(), Builders<User>.Update.Set(md => md.IsReset, 1));
|
||||
user.ResetTime = DateTime.Now;
|
||||
DbManager.ResetUsers.InsertOne(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -20,8 +20,12 @@ namespace Bootstrap.DataAccess
|
|||
/// <summary>
|
||||
/// 保存新增的日志信息
|
||||
/// </summary>
|
||||
/// <param name="p"></param>
|
||||
/// <param name="log"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Save(Log p) => DbContextManager.Create<Log>().Save(p);
|
||||
public static bool Save(Log log)
|
||||
{
|
||||
log.LogTime = DateTime.Now;
|
||||
return DbContextManager.Create<Log>().Save(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,12 +36,14 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Message> Mark(string userName) => DbContextManager.Create<Message>().Flag(userName);
|
||||
public static IEnumerable<Message> Mark(string userName) => DbContextManager.Create<Message>().Mark(userName);
|
||||
/// <summary>
|
||||
/// 获取Header处显示的消息列表
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Message> Retrieves(string userName) => CacheManager.GetOrAdd(RetrieveMessageDataKey, key => DbContextManager.Create<Message>().RetrieveHeaders(userName).OrderByDescending(n => n.SendTime));
|
||||
|
||||
public static bool Save(Message msg) => DbContextManager.Create<Message>().Save(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
using Longbow.Data;
|
||||
using System;
|
||||
|
||||
namespace Bootstrap.DataAccess
|
||||
{
|
||||
/// <summary>
|
||||
/// 重置用户操作类
|
||||
/// </summary>
|
||||
public static class ResetUserHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 保存需要重置用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool Save(ResetUser user)
|
||||
{
|
||||
user.ResetTime = DateTime.Now;
|
||||
return DbContextManager.Create<ResetUser>().Save(user);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,5 +19,12 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Task> Retrieves() => CacheManager.GetOrAdd(RetrieveTasksDataKey, key => DbContextManager.Create<Task>().Retrieves());
|
||||
|
||||
/// <summary>
|
||||
/// 保存任务方法
|
||||
/// </summary>
|
||||
/// <param name="task"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Save(Task task) => DbContextManager.Create<Task>().Save(task);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,10 +166,11 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// 重置密码方法
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <remarks>用户使用忘记密码功能后,管理员在用户管理页面中可以点击重置按钮</remarks>
|
||||
/// <returns></returns>
|
||||
public static bool ResetPassword(string userName, string password)
|
||||
{
|
||||
|
|
|
@ -62,7 +62,6 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
if (p == null) throw new ArgumentNullException(nameof(p));
|
||||
DeleteLogAsync();
|
||||
p.LogTime = DateTime.Now;
|
||||
DbManager.Create().Save(p);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using PetaPoco;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -7,6 +8,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[TableName("Messages")]
|
||||
public class Message
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -47,7 +49,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <summary>
|
||||
/// 标旗状态:0-未标旗,1-已标旗
|
||||
/// </summary>
|
||||
public int Mark { get; set; }
|
||||
public int Flag { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 删除状态:0-未删除,1-已删除
|
||||
|
@ -62,21 +64,25 @@ namespace Bootstrap.DataAccess
|
|||
/// <summary>
|
||||
/// 获得/设置 标签名称
|
||||
/// </summary>
|
||||
[ResultColumn]
|
||||
public string LabelName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 时间描述 2分钟内为刚刚
|
||||
/// </summary>
|
||||
[ResultColumn]
|
||||
public string Period { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 发件人头像
|
||||
/// </summary>
|
||||
[ResultColumn]
|
||||
public string FromIcon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 发件人昵称
|
||||
/// </summary>
|
||||
[ResultColumn]
|
||||
public string FromDisplayName { get; set; }
|
||||
|
||||
//TODO: SQL语句不兼容
|
||||
|
@ -130,10 +136,10 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Message> Flag(string userName)
|
||||
public virtual IEnumerable<Message> Mark(string userName)
|
||||
{
|
||||
var messageRet = Retrieves(userName);
|
||||
return messageRet.Where(n => n.Mark == 1);
|
||||
return messageRet.Where(n => n.Flag == 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -154,5 +160,15 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
return messageRet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool Save(Message msg)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,9 +40,9 @@ namespace Bootstrap.DataAccess
|
|||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual bool Save()
|
||||
public virtual bool Save(ResetUser user)
|
||||
{
|
||||
DbManager.Create().Save(this);
|
||||
DbManager.Create().Save(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <summary>
|
||||
/// 获得/设置 分配人昵称
|
||||
/// </summary>
|
||||
[ResultColumn]
|
||||
public string AssignDisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -55,5 +56,16 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Task> Retrieves() => DbManager.Create().SkipTake<Task>(0, 1000, "select t.*, u.DisplayName AssignDisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc");
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="task"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool Save(Task task)
|
||||
{
|
||||
DbManager.Create().Save(task);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using Bootstrap.Security;
|
||||
using Bootstrap.Security.DataAccess;
|
||||
using Longbow.Data;
|
||||
using Longbow.Security.Cryptography;
|
||||
using PetaPoco;
|
||||
using System;
|
||||
|
@ -196,11 +195,7 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool ForgotPassword(ResetUser user)
|
||||
{
|
||||
user.ResetTime = DateTime.Now;
|
||||
return user.Save();
|
||||
}
|
||||
public virtual bool ForgotPassword(ResetUser user) => ResetUserHelper.Save(user);
|
||||
|
||||
/// <summary>
|
||||
/// 新建前台User View调用/注册用户调用
|
||||
|
|
|
@ -117,27 +117,14 @@ namespace Bootstrap.Admin
|
|||
base.ConfigureWebHost(builder);
|
||||
|
||||
var config = new ConfigurationBuilder();
|
||||
config.AddJsonFile(TestHelper.RetrievePath($"UnitTest{Path.DirectorySeparatorChar}appsettings.json"), false, true);
|
||||
config.AddEnvironmentVariables();
|
||||
var con = config.Build();
|
||||
|
||||
builder.ConfigureAppConfiguration(app => app.AddJsonFile(TestHelper.RetrievePath($"UnitTest{Path.DirectorySeparatorChar}appsettings.json"), false, true));
|
||||
if (con.GetValue("Appveyor", false))
|
||||
{
|
||||
TestHelper.SQLServerConnectionString = con.GetConnectionString("sqlserver-app");
|
||||
TestHelper.MySqlConnectionString = con.GetConnectionString("mysql-app");
|
||||
TestHelper.NpgSqlConnectionString = con.GetConnectionString("npgsql-app");
|
||||
builder.ConfigureAppConfiguration(app => app.AddJsonFile(TestHelper.RetrievePath($"UnitTest{Path.DirectorySeparatorChar}appsettings.appveyor.json"), false, true));
|
||||
}
|
||||
else
|
||||
{
|
||||
TestHelper.SQLServerConnectionString = con.GetConnectionString("sqlserver");
|
||||
TestHelper.MySqlConnectionString = con.GetConnectionString("mysql");
|
||||
TestHelper.NpgSqlConnectionString = con.GetConnectionString("npgsql");
|
||||
builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair<string, string>[] {
|
||||
new KeyValuePair<string, string>("MongoDB", con.GetValue("MongoDB", "UnitTest"))
|
||||
}));
|
||||
}
|
||||
builder.ConfigureAppConfiguration(app => app.AddJsonFile(TestHelper.RetrievePath($"UnitTest{Path.DirectorySeparatorChar}appsettings.unittest.json"), false, true));
|
||||
TestHelper.SQLiteConnectionString = con.GetConnectionString("sqlite");
|
||||
TestHelper.ConfigureWebHost(builder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,18 @@ namespace Bootstrap.Admin.Api.SqlServer
|
|||
var query = "?sort=Category&order=asc&offset=0&limit=20&category=%E8%8F%9C%E5%8D%95&name=%E7%B3%BB%E7%BB%9F%E8%8F%9C%E5%8D%95&define=0&_=1547608210979";
|
||||
var qd = await Client.GetAsJsonAsync<QueryData<BootstrapDict>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=Name&order=asc&offset=0&limit=20&category=%E8%8F%9C%E5%8D%95&name=%E7%B3%BB%E7%BB%9F%E8%8F%9C%E5%8D%95&define=0&_=1547608210979";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<BootstrapDict>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=Code&order=asc&offset=0&limit=20&category=%E8%8F%9C%E5%8D%95&name=%E7%B3%BB%E7%BB%9F%E8%8F%9C%E5%8D%95&define=0&_=1547608210979";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<BootstrapDict>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=Define&order=asc&offset=0&limit=20&category=%E8%8F%9C%E5%8D%95&name=%E7%B3%BB%E7%BB%9F%E8%8F%9C%E5%8D%95&define=0&_=1547608210979";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<BootstrapDict>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
using Xunit;
|
||||
|
||||
namespace Bootstrap.Admin.Api.SqlServer
|
||||
{
|
||||
public class GiteeTest : ControllerTest
|
||||
{
|
||||
public GiteeTest(BAWebHost factory) : base(factory, "api/Gitee") { }
|
||||
|
||||
[Fact]
|
||||
public async void Issues_Ok()
|
||||
{
|
||||
var cates = await Client.GetAsJsonAsync<object>("Issues");
|
||||
Assert.NotNull(cates);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Pulls_Ok()
|
||||
{
|
||||
var cates = await Client.GetAsJsonAsync<object>("Pulls");
|
||||
Assert.NotNull(cates);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Releases_Ok()
|
||||
{
|
||||
var cates = await Client.GetAsJsonAsync<object>("Releases");
|
||||
Assert.NotNull(cates);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Builds_Ok()
|
||||
{
|
||||
var cates = await Client.GetAsJsonAsync<object>("Builds");
|
||||
Assert.NotNull(cates);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,10 +14,33 @@ namespace Bootstrap.Admin.Api.SqlServer
|
|||
[Fact]
|
||||
public async void Get_Ok()
|
||||
{
|
||||
// 菜单 系统菜单 系统使用条件
|
||||
var query = "?sort=Order&order=asc&offset=0&limit=20&parentName=&name=%E5%90%8E%E5%8F%B0%E7%AE%A1%E7%90%86&category=0&isresource=0&_=1547619684999";
|
||||
var query = "?sort=Order&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
|
||||
var qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=Name&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=ParentName&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=CategoryName&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=Target&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=IsResource&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=Application&order=asc&offset=0&limit=100&parentName=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A2&name=%E5%85%B3%E4%BA%8E&category=1&isresource=0&appCode=2&_=1558235377255";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
using Xunit;
|
||||
|
||||
namespace Bootstrap.Admin.Api.MySql
|
||||
{
|
||||
[Collection("MySqlContext")]
|
||||
public class GiteeTest : SqlServer.GiteeTest
|
||||
{
|
||||
public GiteeTest(MySqlBAWebHost factory) : base(factory) { }
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using Longbow.Web;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Xunit;
|
||||
|
||||
namespace Bootstrap.Admin.Api.SqlServer
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using Xunit;
|
||||
|
||||
namespace UnitTest.Bootstrap.Admin.Api
|
||||
{
|
||||
public class OnlineUserTest
|
||||
{
|
||||
[Fact]
|
||||
public void PrivateUser_Dispose()
|
||||
{
|
||||
var assembly = Assembly.Load("Bootstrap.Admin");
|
||||
var t = Activator.CreateInstance(assembly.GetType("Bootstrap.Admin.Controllers.Api.OnlineUsersController", true, true));
|
||||
var userCacheType = t.GetType().GetNestedType("LoginUserCache", BindingFlags.NonPublic);
|
||||
var loginUserType = t.GetType().GetNestedType("LoginUser", BindingFlags.NonPublic);
|
||||
var loginUser = Activator.CreateInstance(loginUserType, true);
|
||||
var action = new Action(() => { });
|
||||
var userCache = Activator.CreateInstance(userCacheType, new object[] { loginUser, action });
|
||||
var mi = userCacheType.GetMethod("Dispose");
|
||||
mi.Invoke(userCache, null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,9 @@
|
|||
using Bootstrap.DataAccess;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using UnitTest;
|
||||
using Xunit;
|
||||
|
||||
namespace Bootstrap.Admin.Api.SqlServer
|
||||
|
@ -51,5 +56,31 @@ namespace Bootstrap.Admin.Api.SqlServer
|
|||
var resp = await Client.PutAsJsonAsync<User, bool>(usr);
|
||||
Assert.True(resp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAndDelIcon_Ok()
|
||||
{
|
||||
var iconFile = TestHelper.RetrievePath(string.Format("Bootstrap.Admin{0}wwwroot{0}images{0}logo.jpg", Path.DirectorySeparatorChar));
|
||||
var adminFile = TestHelper.RetrievePath(string.Format("Bootstrap.Admin{0}wwwroot{0}images{0}uploader{0}Admin.jpg", Path.DirectorySeparatorChar));
|
||||
FileInfo fi = new FileInfo(iconFile);
|
||||
string fileName = fi.Name;
|
||||
byte[] fileContents = File.ReadAllBytes(fi.FullName);
|
||||
|
||||
var loginContent = new MultipartFormDataContent();
|
||||
var byteArrayContent = new ByteArrayContent(fileContents);
|
||||
byteArrayContent.Headers.Add("Content-Type", "application/octet-stream");
|
||||
loginContent.Add(byteArrayContent, "fileName", fileName);
|
||||
|
||||
var req = await Client.PostAsync("", loginContent);
|
||||
Assert.Equal(HttpStatusCode.OK, req.StatusCode);
|
||||
Assert.True(File.Exists(adminFile));
|
||||
|
||||
// delete file
|
||||
var delContent = new StringContent("key=Admin.jpg");
|
||||
delContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
|
||||
req = await Client.PostAsync("del", delContent);
|
||||
req = await Client.PostAsync("Delete", delContent);
|
||||
Assert.False(File.Exists(adminFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
using Xunit;
|
||||
|
||||
namespace Bootstrap.Admin.Api.SQLite
|
||||
{
|
||||
[Collection("SQLiteContext")]
|
||||
public class GiteeTest : SqlServer.GiteeTest
|
||||
{
|
||||
public GiteeTest(SQLiteBAWebHost factory) : base(factory) { }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Xunit;
|
||||
|
||||
namespace Bootstrap.Admin.Api.SqlServer
|
||||
{
|
||||
public class ToolsTest : ControllerTest
|
||||
{
|
||||
public ToolsTest(BAWebHost factory) : base(factory, "Tools/Index?ReturnUrl=http://localhost") { }
|
||||
|
||||
[Fact]
|
||||
public async void Index_Ok()
|
||||
{
|
||||
var req = await Client.SendAsync(new HttpRequestMessage(HttpMethod.Get, ""));
|
||||
Assert.Equal(HttpStatusCode.OK, req.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using Longbow.Web.Mvc;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Xunit;
|
||||
|
||||
|
@ -15,8 +16,9 @@ namespace Bootstrap.Admin.Api.SqlServer
|
|||
[Fact]
|
||||
public async void Option_Ok()
|
||||
{
|
||||
var req = new HttpRequestMessage(HttpMethod.Options, "Users");
|
||||
var req = new HttpRequestMessage(HttpMethod.Options, "");
|
||||
var resp = await Client.SendAsync(req);
|
||||
Assert.Equal(HttpStatusCode.NoContent, resp.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -26,6 +28,22 @@ namespace Bootstrap.Admin.Api.SqlServer
|
|||
var query = "?sort=DisplayName&order=asc&offset=0&limit=20&name=Admin&displayName=Administrator&_=1547628247338";
|
||||
var qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=UserName&order=asc&offset=0&limit=20&name=Admin&displayName=Administrator&_=1547628247338";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=RegisterTime&order=asc&offset=0&limit=20&name=Admin&displayName=Administrator&_=1547628247338";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=ApprovedTime&order=asc&offset=0&limit=20&name=Admin&displayName=Administrator&_=1547628247338";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
|
||||
query = "?sort=ApprovedBy&order=asc&offset=0&limit=20&name=Admin&displayName=Administrator&_=1547628247338";
|
||||
qd = await Client.GetAsJsonAsync<QueryData<object>>(query);
|
||||
Assert.Single(qd.rows);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
using Xunit;
|
||||
using Bootstrap.DataAccess;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Xunit;
|
||||
|
||||
namespace Bootstrap.Admin.Controllers.SqlServer
|
||||
{
|
||||
|
@ -6,6 +10,19 @@ namespace Bootstrap.Admin.Controllers.SqlServer
|
|||
{
|
||||
public AccountTest(BAWebHost factory) : base(factory, "Account") { }
|
||||
|
||||
[Fact]
|
||||
public async void SystemMode_Test()
|
||||
{
|
||||
var dict = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "系统设置" && d.Name == "演示系统");
|
||||
dict.Code = "1";
|
||||
DictHelper.Save(dict);
|
||||
|
||||
var r = await Client.GetAsync("Login");
|
||||
Assert.Equal(HttpStatusCode.OK, r.StatusCode);
|
||||
dict.Code = "0";
|
||||
DictHelper.Save(dict);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Login_Fail()
|
||||
{
|
||||
|
@ -14,6 +31,24 @@ namespace Bootstrap.Admin.Controllers.SqlServer
|
|||
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("Admin"), "userName" },
|
||||
{ new StringContent("1"), "password" },
|
||||
{ new StringContent("true"), "remember" },
|
||||
{ new StringContent(antiToken), "__RequestVerificationToken" }
|
||||
};
|
||||
var req = await client.PostAsync("/Account/Login", loginContent);
|
||||
Assert.Equal(HttpStatusCode.OK, req.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -21,6 +21,11 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
var userId = UserHelper.Retrieves().FirstOrDefault(u => u.UserName == "Admin").Id;
|
||||
UserHelper.SaveByRoleId(roleId, new string[] { userId });
|
||||
Assert.NotEmpty(AppHelper.RetrievesByUserName("Admin"));
|
||||
|
||||
var apps = AppHelper.RetrievesByRoleId(roleId);
|
||||
roleId = RoleHelper.Retrieves().FirstOrDefault(r => r.RoleName == "Default").Id;
|
||||
AppHelper.SaveByRoleId(roleId, apps.Select(a => a.Id));
|
||||
Assert.NotEmpty(AppHelper.RetrievesByUserName("User"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -21,8 +21,15 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
Code = "1",
|
||||
Define = 1
|
||||
};
|
||||
|
||||
// insert
|
||||
Assert.True(DictHelper.Save(dict));
|
||||
Assert.True(DictHelper.Delete(DictHelper.RetrieveDicts().Where(d => d.Category == dict.Category).Select(d => d.Id)));
|
||||
|
||||
// update
|
||||
Assert.True(DictHelper.Save(dict));
|
||||
|
||||
// delete
|
||||
Assert.True(DictHelper.Delete(new string[] { dict.Id }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -35,7 +42,11 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
Code = "1",
|
||||
Define = 1
|
||||
};
|
||||
|
||||
// insert
|
||||
Assert.True(DictHelper.SaveSettings(dict));
|
||||
|
||||
// delete
|
||||
dict.Delete(DictHelper.RetrieveDicts().Where(d => d.Category == dict.Category).Select(d => d.Id));
|
||||
}
|
||||
|
||||
|
@ -79,6 +90,8 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
public void RetrieveHomeUrl_Ok()
|
||||
{
|
||||
Assert.Equal("~/Home/Index", DictHelper.RetrieveHomeUrl("0"));
|
||||
var url = DictHelper.RetrieveHomeUrl("2");
|
||||
Assert.NotEqual("~/Home/Index", url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -176,6 +189,7 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
var dict = new BootstrapDict() { Category = "系统检查", Name = "系统设置", Code = DatabaseName, Define = 0 };
|
||||
Assert.True(DictHelper.Save(dict));
|
||||
Assert.Equal(DatabaseName, DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == dict.Category && d.Name == dict.Name)?.Code ?? "unknown");
|
||||
DictHelper.Delete(new string[] { dict.Id });
|
||||
}
|
||||
|
||||
#region Private Class For Test
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Longbow.Web.Mvc;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
|
@ -10,15 +11,20 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
[Fact]
|
||||
public void Retrieves_Ok()
|
||||
{
|
||||
ExceptionsHelper.Log(new Exception("UnitTest"), null);
|
||||
ExceptionsHelper.Log(new Exception("UnitTest", new SqliteException("UnitTest", 1001)), null);
|
||||
Assert.NotEmpty(ExceptionsHelper.Retrieves());
|
||||
|
||||
Exceptions ex = new Exceptions() { Period = "1" };
|
||||
Assert.Equal("1", ex.Period);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetrievePages_Ok()
|
||||
{
|
||||
var op = ExceptionsHelper.RetrievePages(new PaginationOption() { Offset = 0, Limit = 20, Sort = "LogTime", Order = "desc" }, null, null);
|
||||
Assert.NotNull(op);
|
||||
Assert.NotNull(ExceptionsHelper.RetrievePages(new PaginationOption() { Offset = 0, Limit = 20, Sort = "LogTime", Order = "desc" }, null, null));
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,10 +16,15 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
public void SaveAndDelete_Ok()
|
||||
{
|
||||
Group g = new Group() { GroupName = "UnitTest", Description = "UnitTestSave" };
|
||||
|
||||
// insert
|
||||
Assert.True(GroupHelper.Save(g));
|
||||
|
||||
var ids = GroupHelper.Retrieves().Where(t => t.GroupName == "UnitTest").Select(t => t.Id);
|
||||
Assert.True(GroupHelper.Delete(ids));
|
||||
// update
|
||||
Assert.True(GroupHelper.Save(g));
|
||||
|
||||
// delete
|
||||
Assert.True(GroupHelper.Delete(new string[] { g.Id }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -36,7 +36,11 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
RequestUrl = "~/Home/Index"
|
||||
};
|
||||
LogHelper.Save(log);
|
||||
Assert.NotNull(LogHelper.Retrieves(new PaginationOption() { Limit = 20, Order = "LogTime" }, null, null, null));
|
||||
Assert.NotNull(LogHelper.Retrieves(new PaginationOption() { Limit = 20, Sort = "LogTime", Order = "desc" }, null, null, null));
|
||||
Assert.NotNull(LogHelper.Retrieves(new PaginationOption() { Limit = 20, Sort = "CRUD", Order = "desc" }, null, null, null));
|
||||
Assert.NotNull(LogHelper.Retrieves(new PaginationOption() { Limit = 20, Sort = "UserName", Order = "desc" }, null, null, null));
|
||||
Assert.NotNull(LogHelper.Retrieves(new PaginationOption() { Limit = 20, Sort = "Ip", Order = "desc" }, null, null, null));
|
||||
Assert.NotNull(LogHelper.Retrieves(new PaginationOption() { Limit = 20, Sort = "RequestUrl", Order = "desc" }, null, null, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,16 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
Url = "#",
|
||||
ParentId = "0"
|
||||
};
|
||||
|
||||
// insert
|
||||
Assert.True(MenuHelper.Save(poco));
|
||||
MenuHelper.Delete(MenuHelper.RetrieveAllMenus("Admin").Where(n => n.Name == poco.Name).Select(n => n.Id));
|
||||
|
||||
// update
|
||||
poco = MenuHelper.RetrieveAllMenus("Admin").Where(m => m.Id == poco.Id).FirstOrDefault();
|
||||
Assert.True(MenuHelper.Save(poco));
|
||||
|
||||
// clean
|
||||
MenuHelper.Delete(new string[] { poco.Id });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
using Xunit;
|
||||
|
||||
namespace Bootstrap.DataAccess
|
||||
{
|
||||
public class MessageBodyTest
|
||||
{
|
||||
[Fact]
|
||||
public void ToString_Ok()
|
||||
{
|
||||
var body = new MessageBody();
|
||||
body.Category = "UnitTest";
|
||||
body.Message = "UnitTest";
|
||||
Assert.Equal($"{body.Category}-{body.Message}", body.ToString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using Xunit;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace Bootstrap.DataAccess.SqlServer
|
||||
{
|
||||
|
@ -10,5 +11,29 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
{
|
||||
Assert.NotNull(MessageHelper.Retrieves("Admin"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public virtual void Save_Ok()
|
||||
{
|
||||
var msg = new Message()
|
||||
{
|
||||
Content = "UnitTest",
|
||||
From = "Admin",
|
||||
Label = "Test",
|
||||
IsDelete = 0,
|
||||
Flag = 0,
|
||||
Period = "1",
|
||||
SendTime = DateTime.Now,
|
||||
Status = "0",
|
||||
Title = "Test",
|
||||
To = "User",
|
||||
LabelName = "UnitTest",
|
||||
FromDisplayName = "UnitTest",
|
||||
FromIcon = "Default.jpg"
|
||||
};
|
||||
Assert.True(MessageHelper.Save(msg));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,5 +20,11 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
var reasons = UserHelper.RetrieveResetReasonsByUserName(user.UserName);
|
||||
Assert.NotEmpty(reasons);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Save_Ok()
|
||||
{
|
||||
Assert.True(ResetUserHelper.Save(new ResetUser() { UserName = "U_Reset", DisplayName = "UnitTest", Reason = "UnitTest" }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,15 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
Description = "Role_Desc",
|
||||
RoleName = "UnitTest-Save"
|
||||
};
|
||||
|
||||
// insert
|
||||
Assert.True(RoleHelper.Save(role));
|
||||
Assert.True(RoleHelper.Delete(RoleHelper.Retrieves().Where(r => r.RoleName == role.RoleName).Select(r => r.Id)));
|
||||
|
||||
// update
|
||||
Assert.True(RoleHelper.Save(role));
|
||||
|
||||
// delete
|
||||
Assert.True(RoleHelper.Delete(new string[] { role.Id }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -81,5 +88,12 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
{
|
||||
Assert.NotEmpty(RoleHelper.RetrieveRolesByUrl("~/Home/Index"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveByGroupId_Ok()
|
||||
{
|
||||
var gId = GroupHelper.Retrieves().FirstOrDefault(g => g.GroupName == "Admin").Id;
|
||||
RoleHelper.SaveByGroupId(gId, RoleHelper.Retrieves().Where(r => r.RoleName == "Administrators").Select(r => r.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Linq;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace Bootstrap.DataAccess.SqlServer
|
||||
|
@ -9,7 +9,8 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
[Fact]
|
||||
public void Retrieves_Ok()
|
||||
{
|
||||
Assert.Equal(Enumerable.Empty<Task>(), TaskHelper.Retrieves());
|
||||
TaskHelper.Save(new Task() { TaskName = "UnitTest", AssignName = "User", UserName = "Admin", TaskTime = 0, TaskProgress = 20, AssignTime = DateTime.Now });
|
||||
Assert.NotEmpty(TaskHelper.Retrieves());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,12 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
};
|
||||
DbContextManager.Create<Trace>().Save(log);
|
||||
Assert.NotEmpty(TraceHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0, Order = "desc", Sort = "LogTime" }, null, null, null).Items);
|
||||
Assert.NotEmpty(TraceHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0, Order = "desc", Sort = "IP" }, null, null, null).Items);
|
||||
Assert.NotEmpty(TraceHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0, Order = "desc", Sort = "UserName" }, null, null, null).Items);
|
||||
Assert.NotEmpty(TraceHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0, Order = "desc", Sort = "City" }, null, null, null).Items);
|
||||
Assert.NotEmpty(TraceHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0, Order = "desc", Sort = "Browser" }, null, null, null).Items);
|
||||
Assert.NotEmpty(TraceHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0, Order = "desc", Sort = "OS" }, null, null, null).Items);
|
||||
Assert.NotEmpty(TraceHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0, Order = "desc", Sort = "RequestUrl" }, null, null, null).Items);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Longbow.Web.Mvc;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
|
@ -90,6 +91,7 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
public void SaveUser_Ok()
|
||||
{
|
||||
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));
|
||||
Assert.True(UserHelper.Delete(UserHelper.Retrieves().Where(usr => usr.UserName == user.UserName).Select(usr => usr.Id)));
|
||||
}
|
||||
|
@ -147,5 +149,34 @@ namespace Bootstrap.DataAccess.SqlServer
|
|||
var usr = UserHelper.RetrieveUserByUserName("Admin");
|
||||
Assert.Equal("Administrator", usr.DisplayName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SaveApp_Ok()
|
||||
{
|
||||
var appId = AppHelper.RetrievesByUserName("Admin").FirstOrDefault();
|
||||
Assert.False(string.IsNullOrEmpty(appId));
|
||||
Assert.True(UserHelper.SaveApp("Admin", appId));
|
||||
UserHelper.SaveApp("Admin", "");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResetPassword_Ok()
|
||||
{
|
||||
Assert.False(UserHelper.ResetPassword("User", "123789"));
|
||||
|
||||
var newUser = new User() { UserName = "U_Reset", DisplayName = "UnitTest", ApprovedTime = DateTime.Now, ApprovedBy = "System", Password = "1", Description = "UnitTest", RegisterTime = DateTime.Now };
|
||||
var ids = UserHelper.Retrieves().Where(u => u.UserName == newUser.UserName).Select(u => u.Id);
|
||||
UserHelper.Delete(ids);
|
||||
Assert.True(UserHelper.Save(newUser));
|
||||
Assert.True(UserHelper.ForgotPassword(new ResetUser() { DisplayName = "UnitTest", Reason = "UnitTest", ResetTime = DateTime.Now, UserName = newUser.UserName }));
|
||||
Assert.True(UserHelper.ResetPassword(newUser.UserName, "123"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetrieveLoginUsers_Ok()
|
||||
{
|
||||
var data = LoginHelper.Retrieves(new PaginationOption() { Limit = 20, Offset = 0 }, "");
|
||||
Assert.NotNull(data.Items);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,14 +9,6 @@ namespace UnitTest
|
|||
{
|
||||
public static class TestHelper
|
||||
{
|
||||
public static string SQLServerConnectionString { get; set; }
|
||||
|
||||
public static string SQLiteConnectionString { get; set; }
|
||||
|
||||
public static string MySqlConnectionString { get; set; }
|
||||
|
||||
public static string NpgSqlConnectionString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得当前工程解决方案目录
|
||||
/// </summary>
|
||||
|
@ -55,14 +47,6 @@ namespace UnitTest
|
|||
|
||||
public static void ConfigureWebHost(IWebHostBuilder builder, DatabaseProviderType providerName = DatabaseProviderType.SqlServer)
|
||||
{
|
||||
if (providerName == DatabaseProviderType.SqlServer)
|
||||
{
|
||||
builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair<string, string>[] {
|
||||
new KeyValuePair<string, string>("ConnectionStrings:ba", SQLServerConnectionString),
|
||||
new KeyValuePair<string, string>("DB:0:Enabled", "true")
|
||||
}));
|
||||
}
|
||||
|
||||
if (providerName == DatabaseProviderType.SQLite)
|
||||
{
|
||||
var dbPath = RetrievePath($"UnitTest{Path.DirectorySeparatorChar}DB{Path.DirectorySeparatorChar}UnitTest.db");
|
||||
|
@ -71,8 +55,7 @@ namespace UnitTest
|
|||
|
||||
builder.ConfigureAppConfiguration(app => app.AddInMemoryCollection(new KeyValuePair<string, string>[] {
|
||||
new KeyValuePair<string, string>("DB:0:Enabled", "false"),
|
||||
new KeyValuePair<string, string>("DB:1:Enabled", "true"),
|
||||
new KeyValuePair<string, string>("DB:1:ConnectionStrings:ba", SQLiteConnectionString)
|
||||
new KeyValuePair<string, string>("DB:1:Enabled", "true")
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -81,8 +64,7 @@ namespace UnitTest
|
|||
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", "true"),
|
||||
new KeyValuePair<string, string>("DB:2:ConnectionStrings:ba", MySqlConnectionString)
|
||||
new KeyValuePair<string, string>("DB:2:Enabled", "true")
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -92,8 +74,7 @@ namespace UnitTest
|
|||
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", "true"),
|
||||
new KeyValuePair<string, string>("DB:3:ConnectionStrings:ba", NpgSqlConnectionString)
|
||||
new KeyValuePair<string, string>("DB:3:Enabled", "true")
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"ConnectionStrings": {
|
||||
"ba": "Data Source=(local)\\SQL2014;Initial Catalog=BootstrapAdmin;User ID=sa;Password=Password12!"
|
||||
},
|
||||
"DB": [
|
||||
{
|
||||
"Enabled": true
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"ProviderName": "Sqlite",
|
||||
"ConnectionStrings": {
|
||||
"ba": "Data Source=UnitTest.db;"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"ProviderName": "MySql",
|
||||
"ConnectionStrings": {
|
||||
"ba": "Server=localhost;Database=BootstrapAdmin;Uid=root;Pwd=Password12!;SslMode=none;"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"ProviderName": "Npgsql",
|
||||
"ConnectionStrings": {
|
||||
"ba": "Server=localhost:5432;Database=BootstrapAdmin;User ID=postgres;Password=Password12!;"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"Widget": "Bootstrap.DataAccess.MongoDB",
|
||||
"ConnectionStrings": {
|
||||
"ba": "mongodb://localhost:27017"
|
||||
}
|
||||
}
|
||||
],
|
||||
"MongoDB": "BootstrapAdmin"
|
||||
}
|
|
@ -1,10 +1,49 @@
|
|||
{
|
||||
"MongoDB": "UnitTest",
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Error",
|
||||
"System": "Error",
|
||||
"Microsoft": "Error"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"sqlite": "Data Source=UnitTest.db;",
|
||||
"sqlserver": "Data Source=.;Initial Catalog=UnitTest;User ID=sa;Password=sa",
|
||||
"mysql": "Server=localhost;Database=UnitTest;Uid=argozhang;Pwd=argo@163.com;SslMode=none;allowPublicKeyRetrieval=true",
|
||||
"sqlserver-app": "Data Source=(local)\\SQL2014;Initial Catalog=BootstrapAdmin;User ID=sa;Password=Password12!",
|
||||
"mysql-app": "Server=localhost;Database=BootstrapAdmin;Uid=root;Pwd=Password12!;SslMode=none;allowPublicKeyRetrieval=true"
|
||||
"ba": "Data Source=.;Initial Catalog=UnitTest;User ID=sa;Password=sa"
|
||||
},
|
||||
"DB": [
|
||||
{
|
||||
"Enabled": true
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"ProviderName": "Sqlite",
|
||||
"ConnectionStrings": {
|
||||
"ba": "Data Source=UnitTest.db;"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"ProviderName": "MySql",
|
||||
"ConnectionStrings": {
|
||||
"ba": "Server=localhost;Database=UnitTest;Uid=argozhang;Pwd=argo@163.com;SslMode=none;"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"ProviderName": "Npgsql",
|
||||
"ConnectionStrings": {
|
||||
"ba": "Server=localhost;Database=UnitTest;User ID=argozhang;Password=argo@163.com;"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Enabled": true,
|
||||
"Widget": "Bootstrap.DataAccess.MongoDB",
|
||||
"ConnectionStrings": {
|
||||
"ba": "mongodb://localhost:27017"
|
||||
}
|
||||
}
|
||||
],
|
||||
"MongoDB": "UnitTest",
|
||||
"LongbowCache": {
|
||||
"Enabled": false
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Error",
|
||||
"System": "Error",
|
||||
"Microsoft": "Error"
|
||||
}
|
||||
},
|
||||
"LongbowCache": {
|
||||
"Enabled": false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue