public void SetAndReleaseItemExclusive_OldItemNullItems() { Utility.SetConfigUtilityToDefault(); string id = "session-id"; SessionStateStoreData sssd = new SessionStateStoreData(null, null, 900); var mockCache = A.Fake <ICacheConnection>(); RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider(); sessionStateStore.cache = mockCache; sessionStateStore.SetAndReleaseItemExclusive(null, id, sssd, 7, false); A.CallTo(() => mockCache.TryUpdateAndReleaseLockIfLockIdMatch(A <object> .Ignored, A <ISessionStateItemCollection> .Ignored, 900)).MustNotHaveHappened(); }
public void SetAndReleaseItemExclusive_NewItemNullItems() { Utility.SetConfigUtilityToDefault(); string id = "session-id"; SessionStateStoreData sssd = new SessionStateStoreData(null, null, 15); var mockCache = A.Fake <ICacheConnection>(); RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider(); sessionStateStore.cache = mockCache; sessionStateStore.SetAndReleaseItemExclusive(null, id, sssd, null, true); A.CallTo(() => mockCache.Set(A <ISessionStateItemCollection> .That.Matches(o => o.Count == 0), 900)).MustHaveHappened(); }
public void SessionTimoutChangeFromGlobalAspx() { using (RedisServer redisServer = new RedisServer()) { string sessionId = ResetRedisConnectionWrapperAndConfiguration(); // Inserting empty session with "SessionStateActions.InitializeItem" flag into redis server RedisSessionStateProvider ssp = new RedisSessionStateProvider(); ssp.CreateUninitializedItem(null, sessionId, (int)RedisSessionStateProvider.configuration.SessionTimeout.TotalMinutes); // Get write lock and session from cache bool locked; TimeSpan lockAge; object lockId; SessionStateActions actions; SessionStateStoreData storeData = ssp.GetItemExclusive(null, sessionId, out locked, out lockAge, out lockId, out actions); // Get actual connection and varify lock and session timeout IDatabase actualConnection = GetRealRedisConnection(); Assert.Equal(lockId.ToString(), actualConnection.StringGet(ssp.cache.Keys.LockKey).ToString()); Assert.Equal(((int)RedisSessionStateProvider.configuration.SessionTimeout.TotalSeconds).ToString(), actualConnection.HashGet(ssp.cache.Keys.InternalKey, "SessionTimeout").ToString()); // setting data as done by any normal session operation storeData.Items["key"] = "value"; storeData.Timeout = 5; // session update ssp.SetAndReleaseItemExclusive(null, sessionId, storeData, lockId, false); Assert.Equal(1, actualConnection.HashGetAll(ssp.cache.Keys.DataKey).Length); Assert.Equal("300", actualConnection.HashGet(ssp.cache.Keys.InternalKey, "SessionTimeout").ToString()); // reset sessions timoue ssp.ResetItemTimeout(null, sessionId); // End request ssp.EndRequest(null); // Verify that GetItemExclusive returns timeout from redis bool locked_1; TimeSpan lockAge_1; object lockId_1; SessionStateActions actions_1; SessionStateStoreData storeData_1 = ssp.GetItemExclusive(null, sessionId, out locked_1, out lockAge_1, out lockId_1, out actions_1); Assert.Equal(5, storeData_1.Timeout); // remove data and lock from redis DisposeRedisConnectionWrapper(); } }
public void SetAndReleaseItemExclusive_OldItemInsertedItems() { Utility.SetConfigUtilityToDefault(); string id = "session-id"; ChangeTrackingSessionStateItemCollection sessionStateItemCollection = new ChangeTrackingSessionStateItemCollection(); sessionStateItemCollection["session-key"] = "session-value"; SessionStateStoreData sssd = new SessionStateStoreData(sessionStateItemCollection, null, 15); var mockCache = A.Fake <ICacheConnection>(); RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider(); sessionStateStore.cache = mockCache; sessionStateStore.SetAndReleaseItemExclusive(null, id, sssd, 7, false); A.CallTo(() => mockCache.TryUpdateAndReleaseLockIfLockIdMatch(A <object> .Ignored, A <ChangeTrackingSessionStateItemCollection> .That.Matches(o => o.Count == 1 && o.GetModifiedKeys().Count == 1 && o.GetDeletedKeys().Count == 0), 900)).MustHaveHappened(); }
public void SetAndReleaseItemExclusive_NewItemValidItems() { Utility.SetConfigUtilityToDefault(); string id = "session-id"; ChangeTrackingSessionStateItemCollection sessionStateItemCollection = Utility.GetChangeTrackingSessionStateItemCollection(); sessionStateItemCollection["session-key"] = "session-value"; SessionStateStoreData sssd = new SessionStateStoreData(sessionStateItemCollection, null, 15); var mockCache = A.Fake <ICacheConnection>(); RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider(); sessionStateStore.cache = mockCache; sessionStateStore.SetAndReleaseItemExclusive(null, id, sssd, null, true); A.CallTo(() => mockCache.Set(A <ISessionStateItemCollection> .That.Matches( o => o.Count == 1 && o["session-key"] != null ), 900)).MustHaveHappened(); }
public void SessionWriteCycle_Valid() { using (RedisServer redisServer = new RedisServer()) { string sessionId = ResetRedisConnectionWrapperAndConfiguration(); // Inserting empty session with "SessionStateActions.InitializeItem" flag into redis server RedisSessionStateProvider ssp = new RedisSessionStateProvider(); ssp.CreateUninitializedItem(null, sessionId, (int)RedisSessionStateProvider.configuration.SessionTimeout.TotalMinutes); // Get write lock and session from cache bool locked; TimeSpan lockAge; object lockId; SessionStateActions actions; SessionStateStoreData storeData = ssp.GetItemExclusive(null, sessionId, out locked, out lockAge, out lockId, out actions); // Get actual connection and varify lock and session timeout IDatabase actualConnection = GetRealRedisConnection(); Assert.Equal(lockId.ToString(), actualConnection.StringGet(ssp.cache.Keys.LockKey).ToString()); Assert.Equal(((int)RedisSessionStateProvider.configuration.SessionTimeout.TotalSeconds).ToString(), actualConnection.HashGet(ssp.cache.Keys.InternalKey, "SessionTimeout").ToString()); // setting data as done by any normal session operation storeData.Items["key"] = "value"; // session update ssp.SetAndReleaseItemExclusive(null, sessionId, storeData, lockId, false); Assert.Equal(1, actualConnection.HashGetAll(ssp.cache.Keys.DataKey).Length); // reset sessions timoue ssp.ResetItemTimeout(null, sessionId); // End request ssp.EndRequest(null); // remove data and lock from redis DisposeRedisConnectionWrapper(); } }
public void SetAndReleaseItemExclusive_OldItemInsertedItems() { Utility.SetConfigUtilityToDefault(); string id = "session-id"; ChangeTrackingSessionStateItemCollection sessionStateItemCollection = new ChangeTrackingSessionStateItemCollection(); sessionStateItemCollection["session-key"] = "session-value"; SessionStateStoreData sssd = new SessionStateStoreData(sessionStateItemCollection, null, 15); var mockCache = A.Fake<ICacheConnection>(); RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider(); sessionStateStore.cache = mockCache; sessionStateStore.SetAndReleaseItemExclusive(null, id, sssd, 7, false); A.CallTo(() => mockCache.TryUpdateAndReleaseLockIfLockIdMatch(A<object>.Ignored, A<ChangeTrackingSessionStateItemCollection>.That.Matches(o => o.Count == 1 && o.GetModifiedKeys().Count == 1 && o.GetDeletedKeys().Count == 0), 900)).MustHaveHappened(); }
public void SetAndReleaseItemExclusive_OldItemNullItems() { Utility.SetConfigUtilityToDefault(); string id = "session-id"; SessionStateStoreData sssd = new SessionStateStoreData(null, null, 900); var mockCache = A.Fake<ICacheConnection>(); RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider(); sessionStateStore.cache = mockCache; sessionStateStore.SetAndReleaseItemExclusive(null, id, sssd, 7, false); A.CallTo(() => mockCache.TryUpdateAndReleaseLockIfLockIdMatch(A<object>.Ignored, A<ISessionStateItemCollection>.Ignored, 900)).MustNotHaveHappened(); }
public void SetAndReleaseItemExclusive_NewItemValidItems() { Utility.SetConfigUtilityToDefault(); string id = "session-id"; ChangeTrackingSessionStateItemCollection sessionStateItemCollection = new ChangeTrackingSessionStateItemCollection(); sessionStateItemCollection["session-key"] = "session-value"; SessionStateStoreData sssd = new SessionStateStoreData(sessionStateItemCollection, null, 15); var mockCache = A.Fake<ICacheConnection>(); RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider(); sessionStateStore.cache = mockCache; sessionStateStore.SetAndReleaseItemExclusive(null, id, sssd, null, true); A.CallTo(() => mockCache.Set(A<ISessionStateItemCollection>.That.Matches( o => o.Count == 1 && o["session-key"] != null ), 900)).MustHaveHappened(); }