private void _TouchAllCacheItems(TaggedScavengedExpirableCacheStore cacheStore)
 {
     foreach (string key in cacheStore.GetKeys())
     {
         cacheStore.Get(key);
     }
 }
        private List<string> _GetTagsReferredInCacheItems(TaggedScavengedExpirableCacheStore cacheStore)
        {
            HashSet<string> tagSet = new HashSet<string>();

            foreach (string key in cacheStore.GetKeys())
            {
                CacheItem cacheItem = cacheStore.Get(key);
                if (cacheItem != null)
                {
                    IExpirationSpecifier[] expirationSpecifierList = (IExpirationSpecifier[])Array.FindAll(cacheItem.ExpirationSpecifierList, (esp) => esp is TagExpirationSpecifier);
                    foreach (TagExpirationSpecifier expirationSpecifier in expirationSpecifierList)
                    {
                        PropertyInfo propertyInfo = expirationSpecifier.GetType().GetProperty("_TagInfoList", BindingFlags.NonPublic | BindingFlags.Instance);
                        List<TagInfo> tagInfoList = (List<TagInfo>)propertyInfo.GetValue(expirationSpecifier, null);
                        tagInfoList.ForEach(ti => tagSet.Add(ti.Tag));
                    }
                }
            }

            return tagSet.ToList();
        }
        private void _EnsureCacheItemsDontMatch(TaggedScavengedExpirableCacheStore cacheStore, List<string> tagCombinationList)
        {
            HashSet<string> tagCombination = new HashSet<string>(tagCombinationList);

            foreach (string key in cacheStore.GetKeys())
            {
                CacheItem cacheItem = cacheStore.Get(key);
                if (cacheItem != null)
                {
                    IExpirationSpecifier[] expirationSpecifierList = (IExpirationSpecifier[])Array.FindAll(cacheItem.ExpirationSpecifierList, (esp) => esp is TagExpirationSpecifier);
                    foreach (TagExpirationSpecifier expirationSpecifier in expirationSpecifierList)
                    {
                        PropertyInfo propertyInfo = expirationSpecifier.GetType().GetProperty("_TagInfoList", BindingFlags.NonPublic | BindingFlags.Instance);
                        List<TagInfo> tagInfoList = (List<TagInfo>)propertyInfo.GetValue(expirationSpecifier, null);

                        bool subset = true;
                        foreach(string tag in tagCombinationList)
                        {
                            subset = subset && tagInfoList.Exists(t => t.Tag == tag);
                        }

                        Assert.IsFalse(subset);
                    }
                }
            }
        }
        private void _EnsureTagExpirationStateValidity(TaggedScavengedExpirableCacheStore cacheStore)
        {
            foreach (string key in cacheStore.GetKeys())
            {
                CacheItem cacheItem = cacheStore.Get(key);
                if (cacheItem != null)
                {
                    IExpirationSpecifier[] expirationSpecifierList = (IExpirationSpecifier[])Array.FindAll(cacheItem.ExpirationSpecifierList, (esp) => esp is TagExpirationSpecifier);
                    foreach (TagExpirationSpecifier expirationSpecifier in expirationSpecifierList)
                    {
                        PropertyInfo tagInfoPropertyInfo = expirationSpecifier.GetType().GetProperty("_TagInfoList", BindingFlags.NonPublic | BindingFlags.Instance);
                        PropertyInfo tagInvalidationPropertyInfo = expirationSpecifier.GetType().GetProperty("_TagInvalidationTokenList", BindingFlags.NonPublic | BindingFlags.Instance);

                        List<TagInfo> tagInfoList = (List<TagInfo>) tagInfoPropertyInfo.GetValue(expirationSpecifier, null);
                        List<object> invalidationTokenList = (List<object>)tagInvalidationPropertyInfo.GetValue(expirationSpecifier, null);

                        for(int i = 0; i < tagInfoList.Count; ++i)
                        {
                            foreach (TagInvalidationInfo invalidationInfo in tagInfoList[i].TagInvalidationInfoList.GetEnumerable(invalidationTokenList[i]))
                            {
                                Assert.Fail("invalidation token is not supposed to be available");
                            }
                        }
                    }
                }
            }
        }
        private void _CacheBombard(TaggedScavengedExpirableCacheStore cacheStore, Random random)
        {
            object data = new object();

            try
            {
                for (int i = 0; i < 100000; i++)
                {
                    double dice = random.NextDouble();

                    if (dice <= 0.3)
                    {
                        cacheStore.Set(new CacheItem(TagCacheTestUtil.GetRandomKey(random), data, 0, TagCacheTestUtil.GetTagExpirationSpecifier(cacheStore, TagCacheTestUtil.GetRandomTagList(random, random.Next(1, 4)))));
                    }
                    else if (dice <= 0.8)
                    {
                        cacheStore.Get(TagCacheTestUtil.GetRandomKey(random));
                    }
                    else if (dice <= 0.9)
                    {
                        cacheStore.Invalidate(new List<List<string>> { new List<string> { TagCacheTestUtil.GetRandomTag(random) } });
                    }
                    else
                    {
                        cacheStore.Remove(TagCacheTestUtil.GetRandomKey(random));
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }