当前位置: 首页>>代码示例>>C#>>正文


C# PokerMemoryCache.AddOrGetExisting方法代码示例

本文整理汇总了C#中MonoTests.Common.PokerMemoryCache.AddOrGetExisting方法的典型用法代码示例。如果您正苦于以下问题:C# PokerMemoryCache.AddOrGetExisting方法的具体用法?C# PokerMemoryCache.AddOrGetExisting怎么用?C# PokerMemoryCache.AddOrGetExisting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MonoTests.Common.PokerMemoryCache的用法示例。


在下文中一共展示了PokerMemoryCache.AddOrGetExisting方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddOrGetExisting_String_Object_CacheItemPolicy_String

		public void AddOrGetExisting_String_Object_CacheItemPolicy_String ()
		{
			var mc = new PokerMemoryCache ("MyCache");

			AssertExtensions.Throws<ArgumentNullException> (() => {
				mc.AddOrGetExisting (null, "value", null);
			}, "#A1-1");

			AssertExtensions.Throws<ArgumentNullException> (() => {
				mc.AddOrGetExisting ("key", null, null);
			}, "#A1-2");

			var cip = new CacheItemPolicy ();
			cip.AbsoluteExpiration = DateTime.Now.AddMinutes (1);
			cip.SlidingExpiration = TimeSpan.FromMinutes (1);

			AssertExtensions.Throws<ArgumentException> (() => {
				mc.AddOrGetExisting ("key", "value", cip);
			}, "#A1-3");

			cip = new CacheItemPolicy ();
			cip.SlidingExpiration = TimeSpan.MinValue;
			AssertExtensions.Throws<ArgumentOutOfRangeException> (() => {
				mc.AddOrGetExisting ("key3", "value", cip);
			}, "#A1-4");

			AssertExtensions.Throws<NotSupportedException> (() => {
				mc.AddOrGetExisting ("key", "value", null, "region");
			}, "#A1-5");

			cip = new CacheItemPolicy ();
			cip.SlidingExpiration = TimeSpan.FromDays (500);
			AssertExtensions.Throws<ArgumentOutOfRangeException> (() => {
				mc.AddOrGetExisting ("key3", "value", cip);
			}, "#A1-6");

			cip = new CacheItemPolicy ();
			cip.Priority = (CacheItemPriority) 20;
			AssertExtensions.Throws<ArgumentOutOfRangeException> (() => {
				mc.AddOrGetExisting ("key3", "value", cip);
			}, "#A1-7");

			cip = new CacheItemPolicy ();
			cip.SlidingExpiration = TimeSpan.FromTicks (0L);
			mc.AddOrGetExisting ("key3_A2-1", "value", cip);
			Assert.IsTrue (mc.Contains ("key3_A2-1"), "#A2-1");

			cip = new CacheItemPolicy ();
			cip.SlidingExpiration = TimeSpan.FromDays (365);
			mc.AddOrGetExisting ("key3_A2-2", "value", cip);
			Assert.IsTrue (mc.Contains ("key3_A2-2"), "#A2-2");

			cip = new CacheItemPolicy ();
			cip.RemovedCallback = (CacheEntryRemovedArguments arguments) => { };
			object value = mc.AddOrGetExisting ("key3_A2-3", "value", cip);
			Assert.IsTrue (mc.Contains ("key3_A2-3"), "#A2-3");
			Assert.IsNull (value, "#A2-4");

			mc.Calls.Clear ();
			value = mc.AddOrGetExisting ("key3_A2-3", "value2", null);
			Assert.IsTrue (mc.Contains ("key3_A2-3"), "#A3-1");
			Assert.IsNotNull (value, "#A3-2");
			Assert.AreEqual ("value", value, "#A3-3");
			Assert.AreEqual (2, mc.Calls.Count, "#A3-4");
			Assert.AreEqual ("AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)", mc.Calls [0], "#A3-5");

			cip = new CacheItemPolicy ();
			cip.AbsoluteExpiration = DateTimeOffset.MinValue;
			value = mc.AddOrGetExisting ("key_expired", "value", cip);
			Assert.IsFalse (mc.Contains ("key_expired"), "#A4-1");
			Assert.IsNull (value, "#A4-1");
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:72,代码来源:MemoryCacheTest.cs

示例2: AddOrGetExisting_CacheItem_CacheItemPolicy

		public void AddOrGetExisting_CacheItem_CacheItemPolicy ()
		{
			var mc = new PokerMemoryCache ("MyCache");
			CacheItem ci, ci2;

			AssertExtensions.Throws<ArgumentNullException> (() => {
				ci = mc.AddOrGetExisting (null, new CacheItemPolicy ());
			}, "#A1");

			ci = new CacheItem ("key", "value");
			ci2 = mc.AddOrGetExisting (ci, null);

			// LAMESPEC: MSDN says it should return null if the entry does not exist yet.
			//
			Assert.IsNotNull (ci2, "#A2-1"); 
			Assert.AreNotEqual (ci, ci2, "#A2-2");
			Assert.IsNull (ci2.Value, "#A2-3");
			Assert.IsTrue (mc.Contains (ci.Key), "#A2-4");
			Assert.AreEqual (ci.Key, ci2.Key, "#A2-5");

			ci = new CacheItem ("key", "value");
			ci2 = mc.AddOrGetExisting (ci, null);
			Assert.IsNotNull (ci2, "#A3-1");
			Assert.AreNotEqual (ci, ci2, "#A3-2");
			Assert.IsNotNull (ci2.Value, "#A3-3");
			Assert.AreEqual (ci.Value, ci2.Value, "#A3-4");
			Assert.AreEqual (ci.Key, ci2.Key, "#A3-5");

			AssertExtensions.Throws<ArgumentNullException> (() => {
				ci = new CacheItem (null, "value");
				ci2 = mc.AddOrGetExisting (ci, null);
			}, "#A4");

			ci = new CacheItem (String.Empty, "value");
			ci2 = mc.AddOrGetExisting (ci, null);
			Assert.IsNotNull (ci2, "#A5-1");
			Assert.AreNotEqual (ci, ci2, "#A5-2");
			Assert.IsNull (ci2.Value, "#A5-3");
			Assert.IsTrue (mc.Contains (ci.Key), "#A5-4");
			Assert.AreEqual (ci.Key, ci2.Key, "#A5-5");

			ci = new CacheItem ("key2", null);

			// Thrown from:
			// at System.Runtime.Caching.MemoryCacheEntry..ctor(String key, Object value, DateTimeOffset absExp, TimeSpan slidingExp, CacheItemPriority priority, Collection`1 dependencies, CacheEntryRemovedCallback removedCallback, MemoryCache cache)
			// at System.Runtime.Caching.MemoryCache.AddOrGetExistingInternal(String key, Object value, CacheItemPolicy policy)
			// at System.Runtime.Caching.MemoryCache.AddOrGetExisting(CacheItem item, CacheItemPolicy policy)
			// at MonoTests.System.Runtime.Caching.MemoryCacheTest.AddOrGetExisting_CacheItem_CacheItemPolicy() in C:\Users\grendel\documents\visual studio 2010\Projects\System.Runtime.Caching.Test\System.Runtime.Caching.Test\System.Runtime.Caching\MemoryCacheTest.cs:line 211
			AssertExtensions.Throws<ArgumentNullException> (() => {
				ci2 = mc.AddOrGetExisting (ci, null);
			}, "#B1");
			
			ci = new CacheItem ("key3", "value");
			var cip = new CacheItemPolicy ();
			cip.UpdateCallback = (CacheEntryUpdateArguments arguments) => { };
			AssertExtensions.Throws<ArgumentException> (() => {
				ci2 = mc.AddOrGetExisting (ci, cip);
			}, "#B2");

			ci = new CacheItem ("key3", "value");
			cip = new CacheItemPolicy ();
			cip.AbsoluteExpiration = DateTimeOffset.Now;
			cip.SlidingExpiration = TimeSpan.FromTicks (DateTime.Now.Ticks);
			AssertExtensions.Throws<ArgumentException> (() => {
				mc.AddOrGetExisting (ci, cip);
			}, "#B3");

			ci = new CacheItem ("key3", "value");
			cip = new CacheItemPolicy ();
			cip.SlidingExpiration = TimeSpan.MinValue;
			AssertExtensions.Throws<ArgumentOutOfRangeException> (() => {
				mc.AddOrGetExisting (ci, cip);
			}, "#B4-1");

			ci = new CacheItem ("key4_#B4-2", "value");
			cip = new CacheItemPolicy ();
			cip.SlidingExpiration = TimeSpan.FromTicks (0L);
			mc.AddOrGetExisting (ci, cip);
			Assert.IsTrue (mc.Contains ("key4_#B4-2"), "#B4-2");

			ci = new CacheItem ("key3", "value");
			cip = new CacheItemPolicy ();
			cip.SlidingExpiration = TimeSpan.FromDays (500);
			AssertExtensions.Throws<ArgumentOutOfRangeException> (() => {
				mc.AddOrGetExisting (ci, cip);
			}, "#B5-1");

			ci = new CacheItem ("key5_#B5-2", "value");
			cip = new CacheItemPolicy ();
			cip.SlidingExpiration = TimeSpan.FromDays (365);
			mc.AddOrGetExisting (ci, cip);
			Assert.IsTrue (mc.Contains ("key5_#B5-2"), "#B5-2");

			ci = new CacheItem ("key3", "value");
			cip = new CacheItemPolicy ();
			cip.Priority = (CacheItemPriority)20;
			AssertExtensions.Throws<ArgumentOutOfRangeException> (() => {
				mc.AddOrGetExisting (ci, cip);
			}, "#B6");

//.........这里部分代码省略.........
开发者ID:stabbylambda,项目名称:mono,代码行数:101,代码来源:MemoryCacheTest.cs

示例3: AddOrGetExisting_String_Object_DateTimeOffset_String

		public void AddOrGetExisting_String_Object_DateTimeOffset_String ()
		{
			var mc = new PokerMemoryCache ("MyCache");

			AssertExtensions.Throws<ArgumentNullException> (() => {
				mc.AddOrGetExisting (null, "value", DateTimeOffset.Now);
			}, "#A1-1");

			AssertExtensions.Throws<ArgumentNullException> (() => {
				mc.AddOrGetExisting ("key", null, DateTimeOffset.Now);
			}, "#A1-2");
			
			AssertExtensions.Throws<NotSupportedException> (() => {
				mc.AddOrGetExisting ("key", "value", DateTimeOffset.Now, "region");
			}, "#A1-3");

			object value = mc.AddOrGetExisting ("key3_A2-1", "value", DateTimeOffset.Now.AddMinutes (1));
			Assert.IsTrue (mc.Contains ("key3_A2-1"), "#A2-1");
			Assert.IsNull (value, "#A2-2");

			mc.Calls.Clear ();
			value = mc.AddOrGetExisting ("key3_A2-1", "value2", DateTimeOffset.Now.AddMinutes (1));
			Assert.IsTrue (mc.Contains ("key3_A2-1"), "#A3-1");
			Assert.IsNotNull (value, "#A3-2");
			Assert.AreEqual ("value", value, "#A3-3");
			Assert.AreEqual (2, mc.Calls.Count, "#A3-4");
			Assert.AreEqual ("AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)", mc.Calls [0], "#A3-5");

			value = mc.AddOrGetExisting ("key_expired", "value", DateTimeOffset.MinValue);
			Assert.IsFalse (mc.Contains ("key_expired"), "#A4-1");
			Assert.IsNull (value, "#A4-1");
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:32,代码来源:MemoryCacheTest.cs


注:本文中的MonoTests.Common.PokerMemoryCache.AddOrGetExisting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。