私は静的クラスにこの静的メソッドを持っています:
public static class CookieHelper //:ICookieHelper
{
public static void CreateCookie(string cookieName, int expireyDays)
{
HttpCookie cookie;
cookie = HttpContext.Current.Response.Cookies[cookieName]; //Exception is here
cookie.Expires.AddDays(expireyDays);
}
}
この単体テストを作成しました。このテストを実行すると、nullreferenceexception が生成されます (オブジェクト参照が ... に設定されていません)。
[Test]
public void ShouldCreateCookieAndValidateNotNull()
{
string newCookie = "testCookie";
CookieHelper.CreateCookie(newCookie,5);
string cookieValue = HttpContext.Current.Server.HtmlEncode(HttpContext.Current.Request[newCookie]);
Assert.NotNull(cookieValue);
}
これは、常に Web フォームのコード ビハインドで呼び出されます。プレゼンター層にはありません。
私は何を間違っていますか?