单元测试:部分单元测试用例增加数据恢复功能

This commit is contained in:
Argo-Surface 2019-01-17 13:27:40 +08:00
parent a0affac523
commit b524d9f912
3 changed files with 22 additions and 6 deletions

View File

@ -1,4 +1,5 @@
using Xunit; using System.Linq;
using Xunit;
namespace Bootstrap.DataAccess namespace Bootstrap.DataAccess
{ {
@ -19,7 +20,9 @@ namespace Bootstrap.DataAccess
Url = "#", Url = "#",
ParentId = "0" ParentId = "0"
}; };
m.Delete(m.RetrieveAllMenus("Admin").Where(n => n.Name == m.Name).Select(n => n.Id));
Assert.True(m.Save(m)); Assert.True(m.Save(m));
m.Delete(new string[] { m.Id });
} }
[Fact] [Fact]

View File

@ -25,10 +25,13 @@ namespace Bootstrap.DataAccess
var role = new Role() var role = new Role()
{ {
Description = "Role_Desc", Description = "Role_Desc",
RoleName = "UnitTest" RoleName = "UnitTest-Delete"
}; };
role.Save(role); role.Save(role);
Assert.True(role.Delete(new string[] { role.Id.ToString() })); 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] [Fact]
@ -37,9 +40,12 @@ namespace Bootstrap.DataAccess
var role = new Role() var role = new Role()
{ {
Description = "Role_Desc", Description = "Role_Desc",
RoleName = "UnitTest" RoleName = "UnitTest-Save"
}; };
Assert.True(role.Save(role)); Assert.True(role.Save(role));
// clean
role.Delete(role.Retrieves().Where(r => r.RoleName == role.RoleName).Select(r => r.Id));
} }
[Fact] [Fact]

View File

@ -37,6 +37,7 @@ namespace Bootstrap.DataAccess
public void RetrieveNewUsers_Ok() public void RetrieveNewUsers_Ok()
{ {
var u = new User(); var u = new User();
u.Delete(u.RetrieveNewUsers().Select(usr => usr.Id));
Assert.Empty(u.RetrieveNewUsers()); Assert.Empty(u.RetrieveNewUsers());
} }
@ -63,8 +64,13 @@ namespace Bootstrap.DataAccess
[Fact] [Fact]
public void RetrieveUsersByRoleId_Ok() public void RetrieveUsersByRoleId_Ok()
{ {
var u = new User(); var rid = new Role().Retrieves().Where(r => r.RoleName == "Administrators").First().Id;
var users = u.RetrievesByRoleId("1"); 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.NotEmpty(users);
Assert.Contains(users, usr => usr.Checked == "checked"); Assert.Contains(users, usr => usr.Checked == "checked");
} }
@ -72,8 +78,9 @@ namespace Bootstrap.DataAccess
[Fact] [Fact]
public void RetrievesByGroupId_Ok() public void RetrievesByGroupId_Ok()
{ {
var gid = new Group().Retrieves().Where(r => r.GroupName == "Admin").First().Id;
var u = new User(); var u = new User();
var users = u.RetrievesByGroupId("1"); var users = u.RetrievesByGroupId(gid);
Assert.NotEmpty(users); Assert.NotEmpty(users);
Assert.Contains(users, usr => !usr.Checked.IsNullOrEmpty()); Assert.Contains(users, usr => !usr.Checked.IsNullOrEmpty());
} }