2019-01-14 21:48:24 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Xunit;
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
2019-05-15 00:22:13 +08:00
|
|
|
|
namespace Bootstrap.DataAccess.SqlServer
|
2019-01-11 23:20:28 +08:00
|
|
|
|
{
|
2019-01-24 17:58:06 +08:00
|
|
|
|
[Collection("SQLServerContext")]
|
2019-01-21 17:33:20 +08:00
|
|
|
|
public class RolesTest
|
2019-01-11 23:20:28 +08:00
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SaveRolesByUserId_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var userId = UserHelper.Retrieves().Where(u => u.UserName == "Admin").FirstOrDefault().Id;
|
|
|
|
|
Assert.True(RoleHelper.SaveByUserId(userId, RoleHelper.Retrieves().Select(r => r.Id)));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveRolesByUserId_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var userId = UserHelper.Retrieves().Where(u => u.UserName == "Admin").FirstOrDefault().Id;
|
|
|
|
|
Assert.NotEmpty(RoleHelper.RetrievesByUserId(userId));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteRole_Ok()
|
|
|
|
|
{
|
|
|
|
|
var role = new Role()
|
|
|
|
|
{
|
|
|
|
|
Description = "Role_Desc",
|
2019-01-17 13:27:40 +08:00
|
|
|
|
RoleName = "UnitTest-Delete"
|
2019-01-11 23:20:28 +08:00
|
|
|
|
};
|
2019-05-14 15:08:46 +08:00
|
|
|
|
Assert.True(RoleHelper.Save(role));
|
|
|
|
|
Assert.True(RoleHelper.Delete(RoleHelper.Retrieves().Where(r => r.RoleName == role.RoleName).Select(r => r.Id)));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SaveRole_Ok()
|
|
|
|
|
{
|
|
|
|
|
var role = new Role()
|
|
|
|
|
{
|
|
|
|
|
Description = "Role_Desc",
|
2019-01-17 13:27:40 +08:00
|
|
|
|
RoleName = "UnitTest-Save"
|
2019-01-11 23:20:28 +08:00
|
|
|
|
};
|
2019-05-14 15:08:46 +08:00
|
|
|
|
Assert.True(RoleHelper.Save(role));
|
|
|
|
|
Assert.True(RoleHelper.Delete(RoleHelper.Retrieves().Where(r => r.RoleName == role.RoleName).Select(r => r.Id)));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveRolesByMenuId_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var roleId = RoleHelper.Retrieves().FirstOrDefault(r => r.RoleName == "Administrators").Id;
|
|
|
|
|
MenuHelper.SaveMenusByRoleId(roleId, MenuHelper.RetrieveAllMenus("Admin").Select(m => m.Id));
|
|
|
|
|
var rs = RoleHelper.RetrievesByMenuId(MenuHelper.RetrieveAllMenus("Admin").FirstOrDefault().Id).Where(r => r.Checked == "checked");
|
|
|
|
|
Assert.NotEmpty(rs);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SavaRolesByMenuId_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var menuId = MenuHelper.RetrieveAllMenus("Admin").FirstOrDefault().Id;
|
|
|
|
|
Assert.True(RoleHelper.SavaByMenuId(menuId, RoleHelper.Retrieves().Select(r => r.Id)));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveRolesByGroupId_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var id = RoleHelper.Retrieves().FirstOrDefault(r => r.RoleName == "Administrators").Id;
|
|
|
|
|
GroupHelper.SaveByRoleId(id, GroupHelper.Retrieves().Select(g => g.Id));
|
|
|
|
|
Assert.NotEmpty(RoleHelper.RetrievesByGroupId(GroupHelper.Retrieves().Where(g => g.GroupName == "Admin").FirstOrDefault().Id).Where(r => r.Checked == "checked"));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveRolesByUserName_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var id = RoleHelper.Retrieves().FirstOrDefault(r => r.RoleName == "Administrators").Id;
|
|
|
|
|
UserHelper.SaveByRoleId(id, UserHelper.Retrieves().Select(u => u.Id));
|
|
|
|
|
Assert.NotEmpty(RoleHelper.RetrieveRolesByUserName("Admin"));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveRolesByUrl_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
Assert.NotEmpty(RoleHelper.RetrieveRolesByUrl("~/Home/Index"));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|