Esempio n. 1
0
        public void Dictionary_Add()
        {
            string cacheKey = "Dictionary_Add";

            handler.Remove(cacheKey);

            List <Item> items = GetNewItems(10);

            handler.Register(cacheKey, new Func <IDictionary <object, Item> >(() => items.ToDictionary(new Func <Item, object>(x => x.ID))), TimeSpan.FromMinutes(30));

            if (handler.CacheEnabled)
            {
                //handler.RegisterDictionary(cacheKey, new Func<IList<Item>>(() => items), new Func<Item, object>((x) => x.ID), TimeSpan.FromMinutes(100));
                var r = handler.Retrieve <IDictionary>(cacheKey);

                Assert.IsNotNull(r);
                Assert.AreEqual(items.Count, r.Count);

                var item = handler.DictionaryRetrieve <int, Item>(cacheKey, 1);
                Assert.IsNotNull(item);
                Assert.AreEqual(1, item.ID);
            }
            handler.Remove(cacheKey);
        }