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 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();
                }
            }
        }
		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 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();
				}
			}
		}
        public void ExceptionThrownDuringAddResultsInObjectBeingRemovedFromCacheCompletely()
        {
            MockBackingStore backingStore = new MockBackingStore();
            ICachingInstrumentationProvider instrumentationProvider = new NullCachingInstrumentationProvider();

            Cache cache = new Cache(backingStore, instrumentationProvider);

            try
            {
                cache.Add("foo", "bar");
                Assert.Fail("Should have thrown exception thrown internally to Cache.Add");
            }
            catch (Exception)
            {
                Assert.IsFalse(cache.Contains("foo"));
                Assert.AreEqual(1, backingStore.removalCount);
            }
        }
		public void ExceptionThrownDuringAddResultsInObjectBeingRemovedFromCacheCompletely()
		{
			MockBackingStore backingStore = new MockBackingStore();
			ICachingInstrumentationProvider instrumentationProvider = new NullCachingInstrumentationProvider();

			Cache cache = new Cache(backingStore, instrumentationProvider);

            try
			{
				cache.Add("foo", "bar");
				Assert.Fail("Should have thrown exception thrown internally to Cache.Add");
			}
			catch (Exception)
			{
				Assert.IsFalse(cache.Contains("foo"));
				Assert.AreEqual(1, backingStore.removalCount);
			}
		}