public void Should_Abandon_Session()
        {
            SessionDatabase.CreateSession(Constants.FullSessionId, ShortData);
            var store = new SqlSessionStateStore(Constants.ConnectionString, Constants.SessionTimeout);
            store.Abandon(_sessionId);

            var session = SessionDatabase.GetSession(Constants.FullSessionId);

            session.ShouldBeNull();
        }
        public void Should_Load_A_Session_And_Unlock_It_Afterwards()
        {
            SessionDatabase.CreateSession(Constants.FullSessionId, ShortData);
            var store = new SqlSessionStateStore(Constants.ConnectionString, Constants.SessionTimeout);
            var sessionState = store.Load(_sessionId);

            sessionState.ShouldEqual(ShortData);

            var session = SessionDatabase.GetSession(Constants.FullSessionId);

            session.ShouldNotBeNull("No session found");
            session.Locked.ShouldBeFalse();
        }
        public void Should_Concurrently_Load_A_Session_And_Unlock_It_Afterwards()
        {
            SessionDatabase.CreateSession(Constants.FullSessionId, ShortData);
            var store = new SqlSessionStateStore(Constants.ConnectionString, Constants.SessionTimeout);
            var results = new ConcurrentBag<bool>();

            for (var i = 0; i < 20; i++) ThreadPool.QueueUserWorkItem(
                x => results.Add((store.Load(_sessionId) ?? new byte[] {}).SequenceEqual(ShortData)));

            while (results.Count < 20) Thread.Sleep(100);

            results.All(x => x).ShouldBeTrue();
        }
 public void Should_Return_A_Null_Session()
 {
     var store = new SqlSessionStateStore(Constants.ConnectionString, Constants.SessionTimeout);
     var session = store.Load(_sessionId);
     session.ShouldBeNull();
 }
        public void Should_Write_New_Session_With_Short_Data()
        {
            var store = new SqlSessionStateStore(Constants.ConnectionString, Constants.SessionTimeout);
            store.Save(_sessionId, ShortData);

            var session = SessionDatabase.GetSession(Constants.FullSessionId);

            session.ShouldNotBeNull("No session found");
            session.Locked.ShouldBeFalse();
            session.Created.ShouldBeInRange(DateTime.UtcNow.AddSeconds(-5), DateTime.UtcNow.AddSeconds(5));
            session.Expires.ShouldBeInRange(DateTime.UtcNow.AddMinutes(20).AddSeconds(-5), DateTime.UtcNow.AddMinutes(20).AddSeconds(5));
            session.LockDate.ShouldBeInRange(DateTime.UtcNow.AddSeconds(-5), DateTime.UtcNow.AddSeconds(5));
            session.LockDateLocal.ShouldBeInRange(DateTime.Now.AddSeconds(-5), DateTime.Now.AddSeconds(5));
            session.LockCookie.ShouldEqual(1);
            session.Timeout.ShouldEqual(Constants.SessionTimeout);
            session.SessionItemShort.ShouldEqual(ShortData);
            session.SessionItemLong.ShouldBeNull();
            session.Flags.ShouldEqual(0);
        }