예제 #1
0
        public void AddInsertsToCorrectDatabasePartition()
        {
            firstCache.Add(new CacheItem("key", "value", CacheItemPriority.Low, null));
            Assert.AreEqual(1, firstCache.Count);
            Assert.AreEqual(0, secondCache.Count);

            secondCache.Add(new CacheItem("key2", "value2", CacheItemPriority.High, null));
            Assert.AreEqual(1, firstCache.Count);
            Assert.AreEqual(1, secondCache.Count);
        }
        public void AttemptingToReadEncryptedDataWithoutDecryptingThrowsException()
        {
            StorageEncryptionFactory factory = new StorageEncryptionFactory(Context);

            IStorageEncryptionProvider encryptionProvider     = factory.CreateSymmetricProvider(CacheManagerName);
            DataBackingStore           encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = unencryptedBackingStore.Load();
        }
예제 #3
0
        public void AttemptingToReadEncryptedDataWithoutDecryptingThrowsException()
        {
            IStorageEncryptionProvider encryptionProvider = null;

            encryptionProvider = EnterpriseLibraryFactory.BuildUp <IStorageEncryptionProvider>("Fred");

            DataBackingStore encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = unencryptedBackingStore.Load();
        }
        public void DecryptedDataCanBeReadBackFromDatabase()
        {
            StorageEncryptionFactory factory = new StorageEncryptionFactory(Context);

            IStorageEncryptionProvider encryptionProvider     = factory.CreateSymmetricProvider(CacheManagerName);
            DataBackingStore           encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = encryptingBackingStore.Load();

            CacheItem retrievedItem = (CacheItem)dataInCache["key"];

            Assert.AreEqual("key", retrievedItem.Key);
            Assert.AreEqual("value", retrievedItem.Value);
            Assert.AreEqual(CacheItemPriority.Normal, retrievedItem.ScavengingPriority);
            Assert.AreEqual(typeof(MockRefreshAction), retrievedItem.RefreshAction.GetType());
            Assert.AreEqual(typeof(AlwaysExpired), retrievedItem.Expirations[0].GetType());
        }
예제 #5
0
        public void DecryptedDataCanBeReadBackFromDatabase()
        {
            IStorageEncryptionProvider encryptionProvider = null;

            encryptionProvider = EnterpriseLibraryFactory.BuildUp <IStorageEncryptionProvider>("Fred");

            DataBackingStore encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = encryptingBackingStore.Load();

            CacheItem retrievedItem = (CacheItem)dataInCache["key"];

            Assert.AreEqual("key", retrievedItem.Key);
            Assert.AreEqual("value", retrievedItem.Value);
            Assert.AreEqual(CacheItemPriority.Normal, retrievedItem.ScavengingPriority);
            Assert.AreEqual(typeof(MockRefreshAction), retrievedItem.RefreshAction.GetType());
            Assert.AreEqual(typeof(AlwaysExpired), retrievedItem.GetExpirations()[0].GetType());
        }
        public void CanResolveDataBackingStoreWithOutEncryptionProvider()
        {
            const string         key  = "fooKey";
            DataCacheStorageData data = new DataCacheStorageData("Data Cache Storage", "CachingDatabase", "fooPartition");

            settings.BackingStores.Add(data);

            CacheManagerData managerData = new CacheManagerData("defaultCacheManager", 300, 200, 100, "Data Cache Storage");

            settings.CacheManagers.Add(managerData);
            settings.DefaultCacheManager = "defaultCacheManager";

            dbSettings.DefaultDatabase = "CachingDatabase";

            container = EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource);
            DataBackingStore createdStore = container.GetInstance <DataBackingStore>("Data Cache Storage");

            Assert.IsNotNull(createdStore);
            createdStore.Add(new CacheItem(key, 1, CacheItemPriority.Low, null, null));
            Assert.AreEqual(1, createdStore.Count);
            createdStore.Remove(key);
            Assert.AreEqual(0, createdStore.Count);
        }