Exemple #1
0
        public void SetUp()
        {
            var go = new GameObject();

            this.cache              = new FileCacheForTest(go);
            this.CacheLocator       = new SimpleCacheLocator();
            this.cache.UrlLocator   = new SimpleUrlLocator();
            this.cache.Handler      = new TestCacheHandler();
            this.cache.CacheLocator = new SimpleCacheLocator();
            this.cache.Clear();
        }
Exemple #2
0
        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")));
            }
        }