2019-01-14 21:48:24 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Xunit;
|
2019-01-11 23:20:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
2019-01-21 17:33:20 +08:00
|
|
|
|
[Collection("BootstrapAdminTestContext")]
|
|
|
|
|
public class RolesTest
|
2019-01-11 23:20:28 +08:00
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SaveRolesByUserId_Ok()
|
|
|
|
|
{
|
|
|
|
|
var role = new Role();
|
|
|
|
|
Assert.True(role.SaveByUserId("1", new string[] { "1", "2" }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveRolesByUserId_Ok()
|
|
|
|
|
{
|
|
|
|
|
var role = new Role();
|
|
|
|
|
Assert.NotEmpty(role.RetrievesByUserId("1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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
|
|
|
|
};
|
|
|
|
|
role.Save(role);
|
|
|
|
|
Assert.True(role.Delete(new string[] { role.Id.ToString() }));
|
2019-01-17 13:27:40 +08:00
|
|
|
|
|
|
|
|
|
// clean
|
|
|
|
|
role.Delete(role.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
|
|
|
|
};
|
|
|
|
|
Assert.True(role.Save(role));
|
2019-01-17 13:27:40 +08:00
|
|
|
|
|
|
|
|
|
// clean
|
|
|
|
|
role.Delete(role.Retrieves().Where(r => r.RoleName == role.RoleName).Select(r => r.Id));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveRolesByMenuId_Ok()
|
|
|
|
|
{
|
|
|
|
|
var menu = new Menu();
|
|
|
|
|
var role = new Role();
|
2019-01-14 21:48:24 +08:00
|
|
|
|
var id = role.Retrieves().FirstOrDefault(r => r.RoleName == "Administrators").Id;
|
|
|
|
|
menu.SaveMenusByRoleId(id, new string[] { "1" });
|
2019-01-11 23:20:28 +08:00
|
|
|
|
var rs = role.RetrievesByMenuId("1");
|
|
|
|
|
Assert.Contains(rs, r => r.Checked == "checked");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SavaRolesByMenuId_Ok()
|
|
|
|
|
{
|
|
|
|
|
var role = new Role();
|
|
|
|
|
Assert.True(role.SavaByMenuId("1", new string[] { "1" }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveRolesByGroupId_Ok()
|
|
|
|
|
{
|
|
|
|
|
var role = new Role();
|
2019-01-14 21:48:24 +08:00
|
|
|
|
var id = role.Retrieves().FirstOrDefault(r => r.RoleName == "Administrators").Id;
|
|
|
|
|
new Group().SaveByRoleId(id, new string[] { "1" });
|
2019-01-11 23:20:28 +08:00
|
|
|
|
Assert.Contains(role.RetrievesByGroupId("1"), r => r.Checked == "checked");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveRolesByUserName_Ok()
|
|
|
|
|
{
|
|
|
|
|
var role = new Role();
|
2019-01-14 21:48:24 +08:00
|
|
|
|
var id = role.Retrieves().FirstOrDefault(r => r.RoleName == "Administrators").Id;
|
|
|
|
|
new User().SaveByRoleId(id, new string[] { "1" });
|
2019-01-11 23:20:28 +08:00
|
|
|
|
Assert.NotEmpty(role.RetrieveRolesByUserName("Admin"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveRolesByUrl_Ok()
|
|
|
|
|
{
|
|
|
|
|
var role = new Role();
|
|
|
|
|
Assert.NotEmpty(role.RetrieveRolesByUrl("~/Home/Index"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|