public void EditFunctionTest() { #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> reSecurityRoleFunctionDTO = new List <SecurityRoleFunctionDTO>() { new SecurityRoleFunctionDTO() { Url = "Role/RoleManagement", Description = "瀏覽角色管理畫面" }, new SecurityRoleFunctionDTO() { Url = "Role/RoleAddEditDelete", Description = "角色新增修改刪除畫面" }, new SecurityRoleFunctionDTO() { Url = "Role/EditRole", Description = "編輯角色" } }; // httpContext物件設定 var httpContext = FakeHttpContextManager.CreateHttpContextBase(); httpContext.Response.StatusCode = 200; httpContext.Session["UserID"] = 1; httpContext.Session["AccountName"] = "kevan"; // 設定httpContext _target.CurrentHttpContext = httpContext; FunctionVO functionVO = new FunctionVO() { FunctionID = 1, Url = "Role/RoleManagement", Title = "角色管理", Description = "瀏覽角色管理畫面", IsMenu = true, Parent = 0 }; string reMessage = string.Empty; _loginService.Stub(o => o.GetRoleDataByUserID(Arg <string> .Is.Anything)).Return(reRoleDTO); _securityService.Stub(o => o.GetSecurityRoleFunction(Arg <string> .Is.Anything)).Return(reSecurityRoleFunctionDTO); _functionService.Stub(o => o.EditFunction(Arg <FunctionVO> .Is.Anything)).Return(reMessage); #endregion #region act var resultData = _target.EditFunction(functionVO); var result = (string)((JsonResult)resultData).Data; #endregion #region assert // 測試回應狀態 Assert.AreEqual(_target.CurrentHttpContext.Response.StatusCode, 200); Assert.AreEqual(result, reMessage); #endregion }