Ejemplo n.º 1
0
        public void LockSessionAndReleaseLock()
        {
            var sessionStore = new SessionStore("test");

            byte[]  serializedItems = Serialize((SessionStateItemCollection)item.Items);
            Binary  sessionItems    = new Binary(serializedItems);
            string  id      = Guid.NewGuid().ToString();
            Session session = new Session(id, this.ApplicationName, this.Timeout, sessionItems, item.Items.Count, SessionStateActions.None);

            sessionStore.Insert(session);
            DateTime timestamp = DateTime.Now;

            session.LockID = 1;
            sessionStore.LockSession(session);
            Session lockedSesssion = sessionStore.Get(id, this.ApplicationName);

            Assert.AreEqual(true, lockedSesssion.Locked);
            Assert.AreEqual(1, session.LockID);
            Assert.AreNotEqual(session.LockDate, lockedSesssion.LockDate);
            Assert.AreEqual(0, lockedSesssion.Flags);
            sessionStore.ReleaseLock(lockedSesssion.SessionID, lockedSesssion.ApplicationName, lockedSesssion.LockID, item.Timeout);
            Session unlockedSession = sessionStore.Get(id, this.ApplicationName);

            Assert.AreEqual(false, unlockedSession.Locked);
            Assert.AreEqual(lockedSesssion.LockDate, unlockedSession.LockDate);
            Assert.AreNotEqual(lockedSesssion.Expires, unlockedSession.Expires);
        }
Ejemplo n.º 2
0
        public void InsertNewSessionAndEvictHard()
        {
            var sessionStore = new SessionStore("test");

            byte[]  serializedItems = Serialize((SessionStateItemCollection)item.Items);
            Binary  sessionItems    = new Binary(serializedItems);
            string  id      = Guid.NewGuid().ToString();
            Session session = new Session(id, this.ApplicationName, this.Timeout, sessionItems, item.Items.Count, SessionStateActions.None);

            sessionStore.Insert(session);
            sessionStore.EvictSession(session);
            Session storedSession = sessionStore.Get(id, this.ApplicationName);

            Assert.IsNull(storedSession);
        }
Ejemplo n.º 3
0
        public void InsertNewSession()
        {
            var sessionStore = new SessionStore("test");

            byte[]  serializedItems = Serialize((SessionStateItemCollection)item.Items);
            Binary  sessionItems    = new Binary(serializedItems);
            string  id      = Guid.NewGuid().ToString();
            Session session = new Session(id, this.ApplicationName, this.Timeout, sessionItems, item.Items.Count, SessionStateActions.None);

            sessionStore.Insert(session);
            Session storedSession = sessionStore.Get(id, this.ApplicationName);

            Assert.AreEqual(session.SessionID, storedSession.SessionID);
            Assert.AreEqual(session.ApplicationName, storedSession.ApplicationName);
            Assert.AreEqual(session.SessionItems.Bytes.Length, storedSession.SessionItems.Bytes.Length);
        }
Ejemplo n.º 4
0
        public void AddExpiredSessionAndEvictSoft()
        {
            var sessionStore = new SessionStore("test");

            byte[]  serializedItems = Serialize((SessionStateItemCollection)item.Items);
            Binary  sessionItems    = new Binary(serializedItems);
            string  id      = Guid.NewGuid().ToString();
            Session session = new Session(id, this.ApplicationName, this.Timeout, sessionItems, item.Items.Count, SessionStateActions.None);

            session.Expires = DateTime.Now.Subtract(new TimeSpan(0, 2, 0));
            sessionStore.Insert(session);
            sessionStore.EvictExpiredSession(session.SessionID, session.ApplicationName);
            Session storedSession = sessionStore.Get(session.SessionID, session.ApplicationName);

            Assert.IsNull(storedSession);
        }
Ejemplo n.º 5
0
        public void UpdateSession()
        {
            var sessionStore = new SessionStore("test");

            byte[]  serializedItems = Serialize((SessionStateItemCollection)item.Items);
            Binary  sessionItems    = new Binary(serializedItems);
            string  id      = Guid.NewGuid().ToString();
            Session session = new Session(id, this.ApplicationName, this.Timeout, sessionItems, item.Items.Count, SessionStateActions.None);

            sessionStore.Insert(session);
            sessionStore.UpdateSession(id, 5, new Binary(serializedItems), this.ApplicationName, 3, 0);
            Session updatedSession = sessionStore.Get(id, this.ApplicationName);

            Assert.AreEqual(5, updatedSession.Timeout);
            Assert.AreEqual(3, updatedSession.SessionItemsCount);
            Assert.AreEqual(DateTime.Now.AddMinutes(5).Minute, updatedSession.Expires.Minute);
        }
Ejemplo n.º 6
0
        public void TestInserts()
        {
            int i = 0;

            while (i < 200)
            {
                string id = Guid.NewGuid().ToString();
                SessionStateItemCollection items = new SessionStateItemCollection();
                items["Val1"] = "value";
                byte[]  serializedItems = Serialize(items);
                Binary  b       = new Binary(serializedItems);
                Session session = new Session(id, "AppName", 2, b, items.Count, SessionStateActions.None);
                using (var mongo = new Mongo(config))
                {
                    var sessionStore = new SessionStore("test");
                    sessionStore.Insert(session);
                    i++;
                }
            }
        }