public void RemoveFromCacheRemovesSession()
 {
     InMemorySessionCache cache = new InMemorySessionCache();
     string sessionToken = cache.AddToCache("johndoe");
     cache.RemoveFromCache(sessionToken);
     string userName = cache.RetrieveFromCache(sessionToken);
     Assert.IsNull(userName);
 }
 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);
 }
        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);
        }
 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);
 }
 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);
 }
        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);
        }