Skip to content

Commit

Permalink
issues/22 test(FileCacheTest): fix test for check deleting multiple d…
Browse files Browse the repository at this point in the history
…irectory cache
  • Loading branch information
mattak committed May 6, 2017
1 parent 290a607 commit a03d45e
Showing 1 changed file with 73 additions and 17 deletions.
90 changes: 73 additions & 17 deletions Assets/Editor/Test/FileCacheTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Unicache.Plugin;
using UnicacheExample.Version;
using UniRx;

namespace Unicache.Test
Expand Down Expand Up @@ -74,27 +76,81 @@ public void SetCacheTest()
public void FetchTest()
{
int count = 0;
Assert.IsFalse(this.cache.HasCache("foo"));
// fetch from download
{
Assert.IsFalse(this.cache.HasCache("foo"));

this.cache.Fetch("foo")
.Subscribe(data =>
{
count++;
Assert.AreEqual(data, new byte[] {0x01});
});
this.cache.Fetch("foo")
.Subscribe(data =>
{
count++;
Assert.AreEqual(data, new byte[] {0x01});
});

Assert.IsTrue(this.cache.HasCache("foo"));
Assert.AreEqual(count, 1);
Assert.IsTrue(this.cache.HasCache("foo"));
Assert.AreEqual(count, 1);
}

this.cache.Fetch("foo")
.Subscribe(data =>
{
count++;
Assert.AreEqual(data, new byte[] {0x01});
});
// fetch from cache
{
this.cache.Fetch("foo")
.Subscribe(data =>
{
count++;
Assert.AreEqual(data, new byte[] {0x01});
});

Assert.IsTrue(this.cache.HasCache("foo"));
Assert.AreEqual(count, 2);
}
}

Assert.IsTrue(this.cache.HasCache("foo"));
Assert.AreEqual(count, 2);
[Test]
public void FetchDeleteTest()
{
var count = 0;
var dir = UnicacheConfig.Directory;
var v1map = new Dictionary<String, String> {{"foo", "v1"}};
var v2map = new Dictionary<String, String> {{"foo", "v2"}};
var locator1 = new VersionCacheLocator(v1map);
var locator2 = new VersionCacheLocator(v2map);

// v1 download
{
this.cache.CacheLocator = locator1;
Assert.IsFalse(File.Exists(dir + locator1.CreateCachePath("foo")));
Assert.IsFalse(File.Exists(dir + locator2.CreateCachePath("foo")));

this.cache.Fetch("foo")
.Subscribe(data =>
{
count++;
Assert.AreEqual(data, new byte[] {0x01});
});
Assert.IsTrue(this.cache.HasCache("foo"));
Assert.AreEqual(count, 1);
Assert.IsTrue(File.Exists(dir + locator1.CreateCachePath("foo")));
Assert.IsFalse(File.Exists(dir + locator2.CreateCachePath("foo")));
}

// check automatically remove outdated file
// version up & v2 download
{
this.cache.CacheLocator = locator2;
Assert.IsTrue(File.Exists(dir + locator1.CreateCachePath("foo")));
Assert.IsFalse(File.Exists(dir + locator2.CreateCachePath("foo")));

this.cache.Fetch("foo")
.Subscribe(data =>
{
count++;
Assert.AreEqual(data, new byte[] {0x01});
});
Assert.IsTrue(this.cache.HasCache("foo"));
Assert.AreEqual(count, 2);
Assert.IsFalse(File.Exists(dir + locator1.CreateCachePath("foo")));
Assert.IsTrue(File.Exists(dir + locator2.CreateCachePath("foo")));
}
}

[Test]
Expand Down

0 comments on commit a03d45e

Please sign in to comment.