From b524d9f912d608d685ab2a305ac7145c69e83876 Mon Sep 17 00:00:00 2001 From: Argo-Surface Date: Thu, 17 Jan 2019 13:27:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=EF=BC=9A?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UnitTest/Bootstrap.DataAccess/MenusTest.cs | 5 ++++- UnitTest/Bootstrap.DataAccess/RolesTest.cs | 10 ++++++++-- UnitTest/Bootstrap.DataAccess/UsersTest.cs | 13 ++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) 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()); }