public void Memcached_cache_with_value_set_get() { //Arrange var client = GetMemcachedClient(); var cache = new MemcachedStore(client); var expiration = new TimeSpan(0, 1, 0); const string key = "Random-Key-4"; const string contentType = "application/json"; const int statusCode = 200; var response = new CachedResponse { ContentType = contentType, Expiry = expiration, StatusCode = statusCode, ContentLength = 1, }; //Act cache.Set(key, response, expiration); bool found = cache.TryGetValue(key, out var getResponse); //Assert Assert.Equal(response.ContentType, getResponse.ContentType); Assert.Equal(response.StatusCode, getResponse.StatusCode); Assert.Equal(response.Expiry, getResponse.Expiry); Assert.Equal(1, response.ContentLength); Assert.True(found); }
public void Memcached_cache_empty_remove() { //Arrange var client = GetMemcachedClient(); var cache = new MemcachedStore(client); //Act cache.Remove(string.Empty); //Assert Assert.NotNull(cache); }
public void Memcached_empty_get() { //Arrange var client = GetMemcachedClient(); var cache = new MemcachedStore(client); //Act bool found = cache.TryGetValue(string.Empty, out var response); //Assert Assert.NotNull(cache); Assert.False(found); Assert.Null(response); }
public void TestGet() { using (var mc = new MemcachedStore()) { mc.AddOrUpdate(_key, _response); HttpResponseMessage message; var success = mc.TryGetValue(_key, out message); Assert.AreEqual(_response.Content.Headers.ContentLength, message.Content.Headers.ContentLength); Assert.AreEqual(_response.Content.ReadAsStringAsync().Result, message.Content.ReadAsStringAsync().Result); Assert.IsTrue(success); } }
public void Memcached_cache_empty_key() { //Arrange var client = GetMemcachedClient(); var cache = new MemcachedStore(client); var expiration = new TimeSpan(0, 1, 0); var response = A.Fake <FakeCachedResponse>(); //Act cache.Set(string.Empty, response, expiration); //Assert Assert.NotNull(cache); Assert.NotNull(response); }
public void TestRemove() { using (var mc = new MemcachedStore()) { mc.AddOrUpdate(_key, _response); HttpResponseMessage message; var success = mc.TryRemove(_key); var getFailure = mc.TryGetValue(_key, out message); var failure = mc.TryRemove(_key); Assert.IsTrue(success); Assert.IsTrue(!failure); Assert.IsTrue(!getFailure); } }
public void Memcached_cache_with_value_set_remove_get() { //Arrange var client = GetMemcachedClient(); var cache = new MemcachedStore(client); var expiration = new TimeSpan(0, 1, 0); const string key = "Random-Key-3"; var response = A.Fake <FakeCachedResponse>(); //Act cache.Set(key, response, expiration); cache.Remove(key); bool found = cache.TryGetValue(key, out var getResponse); //Assert Assert.Null(getResponse); Assert.False(found); }
public void Memcached_cache_empty_set_no_timespan() { //Arrange var client = GetMemcachedClient(); var cache = new MemcachedStore(client); var expiration = new TimeSpan(0, 0, 0); const string key = "-Random-Key-5"; var response = A.Fake <FakeCachedResponse>(); //Act cache.Set(key, response, expiration); bool found = cache.TryGetValue(key, out var getResponse); //Assert Assert.NotNull(cache); Assert.NotNull(response); Assert.False(found); Assert.Null(getResponse); }