public void RemoveTest()
        {
            // Create the component under testing.
            var CuT = new TemporaryStorage <string>();

            // Assert adding strings.
            Assert.AreEqual(CuT.Store("Test1"), 0);
            Assert.AreEqual(CuT.Store("Test2"), 1);
            Assert.AreEqual(CuT.Store("Test3"), 2);

            // Assert the strings can be fetched correctly.
            Assert.AreEqual(CuT.Get(0), "Test1");
            Assert.AreEqual(CuT.Get(1), "Test2");
            Assert.AreEqual(CuT.Get(2), "Test3");

            // Remove 2 strings and assert they were removed.
            CuT.Remove(0);
            CuT.Remove(2);
            Assert.AreEqual(CuT.Get(0), null);
            Assert.AreEqual(CuT.Get(1), "Test2");
            Assert.AreEqual(CuT.Get(2), null);

            // Assert adding new strings.
            Assert.AreEqual(CuT.Store("Test4"), 0);
            Assert.AreEqual(CuT.Store("Test5"), 2);
            Assert.AreEqual(CuT.Store("Test6"), 3);

            // Assert the strings can be fetched correctly.
            Assert.AreEqual(CuT.Get(0), "Test4");
            Assert.AreEqual(CuT.Get(1), "Test2");
            Assert.AreEqual(CuT.Get(2), "Test5");
            Assert.AreEqual(CuT.Get(3), "Test6");
        }
        public void GetTest()
        {
            // Create the component under testing.
            var CuT = new TemporaryStorage <string>();

            // Assert adding strings.
            Assert.AreEqual(CuT.Store("Test1"), 0);
            Assert.AreEqual(CuT.Store("Test2"), 1);
            Assert.AreEqual(CuT.Store("Test3"), 2);

            // Assert the strings can be fetched correctly.
            Assert.AreEqual(CuT.Get(0), "Test1");
            Assert.AreEqual(CuT.Get(1), "Test2");
            Assert.AreEqual(CuT.Get(2), "Test3");
        }
Example #3
0
        /// <summary>
        /// Returns value indicating whether items can be added or updated.
        /// </summary>
        /// <returns>Value indicating whether items can be added or updated.</returns>
        private bool CanCache()
        {
            bool   ret = true;
            string key = "HttpCache:CanCache";

            if (!TemporaryStorage.Contains(key))
            {
                TemporaryStorage.Set(key, !Flags.ContainsKey("no-cache") && !Flags.ContainsKey("no-store"));
            }

            ret = TemporaryStorage.Get <bool>(key);

            return(ret);
        }
Example #4
0
        /// <summary>
        /// Retrieves the item with the given key from the cache.
        /// </summary>
        /// <param name="key">Item key.</param>
        /// <returns>Item value.</returns>
        protected override object GetItem(string key)
        {
            object ret = null;

            EnsureExpiration();

            if (CanCache())
            {
                ret = base.GetItem(key);
            }
            else
            {
                ret = TemporaryStorage.Get(key);
            }

            return(ret);
        }