示例#1
0
        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_Abandon_Session_If_There_Is_A_Session_Id()
        {
            SessionDatabase.CreateSession(Constants.FullSessionId, Constants.SessionStateSerializedBytes);
            var context = HttpContext.CreateWithSession();

            var session = new SessionState(new SqlSessionStateProvider());

            session.Abandon(context);
            session.Load(context);

            context.SessionState.Count().ShouldEqual(0);
            SessionDatabase.GetSession(Constants.FullSessionId).ShouldBeNull();
        }
示例#3
0
        public void Should_Load_An_Empty_Session_And_Unlock_It_Afterwards()
        {
            SessionDatabase.CreateSession(Constants.FullSessionId, Constants.SessionStateEmptySerializedBytes);
            var store        = new SqlSessionStateStore(Constants.ConnectionString, Constants.SessionTimeout);
            var sessionState = store.Load(_sessionId);

            sessionState.ShouldEqual(Constants.SessionStateEmptySerializedBytes);

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

            session.ShouldNotBeNull("No session found");
            session.Locked.ShouldBeFalse();
        }
        public void Open_Should_Sync_Session_Variables_If_There_Is_An_Active_Session()
        {
            SessionDatabase.CreateSession(Constants.FullSessionId, Constants.SessionStateSerializedBytes);
            var context = HttpContext.CreateWithSession();

            context.SessionState["test"] = "test";

            new SessionState(new SqlSessionStateProvider()).Load(context);

            context.SessionState.Count().ShouldEqual(Constants.SessionStateItemCount);
            context.SessionState[Constants.SessionStateKey1].ShouldEqual(Constants.SessionStateValue1);
            context.SessionState[Constants.SessionStateKey2].ShouldEqual(Constants.SessionStateValue2);
            context.SessionState[Constants.SessionStateKey3].ShouldEqual(Constants.SessionStateValue3);
        }
        public void Save_Should_Save_Variables_To_The_Active_Session()
        {
            SessionDatabase.CreateSession(Constants.FullSessionId, Constants.SessionStateMultiDataTypeSerializedBytes);
            var context = HttpContext.CreateWithSession(Constants.SessionState);

            var session = new SessionState(new SqlSessionStateProvider());

            session.Save(context);
            session.Load(context);

            context.SessionState.Count().ShouldEqual(Constants.SessionStateItemCount);
            context.SessionState[Constants.SessionStateKey1].ShouldEqual(Constants.SessionStateValue1);
            context.SessionState[Constants.SessionStateKey2].ShouldEqual(Constants.SessionStateValue2);
            context.SessionState[Constants.SessionStateKey3].ShouldEqual(Constants.SessionStateValue3);
        }
        public void Open_Should_Not_Sync_Incompatable_Data_Types()
        {
            SessionDatabase.CreateSession(Constants.FullSessionId, Constants.SessionStateMultiDataTypeSerializedBytes);
            var context = HttpContext.CreateWithSession();

            new SessionState(new SqlSessionStateProvider()).Load(context);

            context.SessionState.Count().ShouldEqual(Constants.SessionStateMultiDataTypeValidItemCount);
            context.SessionState[Constants.SessionStateStringKey].ShouldEqual(Constants.SessionStateStringValue);
            context.SessionState[Constants.SessionStateByteKey].ShouldEqual(Constants.SessionStateByteValue);
            context.SessionState[Constants.SessionStateBoolKey].ShouldEqual(Constants.SessionStateBoolValue);
            context.SessionState[Constants.SessionStateShortKey].ShouldEqual(Constants.SessionStateShortValue);
            context.SessionState[Constants.SessionStateIntKey].ShouldEqual(Constants.SessionStateIntValue);
            context.SessionState[Constants.SessionStateDoubleKey].ShouldEqual(Constants.SessionStateDoubleValue);
            context.SessionState[Constants.SessionStateFloatKey].ShouldEqual(Constants.SessionStateFloatValue);
            context.SessionState[Constants.SessionStateDateTimeKey].ShouldEqual(Constants.SessionStateDateTimeValue);
        }
示例#7
0
        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();
        }
示例#8
0
        public void Should_Write_Existing_Session_With_Long_Data()
        {
            SessionDatabase.CreateSession(Constants.FullSessionId, ShortData);
            var store = new SqlSessionStateStore(Constants.ConnectionString, Constants.SessionTimeout);

            store.Save(_sessionId, LongData);

            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(20);
            session.SessionItemShort.ShouldBeNull();
            session.SessionItemLong.ShouldEqual(LongData);
            session.Flags.ShouldEqual(0);
        }