public async Task SessionReadCycle_Valid() { using (RedisServer redisServer = new RedisServer()) { string sessionId = ResetRedisConnectionWrapperAndConfiguration(); // Inserting empty session with "SessionStateActions.InitializeItem" flag into redis server RedisSessionStateProvider ssp = new Oriflame.Web.Redis.RedisSessionStateProvider(); await ssp.CreateUninitializedItemAsync(FakeHttpContext, sessionId, (int)RedisSessionStateProvider.configuration.SessionTimeout.TotalMinutes, CancellationToken.None); // Get write lock and session from cache GetItemResult data = await ssp.GetItemAsync(FakeHttpContext, sessionId, CancellationToken.None); // Get actual connection and varify lock and session timeout IDatabase actualConnection = GetRealRedisConnection(); Assert.True(actualConnection.StringGet(ssp.cache.Keys.LockKey).IsNull); Assert.Equal(((int)RedisSessionStateProvider.configuration.SessionTimeout.TotalSeconds).ToString(), actualConnection.HashGet(ssp.cache.Keys.InternalKey, "SessionTimeout").ToString()); // reset sessions timoue await ssp.ResetItemTimeoutAsync(FakeHttpContext, sessionId, CancellationToken.None); // End request await ssp.EndRequestAsync(null); // remove data and lock from redis DisposeRedisConnectionWrapper(); } }
public async Task SessionTimoutChangeFromGlobalAspx() { using (RedisServer redisServer = new RedisServer()) { string sessionId = ResetRedisConnectionWrapperAndConfiguration(); // Inserting empty session with "SessionStateActions.InitializeItem" flag into redis server RedisSessionStateProvider ssp = new Oriflame.Web.Redis.RedisSessionStateProvider(); await ssp.CreateUninitializedItemAsync(FakeHttpContext, sessionId, (int)RedisSessionStateProvider.configuration.SessionTimeout.TotalMinutes, CancellationToken.None); // Get write lock and session from cache GetItemResult data = await ssp.GetItemExclusiveAsync(FakeHttpContext, sessionId, CancellationToken.None); // Get actual connection and varify lock and session timeout IDatabase actualConnection = GetRealRedisConnection(); Assert.Equal(data.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 data.Item.Items["key"] = "value"; data.Item.Timeout = 5; // session update await ssp.SetAndReleaseItemExclusiveAsync(FakeHttpContext, sessionId, data.Item, data.LockId, false, CancellationToken.None); Assert.Equal(1, actualConnection.HashGetAll(ssp.cache.Keys.DataKey).Length); Assert.Equal("300", actualConnection.HashGet(ssp.cache.Keys.InternalKey, "SessionTimeout").ToString()); // reset sessions timoue await ssp.ResetItemTimeoutAsync(FakeHttpContext, sessionId, CancellationToken.None); // End request await ssp.EndRequestAsync(FakeHttpContext); // Verify that GetItemExclusive returns timeout from redis GetItemResult data_1 = await ssp.GetItemExclusiveAsync(FakeHttpContext, sessionId, CancellationToken.None); Assert.Equal(5, data.Item.Timeout); // remove data and lock from redis DisposeRedisConnectionWrapper(); } }