单元测试:部分单元测试用例增加数据恢复功能
This commit is contained in:
parent
a0affac523
commit
b524d9f912
|
@ -1,4 +1,5 @@
|
|||
using Xunit;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Bootstrap.DataAccess
|
||||
{
|
||||
|
@ -19,7 +20,9 @@ namespace Bootstrap.DataAccess
|
|||
Url = "#",
|
||||
ParentId = "0"
|
||||
};
|
||||
m.Delete(m.RetrieveAllMenus("Admin").Where(n => n.Name == m.Name).Select(n => n.Id));
|
||||
Assert.True(m.Save(m));
|
||||
m.Delete(new string[] { m.Id });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -25,10 +25,13 @@ namespace Bootstrap.DataAccess
|
|||
var role = new Role()
|
||||
{
|
||||
Description = "Role_Desc",
|
||||
RoleName = "UnitTest"
|
||||
RoleName = "UnitTest-Delete"
|
||||
};
|
||||
role.Save(role);
|
||||
Assert.True(role.Delete(new string[] { role.Id.ToString() }));
|
||||
|
||||
// clean
|
||||
role.Delete(role.Retrieves().Where(r => r.RoleName == role.RoleName).Select(r => r.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -37,9 +40,12 @@ namespace Bootstrap.DataAccess
|
|||
var role = new Role()
|
||||
{
|
||||
Description = "Role_Desc",
|
||||
RoleName = "UnitTest"
|
||||
RoleName = "UnitTest-Save"
|
||||
};
|
||||
Assert.True(role.Save(role));
|
||||
|
||||
// clean
|
||||
role.Delete(role.Retrieves().Where(r => r.RoleName == role.RoleName).Select(r => r.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace Bootstrap.DataAccess
|
|||
public void RetrieveNewUsers_Ok()
|
||||
{
|
||||
var u = new User();
|
||||
u.Delete(u.RetrieveNewUsers().Select(usr => usr.Id));
|
||||
Assert.Empty(u.RetrieveNewUsers());
|
||||
}
|
||||
|
||||
|
@ -63,8 +64,13 @@ namespace Bootstrap.DataAccess
|
|||
[Fact]
|
||||
public void RetrieveUsersByRoleId_Ok()
|
||||
{
|
||||
var u = new User();
|
||||
var users = u.RetrievesByRoleId("1");
|
||||
var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
|
||||
var uid = new User().Retrieves().Where(u => u.UserName == "Admin").First().Id;
|
||||
var db = DbManager.Create();
|
||||
db.Execute("delete from userrole where USERID = @0 and ROLEID = @1", uid, rid);
|
||||
db.Execute("insert into userrole (USERID, ROLEID) values (@0, @1)", uid, rid);
|
||||
|
||||
var users = new User().RetrievesByRoleId(rid);
|
||||
Assert.NotEmpty(users);
|
||||
Assert.Contains(users, usr => usr.Checked == "checked");
|
||||
}
|
||||
|
@ -72,8 +78,9 @@ namespace Bootstrap.DataAccess
|
|||
[Fact]
|
||||
public void RetrievesByGroupId_Ok()
|
||||
{
|
||||
var gid = new Group().Retrieves().Where(r => r.GroupName == "Admin").First().Id;
|
||||
var u = new User();
|
||||
var users = u.RetrievesByGroupId("1");
|
||||
var users = u.RetrievesByGroupId(gid);
|
||||
Assert.NotEmpty(users);
|
||||
Assert.Contains(users, usr => !usr.Checked.IsNullOrEmpty());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue