Exemple #1
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);
        }
Exemple #2
0
        public void RemoveFromCacheRemovesSession()
        {
            InMemorySessionCache cache = new InMemorySessionCache();
            string sessionToken        = cache.AddToCache("johndoe");

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

            Assert.IsNull(userName);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }