+VisualStudio+テストプロジェクト のバックアップ(No.1) - PukiWiki

Visual Studio?

テストプロジェクト中に Web のセッションを利用する場合、下記のように、ダミーなHttpContextを作成すれば、解決できます。

[TestInitialize]
public void TestInit()
{
    HttpContext.Current = new HttpContext(new HttpRequest("",
                                 "http://localhost", ""),
                                 new HttpResponse(new System.IO.StringWriter()));
    System.Web.SessionState.SessionStateUtility.AddHttpSessionStateToContext(
                      HttpContext.Current, new HttpSessionStateContainer("",
                      new SessionStateItemCollection(), new HttpStaticObjectsCollection(),
                      20000, true, HttpCookieMode.UseCookies, SessionStateMode.Off, false));
}

ページHandlerの場合は、下記のように

//WebControl.CustomPageはカスタマイズしたページです。
HttpContext.Current.Handler = new WebControl.CustomPage() { MyProperty = "1" };



0


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS

G|Cg|C@Amazon Yahoo yV

z[y[W yVoC[UNLIMITȂ1~] COiq COsیI