コード例 #1
0
        public void AddRemoveTest()
        {
            var cache = new WeakCache <string, TestClass>(false, value => value.Text);

            TestClass item = new TestClass("1");

            cache.Add(item);
            Assert.AreEqual(1, cache.Count);

            item = new TestClass("2");
            cache.Add(item);
            Assert.AreEqual(2, cache.Count);
            Assert.AreEqual(item, cache[item.Text, false]);

            ICache <string, TestClass> icache = cache;

            Assert.AreEqual(item, icache[item.Text, false]);
            Assert.AreEqual(null, icache["3", false]);

            cache.Remove(item);
            Assert.AreEqual(1, cache.Count);

            cache.Clear();
            Assert.AreEqual(0, cache.Count);
        }
コード例 #2
0
        internal static void RemoveInternal(FrameworkElement control)
        {
            ValidationHelper.NotNull(control, "control");

            control.Dispatcher.Invoke(() => RemoveCore(control.Resources), DispatcherPriority.Render);

            Cache.Remove(control);
            Cache.Iterate(cachedControl => ApplyInternal(cachedControl, General.GetThemeResources(cachedControl)));
        }
コード例 #3
0
        public void Item_should_be_removed_on_demand()
        {
            ICache cache = new WeakCache();

            cache[0] = 0;
            Assert.That(cache[0], Is.Not.Null);

            cache.Remove(0);
            Assert.That(cache[0], Is.Null);
        }
コード例 #4
0
 private void RemoveItem()
 {
     while (!canFinish)
     {
         TestClass test = null;
         lock (globalCache) {
             foreach (TestClass testClass in globalCache)
             {
                 test = testClass;
                 break;
             }
         }
         if (test != null)
         {
             lock (globalCache) {
                 globalCache.Remove(test);
             }
         }
     }
 }
コード例 #5
0
        public void RemoveDenyTest1()
        {
            var cache = new WeakCache <string, TestClass>(false, value => value.Text);

            Assert.Throws <ArgumentNullException>(() => cache.Remove((TestClass)null));
        }