示例#1
0
 public void Session_not_null()
 {
     var s = new Session(r);
     Assert.IsTrue(s != null);
 }
示例#2
0
 public void Session_is_Admin_false_by_default()
 {
     var s = new Session(r);
     Assert.IsFalse(s.IsAdmin);
 }
示例#3
0
        /// <summary>
        /// Creates session and returns Session
        /// </summary>
        /// <returns>Session object with session key = SessionKey</returns>
        public Session CreateSession(Request request, Response response)
        {
            //try getting Session from cookie
            Session s = GetSessionFromCookie(request);

            if (s != null)
            {
                s.LastAccessed = DateTime.Now;
            }
            else
            {
                //session was not found in cookie, create new one
                s = new Session(request);
            }

            //check if session was created before
            if (GetSessionByKey(s.SessionKey, request) == null)
            {
                //add new session
                SessionList.Add(s);

                if (!IsCookieless)
                {
                    //add cookie with session in it
                    var c = new Cookie(SESSION_COOKIE_NAME, s.SessionKey);

                    //set session for whole website
                    c.Path = "/";
                    c.Expires = DateTime.Now.AddDays(10);

                    //add session request to response
                    if (response != null)
                    {
                        response.Cookies.Add(c);
                    }
                }

                //return SessionKey
                return s;
            }

            return null;
        }
示例#4
0
 public void Session_has_SessionKey_on_creation()
 {
     var s = new Session(r);
     Assert.IsTrue(s.SessionKey.Length > 0);
 }
示例#5
0
 public void UpdateSession(Request request, Session s)
 {
     var session = GetSessionByKey(s.SessionKey, request);
     session.LastAccessed = DateTime.Now;
     session.IsAdmin = s.IsAdmin;
 }