2016-10-22 20:55:07 +08:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2016-10-28 20:18:12 +08:00
|
|
|
|
using System.Collections.Generic;
|
2016-10-22 20:55:07 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess.Tests
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class UserHelperTests
|
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void RetrieveUsersTest()
|
|
|
|
|
{
|
|
|
|
|
var result = UserHelper.RetrieveUsers("1");
|
|
|
|
|
Assert.IsTrue((result.Count() == 0 || result.Count() == 1), "带有参数的UserHelper.RetrieveUsers方法调用失败,请检查数据库连接或者数据库SQL语句");
|
|
|
|
|
result = UserHelper.RetrieveUsers();
|
|
|
|
|
Assert.IsTrue(result.Count() >= 0, "不带参数的UserHelper.RetrieveUsers方法调用失败,请检查数据库连接或者数据库SQL语句");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void DeleteUserTest()
|
|
|
|
|
{
|
|
|
|
|
Assert.IsTrue(UserHelper.DeleteUser("1,2"), "带有参数的UserHelper.DeleteUserTest方法调用失败,请检查数据库连接或者数据库SQL语句");
|
|
|
|
|
Assert.IsFalse(UserHelper.DeleteUser(string.Empty), "参数为空字符串的UserHelper.DeleteUserTest方法调用失败,请检查数据库连接或者数据库SQL语句");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void SaveUserTest()
|
|
|
|
|
{
|
|
|
|
|
User users = new User();
|
|
|
|
|
users.ID = 0;
|
2016-10-24 19:59:07 +08:00
|
|
|
|
users.UserName = "lq";
|
2016-10-22 20:55:07 +08:00
|
|
|
|
users.Password = "123";
|
|
|
|
|
users.PassSalt = "123";
|
2016-10-24 19:59:07 +08:00
|
|
|
|
users.DisplayName = "liqi";
|
2016-10-22 20:55:07 +08:00
|
|
|
|
var result = UserHelper.SaveUser(users);
|
2016-10-24 19:59:07 +08:00
|
|
|
|
Assert.IsTrue(result == true, "新建用户信息失败,请检查数据库连接或者数据库SQL语句");
|
2016-10-22 20:55:07 +08:00
|
|
|
|
|
|
|
|
|
User users1 = new User();
|
2016-10-24 19:59:07 +08:00
|
|
|
|
users1.ID = 5;
|
|
|
|
|
users1.UserName = "lq";
|
|
|
|
|
users1.Password = "123";
|
2016-10-22 20:55:07 +08:00
|
|
|
|
users1.PassSalt = "123456";
|
2016-10-24 19:59:07 +08:00
|
|
|
|
users1.DisplayName = "Qi Li";
|
2016-10-22 20:55:07 +08:00
|
|
|
|
result = UserHelper.SaveUser(users1);
|
2016-10-24 19:59:07 +08:00
|
|
|
|
Assert.IsTrue(result == true, "更新用户信息失败,请检查数据库连接或者数据库SQL语句");
|
2016-10-22 20:55:07 +08:00
|
|
|
|
}
|
2016-10-28 20:18:12 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void RetrieveUsersByRoleIdTest(){
|
|
|
|
|
IEnumerable<User> result = UserHelper.RetrieveUsersByRoleId(2);
|
|
|
|
|
Assert.IsTrue(result.Count() >= 0, "获取该角色的用户信息失败,请检查数据库连接或者数据库SQL语句");
|
|
|
|
|
}
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void SaveUsersByRoleIdTest()
|
|
|
|
|
{
|
|
|
|
|
bool result = UserHelper.SaveUsersByRoleId(2,"2,3");
|
|
|
|
|
Assert.IsTrue(result, "获取该角色的用户信息失败,请检查数据库连接或者数据库SQL语句");
|
|
|
|
|
}
|
2016-10-22 20:55:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|