Ejemplo n.º 1
0
        public void TryGetValue_ReturnsDefaultIfNotExists()
        {
            var cache = new NanoCache <string, int>();

            cache.TryGetValue("item", out var value);
            Assert.AreEqual(0, value);
        }
Ejemplo n.º 2
0
        public void TryGetValue_ReturnsTrueIfItemDoesExist()
        {
            var cache = new NanoCache <string, int> {
                ["item"] = 1234
            };

            Assert.IsTrue(cache.TryGetValue("item", out _));
        }
Ejemplo n.º 3
0
        public void TryGetValue_ReturnsItemIfExists()
        {
            var cache = new NanoCache <string, int> {
                ["item"] = 1234
            };

            cache.TryGetValue("item", out var value);
            Assert.AreEqual(1234, value);
        }
Ejemplo n.º 4
0
        public void TryGetValue_ReturnsFalseIfItemExpired()
        {
            var cache = new NanoCache <string, int>();

            cache.Set("item", 1234, 10);
            Thread.Sleep(100);

            Assert.IsFalse(cache.TryGetValue("item", out _));
        }
Ejemplo n.º 5
0
        public void Count_IsUpdatedWhenExpiredItemIsFlushed1()
        {
            var cache = new NanoCache <string, int>();

            cache.Set("1", 1, 10);
            Thread.Sleep(100);

            cache.TryGetValue("1", out _);

            Assert.AreEqual(0, cache.Count);
        }
Ejemplo n.º 6
0
        public void TryGetValue_ThrowsException_IfKeyIsNull()
        {
            var cache = new NanoCache <string, int>();

            Assert.Throws <ArgumentNullException>(() => cache.TryGetValue(null, out _));
        }
Ejemplo n.º 7
0
        public void TryGetValue_ReturnsFalseIfItemDoesNotExist()
        {
            var cache = new NanoCache <string, int>();

            Assert.IsFalse(cache.TryGetValue("item", out _));
        }