다른 로케일에서 다르게 작동하는 일부 코드를 유닛 테스트하고 있습니다. 나는 가짜 HttpContext
을 만들었지 만, 그것에 대해 locale
을 설정해야하고 할 수 없었습니다. 여기에 내가 가짜 HttpContext
을 만드는 오전 방법입니다위조 된 HttpContext에 위조 된 로케일 설정
public static HttpContext FakeHttpContext(string requestUrl)
{
var httpRequest = new HttpRequest("", requestUrl, "");
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;
}