Exemplo n.º 1
0
        public void SimpleCompiledDelegateCache_Basics()
        {
            var cache = new SimpleCompiledDelegateCache();

            Assert.AreEqual(0, cache.Count);

            var f1 = (Func <int>)cache.GetOrAdd(Expression.Lambda(Expression.Constant(42)));

            Assert.AreEqual(42, f1());

            Assert.AreEqual(1, cache.Count);

            var f2 = (Func <int>)cache.GetOrAdd(Expression.Lambda(Expression.Constant(42)));

            Assert.AreEqual(42, f2());
            Assert.AreSame(f1, f2);

            Assert.AreEqual(1, cache.Count);

            var f3 = (Func <int>)cache.GetOrAdd(Expression.Lambda(Expression.Constant(43)));

            Assert.AreEqual(43, f3());

            Assert.AreEqual(2, cache.Count);

            cache.Clear();

            var f4 = (Func <int>)cache.GetOrAdd(Expression.Lambda(Expression.Constant(42)));

            Assert.AreEqual(42, f4());
            Assert.AreNotSame(f1, f4);

            Assert.AreEqual(1, cache.Count);
        }
Exemplo n.º 2
0
        public void SimpleCompiledDelegateCache_ArgumentChecking()
        {
            var cache = new SimpleCompiledDelegateCache();

            Assert.ThrowsException <ArgumentNullException>(() => cache.GetOrAdd(expression: null));
        }