Fixed problem with opening non-existing files through CachingFileStorage
This commit is contained in:
		@@ -66,7 +66,7 @@ namespace keepass2android.Io
 | 
			
		||||
			{
 | 
			
		||||
				if ((ex.Response is HttpWebResponse) && (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound))
 | 
			
		||||
				{
 | 
			
		||||
					throw new FileNotFoundException("404!", ioc.Path, ex);
 | 
			
		||||
					throw new FileNotFoundException(ex.Message, ioc.Path, ex);
 | 
			
		||||
				}
 | 
			
		||||
				throw;
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -146,6 +146,9 @@ namespace keepass2android.Io
 | 
			
		||||
			}
 | 
			
		||||
			catch (Exception ex)
 | 
			
		||||
			{
 | 
			
		||||
				if (!IsCached(ioc))
 | 
			
		||||
					throw;
 | 
			
		||||
 | 
			
		||||
				Kp2aLog.Log("couldn't open from remote " + ioc.Path);
 | 
			
		||||
				Kp2aLog.Log(ex.ToString());
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
@@ -46,6 +47,32 @@ namespace Kp2aUnitTests
 | 
			
		||||
			_testCacheSupervisor.AssertSingleCall(TestCacheSupervisor.CouldntOpenFromRemoteId);
 | 
			
		||||
			
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// Tests correct behavior in case that a file is to be opened which is not in the cache
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		[TestMethod]
 | 
			
		||||
		public void TestOpenNonExistingNonCachedFiles()
 | 
			
		||||
		{
 | 
			
		||||
			SetupFileStorage();
 | 
			
		||||
 | 
			
		||||
			//read the file once. Should now be in the cache.
 | 
			
		||||
			try
 | 
			
		||||
			{
 | 
			
		||||
				MemoryStream fileContents = ReadToMemoryStream(_fileStorage, "nonexistingfile.txt");
 | 
			
		||||
			}
 | 
			
		||||
			catch (Exception e)
 | 
			
		||||
			{
 | 
			
		||||
				_testCacheSupervisor.AssertNoCall();
 | 
			
		||||
				Assert.IsInstanceOfType(e, typeof(FileNotFoundException));
 | 
			
		||||
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			_testCacheSupervisor.AssertNoCall();
 | 
			
		||||
			Assert.Fail("didn't get exception!");
 | 
			
		||||
			
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private string MemoryStreamToString(MemoryStream stream)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user