Fixed problem with opening non-existing files through CachingFileStorage

This commit is contained in:
Philipp Crocoll 2013-08-14 06:36:12 +02:00
parent e014b2c185
commit 04acfb99ed
3 changed files with 32 additions and 2 deletions

View File

@ -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;
}

View File

@ -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());

View File

@ -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)