public void ItemAddedPreviousToFailedAddIsRemovedCompletelyIfSecondAddFails()
        {
            using (IsolatedStorageBackingStore backingStore = new IsolatedStorageBackingStore("foo", null))
            {
                ICachingInstrumentationProvider instrumentationProvider = new NullCachingInstrumentationProvider();

                Cache cache = new Cache(backingStore, instrumentationProvider);

                cache.Add("my", new SerializableClass());

                try
                {
                    try
                    {
                        cache.Add("my", new NonSerializableClass());
                        Assert.Fail("Should have thrown exception internally to Cache.Add");
                    }
                    catch (Exception)
                    {
                        Assert.IsFalse(cache.Contains("my"));
                        Assert.AreEqual(0, backingStore.Count);

                        Hashtable isolatedStorageContents = backingStore.Load();
                        Assert.AreEqual(0, isolatedStorageContents.Count);
                    }
                }
                finally
                {
                    backingStore.Flush();
                }
            }
        }
        public void ItemAddedPreviousToFailedAddIsRemovedCompletelyIfSecondAddFails()
        {
            TestConfigurationContext context = new TestConfigurationContext();

            using (IsolatedStorageBackingStore backingStore = new IsolatedStorageBackingStore("foo"))
            {
                CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", new CachingConfigurationView(context));

                Cache cache = new Cache(backingStore, scavengingPolicy);
                cache.Initialize(this);

                cache.Add("my", new SerializableClass());

                try
                {
                    cache.Add("my", new NonSerializableClass());
                    Assert.Fail("Should have thrown exception internally to Cache.Add");
                }
                catch (Exception)
                {
                    Assert.IsFalse(cache.Contains("my"));
                    Assert.AreEqual(0, backingStore.Count);

                    Hashtable isolatedStorageContents = backingStore.Load();
                    Assert.AreEqual(0, isolatedStorageContents.Count);
                }
            }
        }
        public void ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater()
        {
            using (IsolatedStorageBackingStore backingStore = new IsolatedStorageBackingStore("foo", null))
            {
                ICachingInstrumentationProvider instrumentationProvider = new NullCachingInstrumentationProvider();

                Cache cache = new Cache(backingStore, instrumentationProvider);

                try
                {
                    try
                    {
                        cache.Add("my", new NonSerializableClass());
                        Assert.Fail("Should have thrown exception internally to Cache.Add");
                    }
                    catch (Exception)
                    {
                        cache.Add("my", new SerializableClass());
                        Assert.IsTrue(cache.Contains("my"));
                    }
                }
                finally
                {
                    backingStore.Flush();
                }
            }
        }
