Example #1
0
        public void can_clear_databaseCache()
        {
            Item[] items = null;
            CreateFullGraphCatalog("testcatlog", ref items);

            var client  = Locator.GetInstance <CatalogClient>();
            var catalog = client.GetCatalog("testcatlog");

            Assert.NotNull(catalog);

            //Check that there are items in cache
            var cachedItems        = CacheRepository.GetEnumerator();
            var catalogCachedItems = new List <object>();

            while (cachedItems.MoveNext())
            {
                if (cachedItems.Key.ToString().StartsWith(CacheHelper.CreateCacheKey(Constants.CatalogCachePrefix)))
                {
                    catalogCachedItems.Add(cachedItems.Entry);
                }
            }
            Assert.NotEmpty(catalogCachedItems);

            //Clear cache
            var cacheService = Locator.GetInstance <ICacheService>();
            var removedCount = cacheService.ClearDatabaseCache(Constants.CatalogCachePrefix);

            Assert.True(removedCount > 0, "Nothing was removed from cache");

            catalogCachedItems.Clear();
            cachedItems = CacheRepository.GetEnumerator();
            while (cachedItems.MoveNext())
            {
                if (cachedItems.Key.ToString().StartsWith(CacheHelper.CreateCacheKey(Constants.CatalogCachePrefix)))
                {
                    catalogCachedItems.Add(cachedItems.Entry);
                }
            }

            Assert.Empty(catalogCachedItems);
        }