Esempio n. 1
0
        /// <summary>
        /// Generates the configuration.
        /// </summary>
        /// <returns>The new configuration.</returns>
        public virtual SecurityCache GenerateConfig()
        {
            var cache = new SecurityCache();

            switch ((string)cacheMode.SelectedItem)
            {
            case "File based":
            {
                var newCache = new FileBasedSessionCache();
                newCache.CachingMode = GetExpiryMode();
                newCache.Duration    = Convert.ToInt32(sessionLength.Value);
                cache = newCache;
            }
            break;

            case "In memory":
            {
                var newCache = new InMemorySessionCache();
                newCache.CachingMode = GetExpiryMode();
                newCache.Duration    = Convert.ToInt32(sessionLength.Value);
                cache = newCache;
            }
            break;
            }
            return(cache);
        }
Esempio n. 2
0
        public void AddToCacheReturnsGuid()
        {
            InMemorySessionCache cache = new InMemorySessionCache();
            string sessionToken        = cache.AddToCache("johndoe");
            string userName            = cache.RetrieveFromCache(sessionToken);
            Guid   sessionGuid         = new Guid(sessionToken);

            Assert.AreEqual("johndoe", userName);
        }
Esempio n. 3
0
        public void RemoveFromCacheRemovesSession()
        {
            InMemorySessionCache cache = new InMemorySessionCache();
            string sessionToken        = cache.AddToCache("johndoe");

            cache.RemoveFromCache(sessionToken);
            string userName = cache.RetrieveFromCache(sessionToken);

            Assert.IsNull(userName);
        }
Esempio n. 4
0
        public void InvalidSessionValueReturnsNull()
        {
            InMemorySessionCache cache = new InMemorySessionCache();
            string sessionToken        = "Non-existant";
            string key = "An item";

            object result = cache.RetrieveSessionValue(sessionToken, key);

            Assert.IsNull(result);
        }
Esempio n. 5
0
        public void NonStoredValueReturnsNull()
        {
            InMemorySessionCache cache = new InMemorySessionCache();
            string sessionToken        = cache.AddToCache("johndoe");
            string key = "An item";

            object result = cache.RetrieveSessionValue(sessionToken, key);

            Assert.IsNull(result);
        }
Esempio n. 6
0
        public void StoreSessionValueIsStored()
        {
            InMemorySessionCache cache = new InMemorySessionCache();
            string sessionToken        = cache.AddToCache("johndoe");
            string key   = "An item";
            object value = Guid.NewGuid();

            cache.StoreSessionValue(sessionToken, key, value);
            object result = cache.RetrieveSessionValue(sessionToken, key);

            Assert.AreEqual(value, result);
        }
Esempio n. 7
0
        public void LoadsFromXml()
        {
            NetReflectorTypeTable typeTable = new NetReflectorTypeTable();

            typeTable.Add(AppDomain.CurrentDomain);
            NetReflectorReader reader = new NetReflectorReader(typeTable);

            object result = reader.Read("<inMemoryCache duration=\"5\" mode=\"Fixed\"/>");

            Assert.That(result, Is.InstanceOf <InMemorySessionCache>());
            InMemorySessionCache cache = result as InMemorySessionCache;

            Assert.AreEqual(5, cache.Duration);
            Assert.AreEqual(SessionExpiryMode.Fixed, cache.ExpiryMode);
        }
Esempio n. 8
0
        public void FixedExpiryTimeExpires()
        {
            TestClock clock = new TestClock {
                Now = DateTime.Now
            };
            InMemorySessionCache cache = new InMemorySessionCache(clock);

            cache.Duration   = 1;
            cache.ExpiryMode = SessionExpiryMode.Fixed;
            string sessionToken = cache.AddToCache("johndoe");

            clock.TimePasses(TimeSpan.FromSeconds(61));
            string userName = cache.RetrieveFromCache(sessionToken);

            Assert.IsNull(userName);
        }
Esempio n. 9
0
        public void SlidingExpiryTimeDoesntExpire()
        {
            TestClock clock = new TestClock {
                Now = DateTime.Now
            };
            InMemorySessionCache cache = new InMemorySessionCache(clock);

            cache.Duration   = 1;
            cache.ExpiryMode = SessionExpiryMode.Sliding;
            string sessionToken = cache.AddToCache("johndoe");

            clock.TimePasses(TimeSpan.FromSeconds(31));
            string userName = cache.RetrieveFromCache(sessionToken);

            Assert.AreEqual("johndoe", userName);
            clock.TimePasses(TimeSpan.FromSeconds(31));
            userName = cache.RetrieveFromCache(sessionToken);
            Assert.AreEqual("johndoe", userName);
        }
Esempio n. 10
0
        public void InitialiseDoesNothing()
        {
            InMemorySessionCache cache = new InMemorySessionCache();

            cache.Initialise();
        }