public void DeleteFunctionTest() { #region arrange (刪除成功) // httpContext物件設定 var httpContext = FakeHttpContextManager.CreateHttpContextBase(); httpContext.Response.StatusCode = 200; string id = "1"; string reMessage = ""; _functionService.Stub(o => o.DeleteFunction(Arg <string> .Is.Anything)).Return(reMessage); // 設定httpContext _target.CurrentHttpContext = httpContext; #endregion #region act var resultData = _target.DeleteFunction(id); var result = (string)(((JsonResult)resultData).Data); #endregion #region assert // 測試回應狀態 Assert.AreEqual(_target.CurrentHttpContext.Response.StatusCode, 200); Assert.AreEqual(result, reMessage); #endregion }