public void MakeCookieTest() { ///Make a cookie with a value, no key HttpCookie testCookie = CookieTools.MakeCookie(CookieTools.HobbesCookieName, testCookieValue); Assert.IsNotNull(testCookie, "Cookie is null"); Assert.AreEqual(CookieTools.HobbesCookieName, HttpUtility.HtmlDecode(testCookie.Name), "Problem: Cookie name wrong"); HttpCookieCollection coll = new HttpCookieCollection(); coll.Add(testCookie); String actualValue = HttpUtility.HtmlDecode(CookieTools.GetHobbesCookieValue(coll, "TestCookie with spaces")); Assert.IsNull(actualValue, "Problem: Cookie has key, wrong"); testCookie = CookieTools.AddTo(testCookie, "key1", "Ringo"); actualValue = CookieTools.GetCookieValue(testCookie, "key1"); Assert.AreEqual("Ringo", actualValue, "Problem: Cookie ['key1'] value incorrect"); testCookie = null; //Test creating a cookie with no initial value testCookie = CookieTools.MakeCookie(CookieTools.HobbesCookieName, null); Assert.IsNotNull(testCookie, "Cookie is null"); Assert.AreEqual(CookieTools.HobbesCookieName, HttpUtility.HtmlDecode(testCookie.Name), "Problem: Cookie name wrong"); Assert.IsNull(testCookie.Value, "Problem: Cookie value wrong"); }
public void GetIrcdaCookieValueTest() { string otherCookieVal = "Bobs Cookie"; string testKey = "testkey"; HttpCookie testCookie = CookieTools.MakeCookie(CookieTools.HobbesCookieName, null); testCookie = CookieTools.AddTo(testCookie, testKey, "Bobs Cookie"); HttpCookie testCookie2 = CookieTools.MakeCookie("Bobs Cookie", otherCookieVal); HttpCookieCollection cookies = new HttpCookieCollection(); cookies.Add(testCookie); cookies.Add(testCookie2); string result = CookieTools.GetHobbesCookieValue(cookies, testKey); Assert.AreEqual("Bobs Cookie", result, "Problem: Didn't get value"); }