public void Remove () { var mc = new PokerMemoryCache ("MyCache"); AssertExtensions.Throws<NotSupportedException> (() => { mc.Remove ("key", "region"); }, "#A1-1"); AssertExtensions.Throws<ArgumentNullException> (() => { mc.Remove (null); }, "#A1-2"); bool callbackInvoked; CacheEntryRemovedReason reason = (CacheEntryRemovedReason) 1000; var cip = new CacheItemPolicy (); cip.Priority = CacheItemPriority.NotRemovable; mc.Set ("key2", "value1", cip); object value = mc.Remove ("key2"); Assert.IsNotNull (value, "#B1-1"); Assert.IsFalse (mc.Contains ("key2"), "#B1-2"); cip = new CacheItemPolicy (); cip.RemovedCallback = (CacheEntryRemovedArguments args) => { callbackInvoked = true; reason = args.RemovedReason; }; mc.Set ("key", "value", cip); callbackInvoked = false; reason = (CacheEntryRemovedReason) 1000; value = mc.Remove ("key"); Assert.IsNotNull (value, "#C1-1"); Assert.IsTrue (callbackInvoked, "#C1-2"); Assert.AreEqual (CacheEntryRemovedReason.Removed, reason, "#C1-3"); cip = new CacheItemPolicy (); cip.RemovedCallback = (CacheEntryRemovedArguments args) => { callbackInvoked = true; reason = args.RemovedReason; throw new ApplicationException ("test"); }; mc.Set ("key", "value", cip); callbackInvoked = false; reason = (CacheEntryRemovedReason) 1000; value = mc.Remove ("key"); Assert.IsNotNull (value, "#C2-1"); Assert.IsTrue (callbackInvoked, "#C2-2"); Assert.AreEqual (CacheEntryRemovedReason.Removed, reason, "#C2-3"); // LAMESPEC: UpdateCallback is not called on remove cip = new CacheItemPolicy (); cip.UpdateCallback = (CacheEntryUpdateArguments args) => { callbackInvoked = true; reason = args.RemovedReason; }; mc.Set ("key", "value", cip); callbackInvoked = false; reason = (CacheEntryRemovedReason) 1000; value = mc.Remove ("key"); Assert.IsNotNull (value, "#D1-1"); Assert.IsFalse (callbackInvoked, "#D1-2"); cip = new CacheItemPolicy (); cip.UpdateCallback = (CacheEntryUpdateArguments args) => { callbackInvoked = true; reason = args.RemovedReason; throw new ApplicationException ("test"); }; mc.Set ("key", "value", cip); callbackInvoked = false; reason = (CacheEntryRemovedReason) 1000; value = mc.Remove ("key"); Assert.IsNotNull (value, "#D2-1"); Assert.IsFalse (callbackInvoked, "#D2-2"); }