public void Should_throw_when_session_is_not_available() { // Arrange var lifecycle = new HttpSessionLifecycle(); HttpSessionLifecycle.HasSessionResolver = () => false; // Act & assert Assert.Throws <InvalidOperationException>(() => lifecycle.FindCache()); }
public void Should_return_false_when_not_available() { // Arrange var lifecycle = new HttpSessionLifecycle(); // Will reset to original state // Act var result = lifecycle.HasSession(); // Assert Assert.That(result, Is.False); }
public void Should_try_to_get_cache_from_session_when_session_is_available() { // Arrange var lifecycle = new HttpSessionLifecycle(); HttpSessionLifecycle.HasSessionResolver = () => true; // Act var exception = Assert.Throws <NullReferenceException>(() => lifecycle.FindCache()); // Assert Assert.That(exception.Message, Is.EqualTo("Object reference not set to an instance of an object.")); }
public void Should_return_new_cache_when_session_is_available() { // Arrange var dictionary = new Dictionary <string, object>(); var lifecycle = new HttpSessionLifecycle(); HttpSessionLifecycle.HasSessionResolver = () => true; HttpSessionLifecycle.DictionaryResolver = () => dictionary; // Act var result = lifecycle.FindCache() as ObjectCache; // Assert Assert.That(result, Is.Not.Null); Assert.That(result.Count, Is.EqualTo(0)); }
public void Should_return_existing_cache_when_session_is_available() { // Arrange var cache = new ObjectCache(); cache.Set(Guid.NewGuid(), new object()); var dictionary = new Dictionary <string, object>(); dictionary.Add(HttpSessionLifecycle.CacheKey, cache); var lifecycle = new HttpSessionLifecycle(); HttpSessionLifecycle.HasSessionResolver = () => true; HttpSessionLifecycle.DictionaryResolver = () => dictionary; // Act var result = lifecycle.FindCache() as ObjectCache; // Assert Assert.That(result, Is.EqualTo(cache)); Assert.That(result.Count, Is.EqualTo(1)); }
public HybridHttpSessionLifecycle() { _http = new HttpSessionLifecycle(); _nonHttp = new SingletonLifecycle(); }