diff --git a/UnitTest/Bootstrap.DataAccess/MenusTest.cs b/UnitTest/Bootstrap.DataAccess/MenusTest.cs index fff9e88c..9845b779 100644 --- a/UnitTest/Bootstrap.DataAccess/MenusTest.cs +++ b/UnitTest/Bootstrap.DataAccess/MenusTest.cs @@ -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] diff --git a/UnitTest/Bootstrap.DataAccess/RolesTest.cs b/UnitTest/Bootstrap.DataAccess/RolesTest.cs index 21559ee4..693be840 100644 --- a/UnitTest/Bootstrap.DataAccess/RolesTest.cs +++ b/UnitTest/Bootstrap.DataAccess/RolesTest.cs @@ -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] diff --git a/UnitTest/Bootstrap.DataAccess/UsersTest.cs b/UnitTest/Bootstrap.DataAccess/UsersTest.cs index 98129979..2002a464 100644 --- a/UnitTest/Bootstrap.DataAccess/UsersTest.cs +++ b/UnitTest/Bootstrap.DataAccess/UsersTest.cs @@ -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()); }