This post shows how to test setting a cookie and then seeing it in ViewData. What I what to do is see if the correct cookies were written (values and name). Any reply, blog post or article will be greatly appreciated.
function ReadCookie(cookieName) { var theCookie=""+document.cookie; var ind=theCookie.indexOf(cookieName); if (ind==-1 || cookieName=="") return ""; var ind1=theCookie.indexOf(';',ind); if (ind1==-1) ind1=theCookie.length; return unescape(theCookie.substring(ind+cookieName.length+1,ind1)); }
Are you looking for something more like this? (untested, just typed it up in the reply box)
var cookies = new HttpCookieCollection();
controller.ControllerContext = new FakeControllerContext(controller, cookies);
var result = controller.TestCookie() as ViewResult;
Assert.AreEqual("somevaluethatshouldbethere", cookies["somecookieitem"].Value);
As in, did you mean you want to test the writing of a cookie instead of reading one? Please make your request clearer if possible :)
EDIT: why in the world do i get a -1 for asking a question and the person who pasted client-side javascript get a +1?? (incase people dont realise you can't use client-side JS as there isn't a browser ... )
Perhaps you need to pass in a Fake Response object that the cookies are written to, and you test what is returned in that from the Controller.