本文整理汇总了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");
}