예제 #1
0
파일: CacheTests.cs 프로젝트: nevergofull/A
        public void Dictionary_ReplaceExisting()
        {
            string cacheKey = "Dictionary_ReplaceExisting";

            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));

            //replace existing key
            var newItem = new Item()
            {
                ID = 1, Count = 400, Name = "New Name"
            };

            handler.DictionaryReplace(cacheKey, 1, newItem);
            if (handler.CacheEnabled)
            {
                var cachedItem = handler.DictionaryRetrieve <int, Item>(cacheKey, 1);

                Assert.IsNotNull(cachedItem);
                Assert.AreEqual(newItem.ID, cachedItem.ID);
                Assert.AreEqual(newItem.Name, cachedItem.Name);
                Assert.AreEqual(newItem.Count, cachedItem.Count);
            }
            else
            {
                var cachedItem = handler.DictionaryRetrieve <int, Item>(cacheKey, 1);
                Assert.IsNull(cachedItem);
            }

            handler.Remove(cacheKey);
        }