示例#1
0
        public void Item_not_cached()
        {
            var cache = new Cache.Factory().Create();

            cache.Put("Key", "Url", "Result");
            Assert.False(cache.TryGet("Key1", "Url", out var result));
            Assert.Null(result);
        }
示例#2
0
        public void Accepts_and_retrieves_item()
        {
            var cache = new Cache.Factory().Create();

            cache.Put("Key", "Url", "Result");
            Assert.True(cache.TryGet("Key", "Url", out var result));
            Assert.Equal("Result", result);
        }
示例#3
0
        public void Wrong_parameters()
        {
            var cache = new Cache.Factory().Create();

            Assert.Throws <ArgumentException>("keywords", () => cache.Put("", "Url", "Result"));
            Assert.Throws <ArgumentException>("url", () => cache.Put("Key", null, "Result"));
            Assert.Throws <ArgumentException>("result", () => cache.Put("Key", "Url", " \t"));
            Assert.Throws <ArgumentException>("keywords", () => cache.TryGet("\n", "Url", out var _));
            Assert.Throws <ArgumentException>("url", () => cache.TryGet("Key", "   ", out var _));
        }
示例#4
0
        public void Time_Validity()
        {
            var span  = TimeSpan.FromSeconds(3);
            var cache = new Cache.Factory().Create(span);

            cache.Put("Key", "Url", "Result");
            Assert.True(cache.TryGet("Key", "Url", out var result));
            Assert.Equal("Result", result);
            Thread.Sleep(span);
            Assert.False(cache.TryGet("Key", "Url", out var _));
            cache.Put("Key", "Url", "Result");
            Assert.True(cache.TryGet("Key", "Url", out var _));
        }
示例#5
0
        public void Empty_cache()
        {
            var cache = new Cache.Factory().Create();

            Assert.False(cache.TryGet("Key", "Url", out var _));
        }