コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }