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

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

            cache.Set("item", 999);
            Assert.AreEqual(cache["item"], 999);
        }
Exemplo n.º 3
0
        public void Ctor_UsesDefaultEqualityComparer()
        {
            var cache = new NanoCache <string, int> {
                ["a"] = 999
            };

            Assert.AreEqual(cache["A"], 0);
        }
Exemplo n.º 4
0
        public void TryGetValue_ReturnsTrueIfItemDoesExist()
        {
            var cache = new NanoCache <string, int> {
                ["item"] = 1234
            };

            Assert.IsTrue(cache.TryGetValue("item", out _));
        }
Exemplo n.º 5
0
        public void Count_IsIncrementedWhenItemIsAdded()
        {
            var cache = new NanoCache <string, int> {
                ["1"] = 1
            };

            Assert.AreEqual(1, cache.Count);
        }
Exemplo n.º 6
0
        public void Indexer_StoresANewValueIntoTheCache()
        {
            var cache = new NanoCache <string, int> {
                ["item"] = 999
            };

            Assert.AreEqual(cache["item"], 999);
        }
Exemplo n.º 7
0
        public void Indexer_DoesNotAcknowledgeExpiredItems()
        {
            var cache = new NanoCache <string, int>();

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

            Assert.AreEqual(0, cache["item"]);
        }
Exemplo n.º 8
0
        public void TryGetValue_ReturnsItemIfExists()
        {
            var cache = new NanoCache <string, int> {
                ["item"] = 1234
            };

            cache.TryGetValue("item", out var value);
            Assert.AreEqual(1234, value);
        }
Exemplo n.º 9
0
        public void Ctor_TakesEqualityComparer_IntoConsideration()
        {
            var cache = new NanoCache <string, int>(StringComparer.OrdinalIgnoreCase)
            {
                ["a"] = 999
            };

            Assert.AreEqual(cache["A"], 999);
        }
Exemplo n.º 10
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 _));
        }
Exemplo n.º 11
0
        public void Remove_ReturnsTrueIfItemRemoved()
        {
            var cache = new NanoCache <string, int>
            {
                ["item"] = 999
            };

            Assert.IsTrue(cache.Remove("item"));
        }
Exemplo n.º 12
0
        public void Remove_DoesNotAcknowledgeExpiredItems()
        {
            var cache = new NanoCache <string, int>();

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

            Assert.IsFalse(cache.Remove("item"));
        }
Exemplo n.º 13
0
        public void Count_IsDecrementedWhenItemIsRemoved()
        {
            var cache = new NanoCache <string, int>
            {
                ["1"] = 1
            };

            cache.Remove("1");
            Assert.AreEqual(0, cache.Count);
        }
Exemplo n.º 14
0
        public void Indexer_RemovesTheValueFromTheCacheIfDefaultProvided()
        {
            var cache = new NanoCache <string, int>
            {
                ["item"] = 999,
                ["item"] = 0
            };

            Assert.IsFalse(cache.Remove("item"));
        }
Exemplo n.º 15
0
        public void Indexer_ReplacesAnExistingValueInTheCache()
        {
            var cache = new NanoCache <string, int>
            {
                ["item"] = 999,
                ["item"] = 111
            };

            Assert.AreEqual(cache["item"], 111);
        }
Exemplo n.º 16
0
        public void Set_RefreshesValueOfExpiredItem()
        {
            var cache = new NanoCache <string, int>();

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

            Assert.AreEqual(9876, cache["item"]);
        }
Exemplo n.º 17
0
        public void Remove_RemovesAnExistingItemFromTheCache()
        {
            var cache = new NanoCache <string, int>
            {
                ["item"] = 999
            };

            cache.Remove("item");
            Assert.AreEqual(cache["item"], 0);
        }
Exemplo n.º 18
0
        public void Count_IncludesExpiredItems()
        {
            var cache = new NanoCache <string, int>();

            cache.Set("1", 1, 10);

            Thread.Sleep(100);

            Assert.AreEqual(1, cache.Count);
        }
Exemplo n.º 19
0
        public void Count_IsUpdatedWhenExpiredItemIsFlushed2()
        {
            var cache = new NanoCache <string, int>();

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

            Assert.AreEqual(0, cache["1"]);
            Assert.AreEqual(0, cache.Count);
        }
Exemplo n.º 20
0
        public void Count_IsNotIncrementedWhenItemIsUpdated()
        {
            var cache = new NanoCache <string, int>
            {
                ["1"] = 1,
                ["1"] = 2
            };

            Assert.AreEqual(1, cache.Count);
        }
Exemplo n.º 21
0
        public void Count_IsDecrementedWhenItemIsReplacedWithDefaultValue()
        {
            var cache = new NanoCache <string, int>
            {
                ["1"] = 1,
                ["1"] = 0
            };

            Assert.AreEqual(0, cache.Count);
        }
Exemplo n.º 22
0
        public void Set_ReplacesAnExistingValueInTheCache()
        {
            var cache = new NanoCache <string, int>
            {
                ["item"] = 999
            };

            cache.Set("item", 111);

            Assert.AreEqual(cache["item"], 111);
        }
Exemplo n.º 23
0
        public void Flush_DoesNothingForUnExpiredItems()
        {
            var cache = new NanoCache <string, int>
            {
                ["1"] = 1
            };

            cache.Flush();

            Assert.AreEqual(1, cache.Count);
        }
Exemplo n.º 24
0
        public void Flush_RemovesTheExpiredItems()
        {
            var cache = new NanoCache <string, int>();

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

            cache.Flush();

            Assert.AreEqual(0, cache.Count);
        }
Exemplo n.º 25
0
        public void Set_RemovesTheValueFromTheCacheIfDefaultProvided()
        {
            var cache = new NanoCache <string, int>
            {
                ["item"] = 999
            };

            cache.Set("item", 0);

            Assert.IsFalse(cache.Remove("item"));
        }
Exemplo n.º 26
0
        public void Flush_RemovesTheExpiredItemsWhileLeavingTheNormalOnes()
        {
            var cache = new NanoCache <string, int>();

            cache.Set("1", 1, 10);

            Thread.Sleep(100);

            cache["2"] = 2;
            cache.Flush();

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

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

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

            Assert.Throws <ArgumentNullException>(() => cache.Set(null, 100));
        }
Exemplo n.º 30
0
        public void Set_ThrowsException_ForTtlLessThanMinusOne()
        {
            var cache = new NanoCache <string, int>();

            Assert.Throws <ArgumentOutOfRangeException>(() => cache.Set("a", 1, -2));
        }