public void AddFunctionTest() { #region arrange (新增成功) // httpContext物件設定 var httpContext = FakeHttpContextManager.CreateHttpContextBase(); httpContext.Response.StatusCode = 200; FunctionVO functionVO = new FunctionVO() { Url = "Role/RoleManagement", Title = "角色管理", Description = "瀏覽角色管理畫面", IsMenu = true, Parent = 0 }; string reMessage = ""; _functionService.Stub(o => o.AddFunction(Arg <FunctionVO> .Is.Anything)).Return(reMessage); // 設定httpContext _target.CurrentHttpContext = httpContext; #endregion #region act var resultData = _target.AddFunction(functionVO); var result = (FunctionVO)(((JsonResult)resultData).Data); #endregion #region assert // 測試回應狀態 Assert.AreEqual(_target.CurrentHttpContext.Response.StatusCode, 200); // 測試回傳結果 Assert.AreEqual(result.Url, functionVO.Url); Assert.AreEqual(result.Title, functionVO.Title); Assert.AreEqual(result.Description, functionVO.Description); Assert.AreEqual(result.IsMenu, functionVO.IsMenu); Assert.AreEqual(result.Parent, functionVO.Parent); Assert.AreEqual(result.ParentName, functionVO.ParentName); Assert.IsTrue(string.IsNullOrEmpty(result.Message)); #endregion }