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 Clear()
        {
            TimeSpan             cacheLifeTime = TimeSpan.FromMinutes(5);
            MemoryCachingService service       = new MemoryCachingService(cacheLifeTime);
            string cachableKey = this.cachableKey;
            Foobar cachable    = GetCachableObject();

            service.Cache <Foobar>(cachableKey, cachable);
            Assert.Single(service);;
            Assert.Equal(cachable, service.Retrieve <Foobar>(cachableKey).Value);

            service.Clear();
            Assert.Empty(service);
        }
        public void StaticUsage()
        {
            TimeSpan             cacheLifeTime = TimeSpan.FromMilliseconds(5);
            MemoryCachingService service       = new MemoryCachingService(cacheLifeTime, true);
            Foobar cachable = GetCachableObject();

            string   cachableKey    = this.cachableKey;
            DateTime startedCaching = DateTime.UtcNow;

            service.Cache(cachableKey, cachable);
            DateTime endedCaching = DateTime.UtcNow;
            ICachedObject <Foobar> existsRetrievedWrapper = service.Retrieve <Foobar>(cachableKey);

            MemoryCachingService   service2 = new MemoryCachingService(cacheLifeTime, true);
            ICachedObject <Foobar> existsRetrievedWrapper2 = service2.Retrieve <Foobar>(cachableKey);

            Assert.Equal(cachable, existsRetrievedWrapper.Value);
            Assert.Equal(existsRetrievedWrapper.Value, existsRetrievedWrapper2.Value);
            service2.Clear();
            Assert.Null(service.Retrieve <Foobar>(cachableKey));
        }