Beispiel #4
0
        public void WillNotFailForUpdatingAnInvalidEntry()
        {
            const string invalidKey           = "invalidKey";
            CacheItem    item                 = new CacheItem("foo", "bar", CacheItemPriority.None, null);
            IsolatedStorageBackingStore store = new IsolatedStorageBackingStore("test");

            store.Add(item);
            store.UpdateLastAccessedTime(invalidKey, DateTime.Now);
        }
        public void NullIsolatedStorageAreaNameThrowsException()
        {
            IsolatedStorageCacheStorageData configData = new IsolatedStorageCacheStorageData();
            configData.Name = "foo";
            configData.TypeName = typeof(IsolatedStorageBackingStore).AssemblyQualifiedName;
            configData.PartitionName = null;

            IsolatedStorageBackingStore localStore = new IsolatedStorageBackingStore();
            localStore.Initialize(new TestCachingConfigurationView(configData, Context));
        }
        public void EmptyIsolatedStorageAreaNameThrowsException()
        {
            IsolatedStorageCacheStorageData configData = new IsolatedStorageCacheStorageData();

            configData.Name          = "foo";
            configData.TypeName      = typeof(IsolatedStorageBackingStore).AssemblyQualifiedName;
            configData.PartitionName = "";

            IsolatedStorageBackingStore localStore = new IsolatedStorageBackingStore();

            localStore.Initialize(new TestCachingConfigurationView(configData, Context));
        }
        public void CanCreateIsolatedCacheStorageWithoutEncryption()
        {
            IsolatedStorageCacheStorageData data = new IsolatedStorageCacheStorageData("name", "", "partition");

            settings.BackingStores.Add(data);

            IServiceLocator container = EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource);

            IsolatedStorageBackingStore createdObject = (IsolatedStorageBackingStore)container.GetInstance <IBackingStore>("name");

            Assert.IsNotNull(createdObject);
        }
        public void WillLoadOneItem()
        {
            CacheItem item = new CacheItem("foo", "bar", CacheItemPriority.NotRemovable, null);

            backingStore.Add(item);

            IsolatedStorageBackingStore loadingStore = new IsolatedStorageBackingStore("foo");
            Hashtable items = loadingStore.Load();

            Assert.AreEqual(1, items.Count);
            Assert.AreEqual("bar", ((CacheItem)items["foo"]).Value);
            Assert.AreEqual(item.Key, ((CacheItem)items["foo"]).Key);
        }
        public IBackingStore Assemble(IBuilderContext context, CacheStorageData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            IsolatedStorageCacheStorageData castedObjectConfiguration
                = (IsolatedStorageCacheStorageData)objectConfiguration;
            IStorageEncryptionProvider encryptionProvider
                = GetStorageEncryptionProvider(context, castedObjectConfiguration.StorageEncryption, configurationSource, reflectionCache);
            IBackingStore createdObject
                = new IsolatedStorageBackingStore(
                      castedObjectConfiguration.PartitionName,
                      encryptionProvider);

            return(createdObject);
        }
        public void CanInitializeBackingStoreFromConfigurationObjects()
        {
            IsolatedStorageBackingStore localStore = new IsolatedStorageBackingStore("Storage");

            localStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, null));
            localStore.Dispose();

            IsolatedStorageBackingStore testStore = new IsolatedStorageBackingStore("Storage");
            Hashtable loadedItems = testStore.Load();
            testStore.Flush();
            testStore.Dispose();

            Assert.AreEqual(1, loadedItems.Count, "One item should have been loaded into Storage backing store");
        }
        public void CanInitializeBackingStoreFromConfigurationObjects()
        {
            IsolatedStorageBackingStore localStore = new IsolatedStorageBackingStore("Storage");

            localStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, null));
            localStore.Dispose();

            IsolatedStorageBackingStore testStore = new IsolatedStorageBackingStore("Storage");
            Hashtable loadedItems = testStore.Load();

            testStore.Flush();
            testStore.Dispose();

            Assert.AreEqual(1, loadedItems.Count, "One item should have been loaded into Storage backing store");
        }
        public void WillLoadMultipleItems()
        {
            CacheItem firstItem  = new CacheItem("foo1", "bar1", CacheItemPriority.Low, null);
            CacheItem secondItem = new CacheItem("foo2", "bar2", CacheItemPriority.Low, null);
            CacheItem thirdItem  = new CacheItem("foo3", "bar3", CacheItemPriority.Low, null);

            backingStore.Add(firstItem);
            backingStore.Add(secondItem);
            backingStore.Add(thirdItem);

            IsolatedStorageBackingStore loadingStore = new IsolatedStorageBackingStore("foo");
            Hashtable items = loadingStore.Load();

            Assert.AreEqual(3, items.Count);
            Assert.AreEqual("foo2", ((CacheItem)items["foo2"]).Key);
            Assert.AreEqual("foo1", ((CacheItem)items["foo1"]).Key);
            Assert.AreEqual("foo3", ((CacheItem)items["foo3"]).Key);
        }
        public void CanInitializeBackingStoreFromConfigurationObjects()
        {
            IsolatedStorageCacheStorageData configData = new IsolatedStorageCacheStorageData();
            configData.Name = "foo";
            configData.TypeName = typeof(IsolatedStorageBackingStore).AssemblyQualifiedName;
            configData.PartitionName = "Storage";

            IsolatedStorageBackingStore localStore = new IsolatedStorageBackingStore();
            localStore.Initialize(new TestCachingConfigurationView(configData, Context));

            localStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, null));
            localStore.Dispose();

            IsolatedStorageBackingStore testStore = new IsolatedStorageBackingStore("Storage");
            Hashtable loadedItems = testStore.Load();
            testStore.Flush();
            testStore.Dispose();

            Assert.AreEqual(1, loadedItems.Count, "One item should have been loaded into Storage backing store");
        }
        public void ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater()
        {
            using (IsolatedStorageBackingStore backingStore = new IsolatedStorageBackingStore("foo", null))
            {
                CacheCapacityScavengingPolicy  scavengingPolicy        = new CacheCapacityScavengingPolicy(10);
                CachingInstrumentationProvider instrumentationProvider = new CachingInstrumentationProvider();

                Cache cache = new Cache(backingStore, scavengingPolicy, instrumentationProvider);
                cache.Initialize(this);

                try
                {
                    cache.Add("my", new NonSerializableClass());
                    Assert.Fail("Should have thrown exception internally to Cache.Add");
                }
                catch (Exception)
                {
                    cache.Add("my", new SerializableClass());
                    Assert.IsTrue(cache.Contains("my"));
                }
            }
        }
        public void CanInitializeBackingStoreFromConfigurationObjects()
        {
            IsolatedStorageCacheStorageData configData = new IsolatedStorageCacheStorageData();

            configData.Name          = "foo";
            configData.TypeName      = typeof(IsolatedStorageBackingStore).AssemblyQualifiedName;
            configData.PartitionName = "Storage";

            IsolatedStorageBackingStore localStore = new IsolatedStorageBackingStore();

            localStore.Initialize(new TestCachingConfigurationView(configData, Context));

            localStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, null));
            localStore.Dispose();

            IsolatedStorageBackingStore testStore = new IsolatedStorageBackingStore("Storage");
            Hashtable loadedItems = testStore.Load();

            testStore.Flush();
            testStore.Dispose();

            Assert.AreEqual(1, loadedItems.Count, "One item should have been loaded into Storage backing store");
        }
        public void ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater()
        {
            TestConfigurationContext context = new TestConfigurationContext();

            using (IsolatedStorageBackingStore backingStore = new IsolatedStorageBackingStore("foo"))
            {
                CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", new CachingConfigurationView(context));

                Cache cache = new Cache(backingStore, scavengingPolicy);
                cache.Initialize(this);

                try
                {
                    cache.Add("my", new NonSerializableClass());
                    Assert.Fail("Should have thrown exception internally to Cache.Add");
                }
                catch (Exception)
                {
                    cache.Add("my", new SerializableClass());
                    Assert.IsTrue(cache.Contains("my"));
                }
            }
        }
