public void Encode_Will_Reversibly_Serialize_And_Ecrypt_An_Object() { //arrange var testObject = new TestType("test-object-for-compression"); var encoder = ResolveType.Of<ICacheItemEncoder>(); //act var encryptedObject = encoder.Encode(testObject, StorageStyle.Encrypted); var decryptedObject = encoder.Decode<TestType>(encryptedObject, StorageStyle.Encrypted); Assert.IsNotNull(decryptedObject); Assert.AreEqual(decryptedObject.TestString, "test-object-for-compression"); }
public void Add_Long_Term_Absolute() { //arrange var cache = ResolveType.Of<ICache>(); var key = Key.KeyCreator.Create(_longTermBoundary, StorageStyle.Unmodified, ExpirationType.Absolute, "friendly-name"); var testType = new TestType(("test-string")); //act cache.Add(key, testType); //assert Assert.IsNotNull(key); Assert.AreEqual((DistCache.Get(key.ToString()) as TestType).TestString, "test-string"); }
public void Add_Overwrites_Existing_Cache_Items() { //arrange var cache = ResolveType.Of<ICache>(); var key1 = Key.KeyCreator.Create(_shortTimeSpan, StorageStyle.Unmodified, ExpirationType.Absolute, "friendly-name1"); var testType1 = new TestType(("test-string-1")); var testType2 = new TestType(("test-string-2")); //act cache.Add(key1, testType1); cache.Add(key1, testType2); //assert Assert.AreEqual((HttpRuntime.Cache[key1.ToString()] as TestType).TestString, "test-string-2"); }
public void Add_Short_Term_Absolute() { //arrange var cache = ResolveType.Of<ICache>(); var key = Key.KeyCreator.Create(_shortTimeSpan, StorageStyle.Unmodified, ExpirationType.Absolute, "friendly-name"); var testType = new TestType(("test-string")); //act cache.Add(key, testType); //assert Assert.IsNotNull(key); Assert.AreEqual((HttpRuntime.Cache[key.ToString()] as TestType).TestString, "test-string"); }
public void Remove_Removes_The_Specified_Item_From_The_Relevant_Cache() { //arrange var cache = ResolveType.Of<ICache>(); var key1 = Key.KeyCreator.Create(_shortTimeSpan, StorageStyle.Unmodified, ExpirationType.Absolute, "friendly-name1"); var key2 = Key.KeyCreator.Create(_shortTimeSpan, StorageStyle.Unmodified, ExpirationType.Absolute, "friendly-name2"); var key3 = Key.KeyCreator.Create(_longTermBoundary, StorageStyle.Unmodified, ExpirationType.Absolute, "friendly-name3"); var testType = new TestType(("test-string")); //act cache.Add(key1, testType); cache.Add(key2, testType); cache.Add(key3, testType); //act cache.Remove(key2); //assert Assert.IsNull(cache[key2.ToString()]); Assert.AreEqual(HttpRuntime.Cache.Count, 1); Assert.IsNotNull(cache[key1.ToString()]); Assert.IsNotNull(cache[key3.ToString()]); //act cache.Remove(key3); //assert Assert.AreEqual(HttpRuntime.Cache.Count, 1); Assert.IsNotNull(cache[key1.ToString()]); Assert.IsNull(cache[key2.ToString()]); Assert.IsNull(cache[key3.ToString()]); }
public void Items_Can_Be_Added_And_Retrieved_From_The_Cache_Based_Upon_A_Key_Calculated_At_Runtime_Short_Term() { var cache = ResolveType.Of<ICache>(); TestType topFeeds = null; var success = false; var key = new Key(_shortTimeSpan, ExpirationType.Absolute, "top-ten-rss-feeds"); if (cache[key.ToString()] == null) { topFeeds = new TestType(("top-ten-feeds")); success = cache.Add(key, topFeeds); } else { topFeeds = cache.Get<TestType>(key); } Assert.IsTrue(success); Assert.AreEqual(topFeeds.TestString, "top-ten-feeds"); Assert.IsNotNull(cache.Get<TestType>(key)); Assert.IsNotNull(HttpRuntime.Cache[key.ToString()]); Assert.AreEqual((HttpRuntime.Cache[key.ToString()] as TestType).TestString, "top-ten-feeds"); }
public void Get_And_Indexer_Retrieves_An_Object_From_The_Appropriate_Cache_Implementation() { //arrange var cache = ResolveType.Of<ICache>(); var key1 = Key.KeyCreator.Create(_shortTimeSpan, StorageStyle.Unmodified, ExpirationType.Absolute, "friendly-name1"); var key2 = Key.KeyCreator.Create(_longTermBoundary, StorageStyle.Unmodified, ExpirationType.Absolute, "friendly-name2"); var testType1 = new TestType(("test-string-1")); var testType2 = new TestType(("test-string-2")); //act cache.Add(key1, testType1); cache.Add(key2, testType2); var shortObject = cache.Get<TestType>(key1); var longObject = cache.Get<TestType>(key2); var shortObjectFromIndexer = cache[key1.ToString()] as TestType; var longObjectFromIndexer = cache[key2.ToString()] as TestType; //assert Assert.AreEqual(shortObject.TestString, "test-string-1"); Assert.AreEqual(longObject.TestString, "test-string-2"); Assert.AreEqual(shortObjectFromIndexer.TestString, "test-string-1"); Assert.AreEqual(longObjectFromIndexer.TestString, "test-string-2"); }
public void Count_All_Returns_The_Count() { //arrange var cache = ResolveType.Of<ICache>(); var key1 = Key.KeyCreator.Create(_shortTimeSpan, StorageStyle.Unmodified, ExpirationType.Absolute, "friendly-name1"); var key2 = Key.KeyCreator.Create(_shortTimeSpan, StorageStyle.Unmodified, ExpirationType.Absolute, "friendly-name2"); var key3 = Key.KeyCreator.Create(_longTermBoundary, StorageStyle.Unmodified, ExpirationType.Absolute, "friendly-name3"); var testType = new TestType(("test-string")); //act cache.Add(key1, testType); cache.Add(key2, testType); cache.Add(key3, testType); //assert Assert.AreEqual(HttpRuntime.Cache.Count, 2); //long term not counted Assert.AreEqual(cache.CountAll, 2); //act cache.RemoveAll(); //assert Assert.AreEqual(cache.CountAll, 0); }