public void SessionReflashTest() { #region arrange List <RoleDTO> reRoleDTO = new List <RoleDTO>() { new RoleDTO() { RoleID = 1, RoleName = "Admin", Description = "最高權限" }, new RoleDTO() { RoleID = 2, RoleName = "A", Description = "A1" }, new RoleDTO() { RoleID = 3, RoleName = "B", Description = "B1" } }; List <SecurityRoleFunctionDTO> reSRFRole = new List <SecurityRoleFunctionDTO>() { new SecurityRoleFunctionDTO() { Description = "首頁", Url = "Home/Index" }, new SecurityRoleFunctionDTO() { Description = "瀏覽角色管理畫面", Url = "Role/RoleManagement" }, new SecurityRoleFunctionDTO() { Description = "角色新增修改刪除畫面", Url = "Role/RoleAddEditDelete" }, new SecurityRoleFunctionDTO() { Description = "編輯角色", Url = "Role/EditRole" }, new SecurityRoleFunctionDTO() { Description = "編輯角色使用者畫面", Url = "Role/RoleUserEdit" } }; // httpContext物件設定 var httpContext = FakeHttpContextManager.CreateHttpContextBase(); httpContext.Session["UserID"] = 1; httpContext.Session["AccountName"] = "kevan"; // 設定httpContext _target.CurrentHttpContext = httpContext; _loginService.Stub(o => o.GetRoleDataByUserID(Arg <string> .Is.Anything)).Return(reRoleDTO); _securityService.Stub(o => o.GetSecurityRoleFunction(Arg <string> .Is.Anything)).Return(reSRFRole); #endregion #region act _target.SessionReflash(); #endregion #region assert for (int i = 0; i < _target.CurrentSecurityLevel.SecurityRole.Count; i++) { Assert.AreEqual(_target.CurrentSecurityLevel.SecurityRole[i].RoleID, reRoleDTO[i].RoleID); Assert.AreEqual(_target.CurrentSecurityLevel.SecurityRole[i].RoleName, reRoleDTO[i].RoleName); Assert.AreEqual(_target.CurrentSecurityLevel.SecurityRole[i].Description, reRoleDTO[i].Description); } for (int i = 0; i < _target.CurrentSecurityLevel.SecurityUrl.Count; i++) { Assert.AreEqual(_target.CurrentSecurityLevel.SecurityUrl[i].Url, reSRFRole[i].Url); Assert.AreEqual(_target.CurrentSecurityLevel.SecurityUrl[i].Description, reSRFRole[i].Description); } #endregion }