public void RemoveBranching()
        {
            TimeSpan             cacheLifeTime = TimeSpan.FromMinutes(5);
            MemoryCachingService service       = new MemoryCachingService(cacheLifeTime);
            Foobar cachable    = GetCachableObject();
            string cachableKey = this.cachableKey;
            KeyValuePair <string, ICachedObjectBasic> originalItem = 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 = GetCachableKvp(originalTime, cacheLifeTime, null, cachableKey);
            service.Add(item);
            Assert.False(service.Remove(originalItem));

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

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

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

            service.Clear();
            Assert.Empty(service);
            item = GetCachableKvp(originalTime, cacheLifeTime, GetCachableObject(), cachableKey);
            service.Add(item);
            Assert.False(service.Remove(originalItem));
        }
        public void Contains()
        {
            TimeSpan             cacheLifeTime = TimeSpan.FromMinutes(5);
            MemoryCachingService service       = new MemoryCachingService(cacheLifeTime);
            Foobar cachable    = GetCachableObject();
            string cachableKey = this.cachableKey;
            KeyValuePair <string, ICachedObjectBasic> item = GetCachableKvp(DateTime.UtcNow, cacheLifeTime, cachable, cachableKey);

            Assert.DoesNotContain(item, service);
            service.Add(item);
            Assert.Contains(item, service);
        }
        public void AddKvp()
        {
            TimeSpan             cacheLifeTime = TimeSpan.FromMinutes(5);
            MemoryCachingService service       = new MemoryCachingService(cacheLifeTime);
            Foobar cachable    = GetCachableObject();
            string cachableKey = this.cachableKey;
            KeyValuePair <string, ICachedObjectBasic> item = GetCachableKvp(DateTime.UtcNow, cacheLifeTime, cachable, cachableKey);

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

            Assert.Equal(cachable, result.Value);
        }
        public void Add()
        {
            TimeSpan             cacheLifeTime = TimeSpan.FromMinutes(5);
            MemoryCachingService service       = new MemoryCachingService(cacheLifeTime);
            string cachableKey = this.cachableKey;
            Foobar cachable    = GetCachableObject();
            DefaultCachedObject <object> dto = new DefaultCachedObject <object>
            {
                Value      = cachable,
                CachedTime = DateTime.UtcNow,
                ExpireTime = DateTime.UtcNow.Add(cacheLifeTime)
            };

            service.Add(cachableKey, dto);
            Assert.Single(service);;
            Assert.Equal(dto.Value, service.Retrieve <Foobar>(cachableKey).Value);
        }