Beispiel #17
0
 public void CreateIsolatdStorageArea()
 {
     backingStore = new IsolatedStorageBackingStore("EntLib");
     backingStore.Flush();
 }
 public void CreateIsolatdStorageArea()
 {
     backingStore   = new IsolatedStorageBackingStore("foo");
     differentStore = new IsolatedStorageBackingStore("diffFoo");
 }
 public void EmptyIsolatedStorageAreaNameThrowsException()
 {
     IsolatedStorageBackingStore localStore = new IsolatedStorageBackingStore(string.Empty);
 }
 public void NullIsolatedStorageAreaNameThrowsException()
 {
     IsolatedStorageBackingStore localStore = new IsolatedStorageBackingStore(null);
 }
 public void WillNotFailForUpdatingAnInvalidEntry()
 {
     const string invalidKey = "invalidKey";
     CacheItem item = new CacheItem("foo", "bar", CacheItemPriority.None, null);
     IsolatedStorageBackingStore store = new IsolatedStorageBackingStore("test");
     store.Add(item);
     store.UpdateLastAccessedTime(invalidKey, DateTime.Now);
 }
 public void EmptyIsolatedStorageAreaNameThrowsException()
 {
     IsolatedStorageBackingStore localStore = new IsolatedStorageBackingStore(string.Empty);
 }
 public void NullIsolatedStorageAreaNameThrowsException()
 {
     IsolatedStorageBackingStore localStore = new IsolatedStorageBackingStore(null);
 }
		public void CreateIsolatdStorageArea()
        {
            backingStore = new IsolatedStorageBackingStore("foo", null);
            differentStore = new IsolatedStorageBackingStore("diffFoo", null);
        }
        public void WillLoadMultipleItems()
        {
            CacheItem firstItem = new CacheItem("foo1", "bar1", CacheItemPriority.Low, null);
            CacheItem secondItem = new CacheItem("foo2", "bar2", CacheItemPriority.Low, null);
            CacheItem thirdItem = new CacheItem("foo3", "bar3", CacheItemPriority.Low, null);

            backingStore.Add(firstItem);
            backingStore.Add(secondItem);
            backingStore.Add(thirdItem);

            IsolatedStorageBackingStore loadingStore = new IsolatedStorageBackingStore("foo");
            Hashtable items = loadingStore.Load();
            Assert.AreEqual(3, items.Count);
            Assert.AreEqual("foo2", ((CacheItem)items["foo2"]).Key);
            Assert.AreEqual("foo1", ((CacheItem)items["foo1"]).Key);
            Assert.AreEqual("foo3", ((CacheItem)items["foo3"]).Key);
        }
        public void WillLoadOneItem()
        {
            CacheItem item = new CacheItem("foo", "bar", CacheItemPriority.NotRemovable, null);
            backingStore.Add(item);

            IsolatedStorageBackingStore loadingStore = new IsolatedStorageBackingStore("foo", null);
            Hashtable items = loadingStore.Load();
            Assert.AreEqual(1, items.Count);
            Assert.AreEqual("bar", ((CacheItem)items["foo"]).Value);
            Assert.AreEqual(item.Key, ((CacheItem)items["foo"]).Key);
        }
 public void CreateIsolatdStorageArea()
 {
     backingStore = new IsolatedStorageBackingStore("EntLib");
 }