2019-01-11 23:20:28 +08:00
|
|
|
|
using System;
|
2019-01-12 00:34:12 +08:00
|
|
|
|
using System.Linq;
|
2019-01-11 23:20:28 +08:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2019-01-24 17:58:06 +08:00
|
|
|
|
[Collection("SQLServerContext")]
|
2019-01-21 17:33:20 +08:00
|
|
|
|
public class UsersTest
|
2019-01-11 23:20:28 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Authenticate_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
|
|
|
|
Assert.True(u.Authenticate("Admin", "123789"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ChangePassword_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
|
|
|
|
Assert.True(u.ChangePassword("Admin", "123789", "123789"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2019-01-24 17:58:06 +08:00
|
|
|
|
public virtual void Retrieves_Ok()
|
2019-01-11 23:20:28 +08:00
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
|
|
|
|
Assert.NotEmpty(u.Retrieves());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveNewUsers_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
2019-01-17 13:27:40 +08:00
|
|
|
|
u.Delete(u.RetrieveNewUsers().Select(usr => usr.Id));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
Assert.Empty(u.RetrieveNewUsers());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Update_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
2019-01-12 18:01:37 +08:00
|
|
|
|
Assert.True(u.Update("1", "123789", "Administrator"));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ApproveUser_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
2019-01-12 00:34:12 +08:00
|
|
|
|
u.Delete(u.Retrieves().Where(usr => usr.UserName == "UnitTest").Select(usr => usr.Id));
|
|
|
|
|
|
|
|
|
|
var up = new User() { UserName = "UnitTest", Password = "123", Description = "新建用户用于测试批准", DisplayName = "UnitTest", Icon = "default.jpg" };
|
|
|
|
|
u.Save(up);
|
2019-01-12 18:01:37 +08:00
|
|
|
|
Assert.True(u.Approve(up.Id, "UnitTest"));
|
2019-01-12 00:34:12 +08:00
|
|
|
|
|
|
|
|
|
u.Delete(new string[] { up.Id });
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveUsersByRoleId_Ok()
|
|
|
|
|
{
|
2019-01-17 13:27:40 +08:00
|
|
|
|
var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
|
|
|
|
var uid = new User().Retrieves().Where(u => u.UserName == "Admin").First().Id;
|
|
|
|
|
var db = DbManager.Create();
|
|
|
|
|
db.Execute("delete from userrole where USERID = @0 and ROLEID = @1", uid, rid);
|
|
|
|
|
db.Execute("insert into userrole (USERID, ROLEID) values (@0, @1)", uid, rid);
|
|
|
|
|
|
|
|
|
|
var users = new User().RetrievesByRoleId(rid);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
Assert.NotEmpty(users);
|
|
|
|
|
Assert.Contains(users, usr => usr.Checked == "checked");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrievesByGroupId_Ok()
|
|
|
|
|
{
|
2019-01-17 13:27:40 +08:00
|
|
|
|
var gid = new Group().Retrieves().Where(r => r.GroupName == "Admin").First().Id;
|
2019-01-11 23:20:28 +08:00
|
|
|
|
var u = new User();
|
2019-01-17 13:27:40 +08:00
|
|
|
|
var users = u.RetrievesByGroupId(gid);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
Assert.NotEmpty(users);
|
|
|
|
|
Assert.Contains(users, usr => !usr.Checked.IsNullOrEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteUser_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
|
|
|
|
Assert.True(u.Delete(new string[] { "5", "6" }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SaveUser_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
2019-01-16 18:16:55 +08:00
|
|
|
|
u.Delete(u.Retrieves().Where(usr => usr.UserName == "UnitTest").Select(usr => usr.Id));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
Assert.True(u.Save(new User { UserName = "UnitTest", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = "default.jpg" }));
|
2019-01-16 18:16:55 +08:00
|
|
|
|
u.Delete(u.Retrieves().Where(usr => usr.UserName == "UnitTest").Select(usr => usr.Id));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SaveUserIconByName_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
|
|
|
|
Assert.True(u.SaveUserIconByName("Admin", "default.jpg"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SaveDisplayName_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
2019-01-12 18:01:37 +08:00
|
|
|
|
Assert.True(u.SaveDisplayName("Admin", "Administrator"));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SaveUserCssByName_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
|
|
|
|
Assert.True(u.SaveUserCssByName("Admin", "default.css"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Reject_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
|
|
|
|
u.UserName = "UnitTest-Reject";
|
|
|
|
|
u.DisplayName = "DisplayName";
|
|
|
|
|
u.Description = "Desc";
|
|
|
|
|
u.Icon = "default.jpg";
|
|
|
|
|
u.Save(u);
|
|
|
|
|
Assert.True(u.Reject(u.Id, "Argo"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SaveByGroupId_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
|
|
|
|
Assert.True(u.SaveByGroupId("1", new string[] { "1" }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SaveByRoleId_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
|
|
|
|
Assert.True(u.SaveByRoleId("1", new string[] { "1", "2" }));
|
|
|
|
|
}
|
2019-01-12 19:23:10 +08:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveUserByUserName_Ok()
|
|
|
|
|
{
|
|
|
|
|
var u = new User();
|
|
|
|
|
var usr = u.RetrieveUserByUserName("Admin");
|
|
|
|
|
Assert.Equal("Administrator", usr.DisplayName);
|
|
|
|
|
}
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|