public void Add(bool compressValues, bool useBasic)
        {
            TimeSpan            cacheLifeTime = TimeSpan.FromMinutes(5);
            RedisCachingService service       = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic);

            service.Clear();
            string cachableKey = RedisHelpers.CachableKey;
            Foobar cachable    = RedisHelpers.GetCachableObject();
            DefaultCachedObject <object> dto = new DefaultCachedObject <object>
            {
                Value      = cachable,
                CachedTime = DateTime.UtcNow,
                ExpireTime = DateTime.UtcNow.Add(cacheLifeTime)
            };

            service.Add(cachableKey, dto);
            Assert.Single(service);
            var    theSingle      = service.Values.Single();
            var    theValue       = theSingle.UntypedValue;
            string returnedString = theValue as string;

            Assert.False(string.IsNullOrWhiteSpace(returnedString));
            Foobar returned = RedisHelpers.SerializationService.DeserializeObject <Foobar>(returnedString, RedisHelpers.SerializationSettings);

            Assert.True(RedisHelpers.CheckFooBarEquality(cachable, returned));
        }
        public void RemoveBranching(bool compressValues, bool useBasic)
        {
            TimeSpan            cacheLifeTime = TimeSpan.FromMinutes(5);
            RedisCachingService service       = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic);

            service.Clear();
            Foobar cachable    = RedisHelpers.GetCachableObject();
            string cachableKey = RedisHelpers.CachableKey;
            KeyValuePair <string, ICachedObjectBasic> originalItem = RedisHelpers.GetCachableKvp(DateTime.UtcNow, cacheLifeTime, cachable, cachableKey);
            KeyValuePair <string, ICachedObjectBasic> item;
            DateTime originalTime = originalItem.Value.CachedTime;

            Assert.False(service.Remove(originalItem));

            service.Clear();
            Assert.Empty(service);
            item = RedisHelpers.GetCachableKvp(originalTime, cacheLifeTime, null, cachableKey);
            service.Add(item);
            Assert.False(service.Remove(originalItem));

            service.Clear();
            Assert.Empty(service);
            item = RedisHelpers.GetCachableKvp(originalTime, TimeSpan.FromMilliseconds(100), cachable, cachableKey);
            service.Add(item);
            Thread.Sleep(100);
            Assert.False(service.Remove(originalItem));
            Assert.Empty(service);

            service.Clear();
            Assert.Empty(service);
            item = RedisHelpers.GetCachableKvp(originalTime.AddSeconds(10), cacheLifeTime, cachable, cachableKey);
            service.Add(item);
            Assert.False(service.Remove(originalItem));

            service.Clear();
            Assert.Empty(service);
            item = RedisHelpers.GetCachableKvp(originalTime, TimeSpan.FromMinutes(4), cachable, cachableKey);
            service.Add(item);
            Assert.False(service.Remove(originalItem));

            service.Clear();
            Assert.Empty(service);
            item = RedisHelpers.GetCachableKvp(originalTime, cacheLifeTime, RedisHelpers.GetCachableObject(), cachableKey);
            service.Add(item);
            Assert.False(service.Remove(originalItem));
        }
        public void Contains(bool compressValues, bool useBasic)
        {
            TimeSpan            cacheLifeTime = TimeSpan.FromMinutes(5);
            RedisCachingService service       = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic);

            service.Clear();
            Foobar cachable    = RedisHelpers.GetCachableObject();
            string cachableKey = RedisHelpers.CachableKey;
            KeyValuePair <string, ICachedObjectBasic> item = RedisHelpers.GetCachableKvp(DateTime.UtcNow, cacheLifeTime, cachable, cachableKey);

            Assert.DoesNotContain(item, service);
            service.Add(item);
            Assert.Contains(item, service);
        }
        public void AddKvp(bool compressValues, bool useBasic)
        {
            TimeSpan            cacheLifeTime = TimeSpan.FromMinutes(5);
            RedisCachingService service       = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic);

            service.Clear();
            Foobar cachable    = RedisHelpers.GetCachableObject();
            string cachableKey = RedisHelpers.CachableKey;
            KeyValuePair <string, ICachedObjectBasic> item = RedisHelpers.GetCachableKvp(DateTime.UtcNow, cacheLifeTime, cachable, cachableKey);

            service.Add(item);
            ICachedObject <Foobar> result = service.Retrieve <Foobar>(cachableKey);

            Assert.True(RedisHelpers.CheckFooBarEquality(cachable, result.Value));
        }