本文整理匯總了C#中MonoTests.Common.PokerMemoryCache.DoGetEnumerator方法的典型用法代碼示例。如果您正苦於以下問題:C# PokerMemoryCache.DoGetEnumerator方法的具體用法?C# PokerMemoryCache.DoGetEnumerator怎麽用?C# PokerMemoryCache.DoGetEnumerator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MonoTests.Common.PokerMemoryCache
的用法示例。
在下文中一共展示了PokerMemoryCache.DoGetEnumerator方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetEnumerator
public void GetEnumerator ()
{
var mc = new PokerMemoryCache ("MyCache");
// This one is a Hashtable enumerator
IEnumerator enumerator = ((IEnumerable) mc).GetEnumerator ();
// This one is a Dictionary <string, object> enumerator
IEnumerator enumerator2 = mc.DoGetEnumerator ();
Assert.IsNotNull (enumerator, "#A1-1");
Assert.IsNotNull (enumerator2, "#A1-2");
Assert.IsTrue (enumerator.GetType () != enumerator2.GetType (), "#A1-3");
mc.Set ("key1", "value1", null);
mc.Set ("key2", "value2", null);
mc.Set ("key3", "value3", null);
bool expired = false;
var cip = new CacheItemPolicy ();
cip.AbsoluteExpiration = DateTime.Now.AddMilliseconds (50);
cip.RemovedCallback = (CacheEntryRemovedArguments args) => {
expired = true;
};
mc.Set ("key4", "value4", cip);
Thread.Sleep (100);
enumerator = ((IEnumerable) mc).GetEnumerator ();
int count = 0;
while (enumerator.MoveNext ()) {
count++;
}
Assert.IsFalse (expired, "#A2-1");
Assert.AreEqual (3, count, "#A2-2");
expired = false;
cip = new CacheItemPolicy ();
cip.AbsoluteExpiration = DateTime.Now.AddMilliseconds (50);
cip.RemovedCallback = (CacheEntryRemovedArguments args) => {
expired = true;
};
mc.Set ("key5", "value5", cip);
Thread.Sleep (100);
enumerator2 = mc.DoGetEnumerator ();
count = 0;
while (enumerator2.MoveNext ()) {
count++;
}
Assert.IsFalse (expired, "#A3-1");
Assert.AreEqual (3, count, "#A3-2");
}