2019-05-11 12:15:03 +08:00
|
|
|
|
using Bootstrap.Security;
|
|
|
|
|
using System.Linq;
|
2019-01-17 13:27:40 +08:00
|
|
|
|
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 MenusTest
|
2019-01-11 23:20:28 +08:00
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Save_Ok()
|
|
|
|
|
{
|
2019-05-11 12:15:03 +08:00
|
|
|
|
var poco = new BootstrapMenu()
|
2019-01-11 23:20:28 +08:00
|
|
|
|
{
|
|
|
|
|
Name = "UnitTest",
|
|
|
|
|
Application = "0",
|
|
|
|
|
Category = "0",
|
|
|
|
|
Icon = "fa fa-fa",
|
|
|
|
|
IsResource = 0,
|
|
|
|
|
Target = "_blank",
|
|
|
|
|
Order = 10,
|
|
|
|
|
Url = "#",
|
2019-05-25 14:38:11 +08:00
|
|
|
|
ParentId = "0",
|
|
|
|
|
ParentName = "Test"
|
2019-01-11 23:20:28 +08:00
|
|
|
|
};
|
2019-05-18 21:21:03 +08:00
|
|
|
|
|
|
|
|
|
// insert
|
|
|
|
|
Assert.True(MenuHelper.Save(poco));
|
|
|
|
|
|
|
|
|
|
// update
|
|
|
|
|
poco = MenuHelper.RetrieveAllMenus("Admin").Where(m => m.Id == poco.Id).FirstOrDefault();
|
2019-05-14 15:08:46 +08:00
|
|
|
|
Assert.True(MenuHelper.Save(poco));
|
2019-05-18 21:21:03 +08:00
|
|
|
|
|
|
|
|
|
// clean
|
|
|
|
|
MenuHelper.Delete(new string[] { poco.Id });
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveMenusByRoleId_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var roleId = RoleHelper.Retrieves().FirstOrDefault(r => r.RoleName == "Administrators").Id;
|
|
|
|
|
Assert.NotEmpty(MenuHelper.RetrieveMenusByRoleId(roleId));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void RetrieveAllMenus_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
Assert.NotEmpty(MenuHelper.RetrieveAllMenus("Admin"));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SaveMenusByRoleId_Ok()
|
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
var roleId = RoleHelper.Retrieves().FirstOrDefault(r => r.RoleName == "Administrators").Id;
|
|
|
|
|
Assert.True(MenuHelper.SaveMenusByRoleId(roleId, MenuHelper.RetrieveAllMenus("Admin").Select(m => m.Id)));
|
2019-01-11 23:20:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|