示例#1
0
        public void InternCache_Create_Dispose()
        {
            var cache = InternCache.CreateInternCache <string>(MemoizationCacheFactory.Unbounded);

            cache.Intern("bar".ToUpper());
            cache.Intern("bar".ToUpper());

            cache.Dispose();

            Assert.ThrowsException <ObjectDisposedException>(() => cache.Intern("bar".ToUpper()));
        }
示例#2
0
        public void InternCache_Create_Service()
        {
            var cache = InternCache.CreateInternCache <string>(MemoizationCacheFactory.Unbounded);

            var trim = cache.GetService <ITrimmable <KeyValuePair <string, string> > >();

            Assert.IsNotNull(trim);

            cache.Intern("bar".ToUpper());

            Assert.AreEqual(1, cache.Count);

            trim.Trim(kv => kv.Key == "BAR");

            Assert.AreEqual(0, cache.Count);
        }
示例#3
0
        public void InternCache_Create_Simple2()
        {
            var cache = InternCache.CreateInternCache <string>(MemoizationCacheFactory.Unbounded);

            for (var n = 0; n < 2; n++)
            {
                for (var i = 0; i < 100; i++)
                {
                    Assert.AreEqual("BAR", cache.Intern("bar".ToUpper()));
                }

                Assert.AreEqual(1, cache.Count);

                cache.Clear();
                Assert.AreEqual(0, cache.Count);
            }
        }
示例#4
0
        public void InternCache_Create_Simple1()
        {
            var cache = InternCache.CreateInternCache <string>(MemoizationCacheFactory.Unbounded);

            var arg1 = "bar".ToUpper();
            var res1 = cache.Intern(arg1);

            Assert.AreEqual("BAR", res1);

            Assert.AreSame(arg1, res1);

            var arg2 = "bar".ToUpper();
            var res2 = cache.Intern(arg2);

            Assert.AreEqual("BAR", res2);

            Assert.AreNotSame(arg2, res2);
            Assert.AreSame(res1, res2);

            Assert.IsFalse(string.IsNullOrEmpty(cache.DebugView));
        }
示例#5
0
 public void InternCache_Create_ArgumentChecking()
 {
     Assert.ThrowsException <ArgumentNullException>(() => InternCache.CreateInternCache <string>(cacheFactory: null));
 }