コード例 #1
0
        public void MemoizationCacheBase_Simple()
        {
            var cleared   = false;
            var disposing = false;

            var c = new MyCache
            {
                CountF        = () => 42,
                DebugViewF    = () => "foo",
                ClearA        = b => { Assert.AreEqual(disposing, b); cleared = true; },
                GetOrAddCoreF = x => x + 1,
            };

            Assert.AreEqual(42, c.Count);
            Assert.AreEqual("foo", c.DebugView);
            Assert.AreEqual(2, c.GetOrAdd(1));

            cleared   = false;
            disposing = false;
            c.Clear();
            Assert.IsTrue(cleared);

            cleared   = false;
            disposing = true;
            c.Dispose();
            Assert.IsTrue(cleared);

            Assert.AreEqual(0, c.Count);
            Assert.AreNotEqual("foo", c.DebugView);

            Assert.ThrowsException <ObjectDisposedException>(() => c.GetOrAdd(2));
        }