Example #1
0
        /// <summary>
        ///A test for OnItemLoading
        ///</summary>
        public void OnItemLoadingTestHelper()
        {
            TKey   k1 = new TKey();
            TKey   k2 = new TKey();
            TValue v1 = new TValue();
            TValue v2 = new TValue();
            TValue v3 = new TValue();
            TValue v4 = new TValue();
            TValue v;

            // Init cache
            Cache <TKey, TValue> cache  = new Cache <TKey, TValue>();
            TDictionary          target = CreateTarget(cache);

            // See if auto-loaded items show up in cache
            target.ItemLoading += (o, e) =>
            {
                CacheableParameterHelper cc = (CacheableParameterHelper)(object)v1;
                cc.IsCacheable = true;
                e.Value        = v1;
                e.IsFound      = true;
            };

            v = target[k1];
            Assert.AreEqual(v, v1);
            Assert.AreEqual(cache[k1], v1);

            // Make sure non-cacheable items don't show up in the cache
            cache  = new Cache <TKey, TValue>();
            target = CreateTarget(cache);

            target.ItemLoading += (o, e) =>
            {
                CacheableParameterHelper cc = (CacheableParameterHelper)(object)v1;
                cc.IsCacheable = false;
                e.Value        = v1;
                e.IsFound      = true;
            };

            v = target[k1];
            Assert.AreEqual(v, v1);
            Assert.IsFalse(cache.ContainsKey(k1));
        }
 private void CopyMembers(CacheableParameterHelper old)
 {
     this.isCacheable = old.isCacheable;
     this.cachedVersion = old.cachedVersion;
 }
 public CacheableParameterHelper(CacheableParameterHelper old)
 {
     CopyMembers(old);
 }
 private void CopyMembers(CacheableParameterHelper old)
 {
     this.isCacheable   = old.isCacheable;
     this.cachedVersion = old.cachedVersion;
 }
 public CacheableParameterHelper(CacheableParameterHelper old)
 {
     CopyMembers(old);
 }