Skip to content

Instantly share code, notes, and snippets.

Created January 6, 2013 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4465472 to your computer and use it in GitHub Desktop.
Save anonymous/4465472 to your computer and use it in GitHub Desktop.
Investigating why Akavache and roaming/local storage doesn't play nice with one specific API
using System.IO;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Akavache;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
namespace Tests
{
[TestClass]
public class CacheDirectoryFailingTests
{
public class MyPersistentBlobCache : PersistentBlobCache
{
public MyPersistentBlobCache(string cacheDirectory = null, IScheduler scheduler = null) : base(cacheDirectory, null, scheduler) { }
}
static MyPersistentBlobCache SetupCache(string cacheDirectory)
{
var fixture = new MyPersistentBlobCache(cacheDirectory);
// ensuring we are working with a clear cache
fixture.InvalidateAll();
return fixture;
}
static string RoamingFolder()
{
return Path.Combine(Windows.Storage.ApplicationData.Current.RoamingFolder.Path, "BlobCache");
}
static string LocalFolder()
{
return Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "BlobCache");
}
static string InstalledLocation()
{
return Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "BlobCache");
}
class SomethingUseful { public int Id; }
[TestInitialize]
public void TestInitalize()
{
BlobCache.ApplicationName = "MyApp";
}
[TestMethod]
public async Task GetOrFetchObject_UsingRoamingStore_ReturnsCreatedObject()
{
// failing
var fixture = SetupCache(RoamingFolder());
var existingValueNoExpiration = await fixture.GetOrFetchObject(
"KeyOne",
() => Observable.Return(new SomethingUseful { Id = 1 }));
Assert.IsNotNull(existingValueNoExpiration);
Assert.AreEqual(1, existingValueNoExpiration.Id);
}
[TestMethod]
public async Task GetOrFetchObject_UsingLocalAccount_ReturnsCreatedObject()
{
// also doesn't work
var fixture = SetupCache(LocalFolder());
var existingValueNoExpiration = await fixture.GetOrFetchObject(
"KeyOne",
() => Observable.Return(new SomethingUseful { Id = 1 }));
Assert.IsNotNull(existingValueNoExpiration);
Assert.AreEqual(1, existingValueNoExpiration.Id);
}
[TestMethod]
public async Task GetOrFetchObject_UsingPackageInstallPathAccount_ReturnsCreatedObject()
{
// but this works yay!
var fixture = SetupCache(InstalledLocation());
var existingValueNoExpiration = await fixture.GetOrFetchObject(
"KeyOne",
() => Observable.Return(new SomethingUseful { Id = 1 }));
Assert.IsNotNull(existingValueNoExpiration);
Assert.AreEqual(1, existingValueNoExpiration.Id);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment