/// <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); }
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 RemoveFromCacheRemovesSession() { InMemorySessionCache cache = new InMemorySessionCache(); string sessionToken = cache.AddToCache("johndoe"); cache.RemoveFromCache(sessionToken); string userName = cache.RetrieveFromCache(sessionToken); Assert.IsNull(userName); }
public void InvalidSessionValueReturnsNull() { InMemorySessionCache cache = new InMemorySessionCache(); string sessionToken = "Non-existant"; string key = "An item"; object result = cache.RetrieveSessionValue(sessionToken, key); Assert.IsNull(result); }
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); }
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 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); }
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 InitialiseDoesNothing() { InMemorySessionCache cache = new InMemorySessionCache(); cache.Initialise(); }