Skip to content

Instantly share code, notes, and snippets.

@underwhelmed
Created January 7, 2011 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save underwhelmed/770047 to your computer and use it in GitHub Desktop.
Save underwhelmed/770047 to your computer and use it in GitHub Desktop.
Testing setting of cookies in an ASP.NET MVC 2 Controller
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ADLogin()
{
//Delete the cookie passed to this page
if (!Request.Cookies["_CognitionAuthCheck"] == null)
{
HttpCookie myCookie = new HttpCookie("_CognitionAuthCheck");
myCookie.Expires = DateTime.Now().AddDays(-1D);
Response.Cookies.Add(myCookie);
}
}
[Test]
public void if_cookie_exists_then_set_to_expire()
{
TestControllerBuilder builder = new TestControllerBuilder();
LoginController controller = new LoginController();
builder.InitializeController(controller);
builder.HttpContext.Response.Cookies.Add(new HttpCookie("_CognitionAuthCheck", ""));
RedirectResult result = controller.ADLogin() as RedirectResult;
Assert.IsNotNull(controller.HttpContext.Request.Cookies["_CognitionAuthCheck"]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment