예제 #1
0
        public void Test_GlobalCache()
        {
            // We don't want to test the singleton

            var unique_prefix = "test_cache_" + Guid.NewGuid() + "__";
            var cacheType     = Type.GetType("ImageResizer.Plugins.WriteThroughCache, ImageResizer");

            Debug.Assert(cacheType != null, "cacheType != null");
            var cacheCtor = cacheType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null,
                                                     new[] { typeof(string) }, null);
            var cacheInstance = cacheCtor.Invoke(new object[] { unique_prefix });


            var c          = new PersistentGlobalStringCache();
            var cacheField = typeof(PersistentGlobalStringCache)
                             .GetField("cache", BindingFlags.NonPublic | BindingFlags.Instance);

            Debug.Assert(cacheField != null, "cacheField != null");
            cacheField.SetValue(c, cacheInstance);

            Assert.Equal(StringCachePutResult.WriteComplete, c.TryPut("a", "b"));
            Assert.Equal(StringCachePutResult.Duplicate, c.TryPut("a", "b"));
            Assert.Equal("b", c.Get("a"));
            Assert.Equal(null, c.Get("404"));
            Assert.Equal(StringCachePutResult.WriteComplete, c.TryPut("a", null));
            Assert.NotNull(Config.Current.GetDiagnosticsPage());
            Assert.NotNull(Config.Current.GetLicensesPage());
        }
        public void Test_GlobalCache()
        {
            // We don't want to test the singleton

            var uniquePrefix = "test_cache_" + Guid.NewGuid() + "__";

            var cacheInstance = new WriteThroughCache(uniquePrefix, new[] { Path.GetTempPath() });

            var c          = new PersistentGlobalStringCache(uniquePrefix, new[] { Path.GetTempPath() });
            var cacheField = typeof(PersistentGlobalStringCache)
                             .GetField("cache", BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.NotNull(cacheField);
            cacheField.SetValue(c, cacheInstance);

            try
            {
                Assert.Equal(StringCachePutResult.WriteComplete, c.TryPut("a", "b"));
                Assert.Equal(StringCachePutResult.Duplicate, c.TryPut("a", "b"));
                Assert.Equal("b", c.Get("a"));
                Assert.Null(c.Get("404"));
                Assert.Equal(StringCachePutResult.WriteComplete, c.TryPut("a", null));
            }
            catch
            {
                output.WriteLine(c.GetIssues().Delimited("\r\n"));
                throw;
            }
        }