public void Disk_cache_set_get_set_get(string key, string key2)
        {
            //Arrange
            var cache   = new DiskCacheStore(path, new TimeSpan(0, 0, 5));
            var context = new NancyContext()
            {
                Response = new FakeResponse()
                {
                }
            };

            //Act
            cache.Set(key, context, DateTime.UtcNow.AddSeconds(5));
            var response = cache.Get(key);

            System.Threading.Thread.Sleep(5000);

            cache.Set(key2, context, DateTime.UtcNow.AddSeconds(5));

            var response2 = cache.Get(key);
            var response3 = cache.Get(key2);

            cache.Remove(key);
            cache.Remove(key2);

            //Assert
            Assert.NotNull(response);
            Assert.Null(response2); //Expired
            Assert.NotNull(response3);
            Assert.NotNull(context.Response);
        }
        public void Disk_cache_set_set_get(string key)
        {
            //Arrange
            var expirationDate = DateTime.UtcNow.AddMinutes(15);
            var cache          = new DiskCacheStore(path);
            var context        = new NancyContext()
            {
                Response = new FakeResponse()
                {
                }
            };

            //Act
            cache.Set(key, context, expirationDate);
            cache.Set(key, context, expirationDate);
            var response = cache.Get(key);

            cache.Remove(key);

            //Assert
            Assert.Equal(context.Response.ContentType, response.ContentType);
            Assert.Equal(context.Response.StatusCode, response.StatusCode);
            Assert.Equal(expirationDate, response.Expiration);
            Assert.Equal(context.Response.Contents.ConvertStream(), response.Contents.ConvertStream());
        }
        public void Disk_cache_empty_get_with_timespan()
        {
            //Arrange
            var cache   = new DiskCacheStore(path, TimeSpan);
            var context = new NancyContext()
            {
                Response = new FakeResponse()
                {
                }
            };

            //Act
            cache.Set(string.Empty, context, DateTime.UtcNow.AddMinutes(1));
            var response = cache.Get(string.Empty);

            //Assert
            Assert.Null(response);
            Assert.True(Directory.Exists(path));
        }
        public void Disk_cache_set_then_get_expired(string key)
        {
            //Arrange
            var expiredDate = DateTime.UtcNow;
            var cache       = new DiskCacheStore(path);
            var context     = new NancyContext()
            {
                Response = new FakeResponse()
                {
                }
            };

            //Act
            cache.Set(key, context, expiredDate);
            var response = cache.Get(key);

            //Assert
            Assert.Null(response);
            Assert.NotNull(context.Response);
        }
        public void Disk_cache_empty_get_with_timespan_and_not_existing_custom_path()
        {
            //Arrange
            string tempPath = Path.Combine(path, "temp2");
            var    cache    = new DiskCacheStore(tempPath, TimeSpan);
            var    context  = new NancyContext()
            {
                Response = new FakeResponse()
                {
                }
            };

            //Act
            cache.Set(string.Empty, context, DateTime.UtcNow.AddMinutes(1));
            var response = cache.Get(string.Empty);

            //Assert
            Assert.Null(response);
            Assert.True(Directory.Exists(path));

            Directory.Delete(tempPath);
        }
        public void Disk_cache_set_remove_get(string key)
        {
            //Arrange
            var expirationDate = DateTime.Now.AddMinutes(15);
            var cache          = new DiskCacheStore(path);
            var context        = new NancyContext()
            {
                Response = new FakeResponse()
                {
                }
            };

            //Act
            cache.Set(key, context, expirationDate);

            cache.Remove(key);

            var response = cache.Get(key);

            //Assert
            Assert.Null(response);
            Assert.NotNull(context.Response);
        }