예제 #1
0
        public void SetCookie()
        {
            HttpCookie cookie;

            cookie = HttpCookie.ParseSetCookie("Key=Value; Domain=docs.foo.com; Path=/accounts; Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; HttpOnly");
            Assert.IsNotNull(cookie);
            Assert.AreEqual("Key", cookie.Name);
            Assert.AreEqual("Value", cookie.Value);
            Assert.AreEqual("docs.foo.com", cookie.Domain);
            Assert.AreEqual("/accounts", cookie.Path);
            Assert.AreEqual(DateTime.Parse("Wed, 13-Jan-2021 22:23:01 GMT"), cookie.Expires);
            Assert.IsTrue(cookie.IsSecure);
            Assert.IsTrue(cookie.IsHttpOnly);

            cookie = HttpCookie.ParseSetCookie("Key=Value; Domain=docs.foo.com; Path=/accounts; Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure");
            Assert.IsNotNull(cookie);
            Assert.AreEqual("Key", cookie.Name);
            Assert.AreEqual("Value", cookie.Value);
            Assert.AreEqual("docs.foo.com", cookie.Domain);
            Assert.AreEqual("/accounts", cookie.Path);
            Assert.AreEqual(DateTime.Parse("Wed, 13-Jan-2021 22:23:01 GMT"), cookie.Expires);
            Assert.IsTrue(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);

            cookie = HttpCookie.ParseSetCookie("Key=Value; Domain=docs.foo.com; Path=/accounts; Expires=Wed, 13-Jan-2021 22:23:01 GMT");
            Assert.IsNotNull(cookie);
            Assert.AreEqual("Key", cookie.Name);
            Assert.AreEqual("Value", cookie.Value);
            Assert.AreEqual("docs.foo.com", cookie.Domain);
            Assert.AreEqual("/accounts", cookie.Path);
            Assert.AreEqual(DateTime.Parse("Wed, 13-Jan-2021 22:23:01 GMT"), cookie.Expires);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);

            cookie = HttpCookie.ParseSetCookie("Key=Value; Domain=docs.foo.com; Path=/accounts");
            Assert.IsNotNull(cookie);
            Assert.AreEqual("Key", cookie.Name);
            Assert.AreEqual("Value", cookie.Value);
            Assert.AreEqual("docs.foo.com", cookie.Domain);
            Assert.AreEqual("/accounts", cookie.Path);
            Assert.IsNull(cookie.Expires);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);

            cookie = HttpCookie.ParseSetCookie("Key=Value; Domain=docs.foo.com");
            Assert.IsNotNull(cookie);
            Assert.AreEqual("Key", cookie.Name);
            Assert.AreEqual("Value", cookie.Value);
            Assert.AreEqual("docs.foo.com", cookie.Domain);
            Assert.IsNullOrEmpty(cookie.Path);
            Assert.IsNull(cookie.Expires);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);

            cookie = HttpCookie.ParseSetCookie("Key=Value");
            Assert.IsNotNull(cookie);
            Assert.AreEqual("Key", cookie.Name);
            Assert.AreEqual("Value", cookie.Value);
            Assert.IsNullOrEmpty(cookie.Domain);
            Assert.IsNullOrEmpty(cookie.Path);
            Assert.IsNull(cookie.Expires);
            Assert.IsFalse(cookie.IsSecure);
            Assert.IsFalse(cookie.IsHttpOnly);
        }