public void TryRemoveIfLockIdMatch_ValidLockIdAndRemove() { ProviderConfiguration pc = Utility.GetDefaultConfigUtility(); using (RedisServer redisServer = new RedisServer()) { RedisConnectionWrapper redisConn = GetRedisConnectionWrapperWithUniqueSession(); // Inserting data into redis server ChangeTrackingSessionStateItemCollection data = new ChangeTrackingSessionStateItemCollection(new RedisUtility(pc)); data["key"] = "value"; redisConn.Set(data, 900); int lockTimeout = 900; DateTime lockTime = DateTime.Now; object lockId; ISessionStateItemCollection dataFromRedis; int sessionTimeout; Assert.True(redisConn.TryTakeWriteLockAndGetData(lockTime, lockTimeout, out lockId, out dataFromRedis, out sessionTimeout)); Assert.Equal(lockTime.Ticks.ToString(), lockId.ToString()); Assert.Equal(1, dataFromRedis.Count); redisConn.TryRemoveAndReleaseLockIfLockIdMatch(lockId); // Get actual connection and get data from redis IDatabase actualConnection = GetRealRedisConnection(redisConn); Assert.False(actualConnection.KeyExists(redisConn.Keys.DataKey)); // check lock removed from redis Assert.False(actualConnection.KeyExists(redisConn.Keys.LockKey)); DisposeRedisConnectionWrapper(redisConn); } }
public void TryRemoveIfLockIdMatch_Valid() { string id = "session_id"; object lockId = DateTime.Now.Ticks; RedisConnectionWrapper.sharedConnection = A.Fake <RedisSharedConnection>(); RedisConnectionWrapper redisConn = new RedisConnectionWrapper(Utility.GetDefaultConfigUtility(), id); redisConn.redisConnection = A.Fake <IRedisClientConnection>(); redisConn.TryRemoveAndReleaseLockIfLockIdMatch(lockId); A.CallTo(() => redisConn.redisConnection.Eval(A <string> .Ignored, A <string[]> .That.Matches(s => s.Length == 3), A <object[]> .That.Matches(o => o.Length == 1))).MustHaveHappened(); }
public void TryRemoveIfLockIdMatch_Valid() { string id = "session_id"; object lockId = DateTime.Now.Ticks; var mockRedisClient = A.Fake<IRedisClientConnection>(); RedisConnectionWrapper.sharedConnection = new RedisSharedConnection(null, null); RedisConnectionWrapper.sharedConnection.connection = mockRedisClient; RedisConnectionWrapper redisConn = new RedisConnectionWrapper(Utility.GetDefaultConfigUtility(), id); redisConn.TryRemoveAndReleaseLockIfLockIdMatch(lockId); A.CallTo(() => mockRedisClient.Eval(A<string>.Ignored, A<string[]>.That.Matches(s => s.Length == 3), A<object[]>.That.Matches(o => o.Length == 1))).MustHaveHappened(); }