Ejemplo n.º 1
0
        public void Delete()
        {
            var cmd = SessionDatabase.CreateCommand();

            cmd.CommandText = "DELETE FROM sessions WHERE sessionid = @sessionid";
            cmd.Parameters.AddWithValue("@sessionid", SessionID);
            cmd.ExecuteNonQuery();
        }
Ejemplo n.º 2
0
        public override void WillTerminate(UIApplication application)
        {
            // clean up when we die.

            Console.WriteLine("terminating");
            UIApplication.SharedApplication.ApplicationIconBadgeNumber = SessionDatabase.LastSeenDownloadCount;
            SessionDatabase.Dispose();
            SessionDatabase = null;

            UIApplication.SharedApplication.IdleTimerDisabled = false;
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        public string Get(string name)
        {
            var cmd = SessionDatabase.CreateCommand();

            cmd.CommandText = "SELECT value FROM sessions WHERE sessionid = @sessionid AND name = @name";
            cmd.Parameters.AddWithValue("@sessionid", SessionID);
            cmd.Parameters.AddWithValue("@name", name);
            var result = cmd.ExecuteScalar();

            return(result == null ? null : result.ToString());
        }
Ejemplo n.º 5
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 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();
        }
        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);
        }
Ejemplo n.º 9
0
 public void Set(string name, string value)
 {
     if (value == null)
     {
         Delete(name);
     }
     else
     {
         var cmd = SessionDatabase.CreateCommand();
         cmd.CommandText = "INSERT OR REPLACE INTO sessions (sessionid, name, value) VALUES (@sessionid, @name, @value)";
         cmd.Parameters.AddWithValue("@sessionid", SessionID);
         cmd.Parameters.AddWithValue("@name", name);
         cmd.Parameters.AddWithValue("@value", value);
         cmd.ExecuteNonQuery();
     }
 }
        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);
        }
Ejemplo n.º 11
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();
        }
Ejemplo n.º 12
0
        public void Should_Write_New_Session_With_Long_Data()
        {
            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);
        }
Ejemplo n.º 13
0
 public QueryHandler(SessionDatabase db, IMapper mapper)
 {
     _db     = db;
     _mapper = mapper;
 }
Ejemplo n.º 14
0
 public void SetUp()
 {
     sut = new SessionDatabase();
 }
 public void TearDown()
 {
     SessionDatabase.ClearSessions();
 }
 public void Setup()
 {
     SessionDatabase.ClearSessions();
 }
Ejemplo n.º 17
0
 public CommandHandler(SessionDatabase db, IMapper mapper)
 {
     _db     = db;
     _mapper = mapper;
 }