Mock HttpContext in UnitTest
public static HttpContext FakeHttpContext()
{
var httpRequest = new HttpRequest("", "http://fakeRequest/", "");
var stringWriter = new StringWriter();
var httpResponce = new HttpResponse(stringWriter);
var httpContext = new HttpContext(httpRequest, httpResponce);
var sessionContainer = new HttpSessionStateContainer("id", new SessionStateItemCollection(),
new HttpStaticObjectsCollection(), 10, true,
HttpCookieMode.AutoDetect,
SessionStateMode.InProc, false);
httpContext.Items["AspSession"] = typeof(HttpSessionState).GetConstructor(
BindingFlags.NonPublic | BindingFlags.Instance,
null, CallingConventions.Standard,
new[] { typeof(HttpSessionStateContainer) },
null)
.Invoke(new object[] { sessionContainer });
return httpContext;
}
HttpContext.Current = FakeHttpContext();
相關文章
- HttpContext探究之RequestServicesHTTPContext
- unittest系列(一)unittest簡介和示例
- unittest使用
- unittest系列(三)unittest用例如何執行
- 全域性獲取HttpContextHTTPContext
- HttpContext擴充套件類HTTPContext套件
- unittest筆記筆記
- unittest例項
- httpcontext in asp.net unit testHTTPContextASP.NET
- unittest系統(八)一文搞定unittest重試功能
- unittest斷言-assertIn
- 我的 Mock Server - Meow MockMockServer
- MockMock
- unittest單元測試
- HttpContext請求上下文物件HTTPContext物件
- HttpContext.User.Identity.IsAuthenticated 為falseHTTPContextIDEFalse
- mock in iOSMockiOS
- Python中的Unittest框架Python框架
- Java 中的 UnitTest 和 PowerMockJavaMock
- 手動編寫mock服務(ma-mock)Mock
- 淺談mockMock
- ajax_mockMock
- 非同步 HttpContext.Current實現取值的方法非同步HTTPContext
- mock-stores——簡單易用的資料mock方案Mock
- 活兒好又性感的線上 Mock 平臺 - Easy MockMock
- koa-mock-swichMock
- mock server 實踐MockServer
- Java mockito mock InputStreamJavaMockito
- Mock方法介紹Mock
- vue-cli + mockVueMock
- 每週一個 Python 模組 | unittestPython
- APP測試的極簡Mock方法——Mock服務端介面APPMock服務端
- mock以及特殊場景下對mock資料的處理Mock
- EF建立上下文物件HttpContext和CallContext物件HTTPContext
- HttpApplication,HttpModule,HttpContext及Asp.Net頁生命週期HTTPAPPContextASP.NET
- 阿里 Mock 工具正式開源,幹掉市面上所有 Mock 工具!阿里Mock
- unittest--TestCase 按宣告順序執行
- Python 自動化測試框架unittestPython框架