BootstrapAdmin11/Bootstrap.DataAccessTests/RoleHelperTests.cs

78 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
namespace Bootstrap.DataAccess.Tests
{
[TestClass()]
public class RoleTests
{
[TestMethod()]
public void SaveRoleTest()
{
Role role1 = new Role()
{
RoleName = "管理员",
Description = "可以读写所有内容"
};
var result1 = RoleHelper.SaveRole(role1);
Assert.IsTrue(result1 == true, "带有参数的RoleHelper.SaveRole方法添加用户失败请检查数据库连接或者数据库SQL语句");
Role role2 = new Role()
{
ID = 1,
RoleName = "管理员",
Description = "读写所有内容"
};
var result2 = RoleHelper.SaveRole(role2);
Assert.IsTrue(result2 == true, "带有参数的RoleHelper.SaveRole方法编辑用户信息失败请检查数据库连接或者数据库SQL语句");
}
[TestMethod()]
public void RetrieveRoleTest()
{
var result = RoleHelper.RetrieveRoles("1");
Assert.IsTrue((result.Count() == 0 || result.Count() == 1), "带有参数的RoleHelper.RetrieveRole方法调用失败请检查数据库连接或者数据库SQL语句");
result = RoleHelper.RetrieveRoles();
Assert.IsTrue(result.Count() >= 0, "不带参数的RoleHelper.RetrieveRole方法调用失败请检查数据库连接或者数据库SQL语句");
}
[TestMethod()]
public void DeleteRoleTest()
{
RoleHelper.SaveRole(new Role()
{
ID = 0,
RoleName = "RoleUnitTest",
Description = string.Empty
});
var role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == "RoleUnitTest");
Assert.IsTrue(RoleHelper.DeleteRole(role.ID.ToString()), "删除用户失败");
}
[TestMethod()]
public void RetrieveRolesByUserIdTest()
{
var result = RoleHelper.RetrieveRolesByUserId(1);
Assert.IsTrue(result.Count() >= 0, "用户查询角色关系失败!");
}
[TestMethod()]
public void SaveRolesByUserIdTest()
{
var result = RoleHelper.SaveRolesByUserId(1,"3");
Assert.IsTrue(result == true, "保存用户角色关系失败");
}
[TestMethod()]
public void RetrieveRoleByGroupIDTest()
{
var result = RoleHelper.RetrieveRolesByGroupId(1);
Assert.IsTrue((result.Count() == 8), "RetrieveRoleByGroupID测试失败");
}
[TestMethod()]
public void SaveRoleByGroupIDTest()
{
var result = RoleHelper.SaveRolesByGroupId(1,"1,2,3,4");
Assert.IsTrue(result, "SaveRoleByGroupID测试失败");
}
}
}