public void TryReleaseLockIfLockIdMatch_ValidWriteLockRelease()
        {
            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.TryReleaseLockIfLockIdMatch(lockId, 900);

                // Get actual connection and check that lock do not exists
                IDatabase actualConnection   = GetRealRedisConnection(redisConn);
                string    lockValueFromRedis = actualConnection.StringGet(redisConn.Keys.LockKey);
                Assert.Equal(null, lockValueFromRedis);

                // remove data from redis
                actualConnection.KeyDelete(redisConn.Keys.DataKey);
                DisposeRedisConnectionWrapper(redisConn);
            }
        }
        public void TryReleaseLockIfLockIdMatch_WriteLock()
        {
            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.TryReleaseLockIfLockIdMatch(lockId, 900);
            A.CallTo(() => redisConn.redisConnection.Eval(A <string> .Ignored, A <string[]> .That.Matches(s => s.Length == 3 && s[0].Equals(redisConn.Keys.LockKey)),
                                                          A <object[]> .That.Matches(o => o.Length == 2))).MustHaveHappened();
        }
 public void TryReleaseLockIfLockIdMatch_WriteLock()
 {
     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.TryReleaseLockIfLockIdMatch(lockId, 900);
     A.CallTo(() => mockRedisClient.Eval(A<string>.Ignored, A<string[]>.That.Matches(s => s.Length == 3 && s[0].Equals(redisConn.Keys.LockKey)),
          A<object[]>.That.Matches(o => o.Length == 2))).MustHaveHappened();
 }