Example #1
0
        public void Get_value_for_key()
        {
            var sut = new FilesystemCache(CACHE_PATH);
            sut.ReplaceOrAdd("mykey", "hello");

            Assert.AreEqual("hello", sut.Get("mykey"));
        }
Example #2
0
        public void Increment_existing_value_returns_new_value()
        {
            var sut = new FilesystemCache(CACHE_PATH);
            sut.ReplaceOrAdd("mycounter", "1");

            Assert.AreEqual(100, sut.Increment("mycounter", 99));
        }
Example #3
0
        public void Replace_non_existent_key_creates_it()
        {
            const string entry_filename = CACHE_PATH + @"\mykey.txt";
            File.Delete(entry_filename);
            var sut = new FilesystemCache(CACHE_PATH);

            sut.ReplaceOrAdd("mykey", "hello");

            Assert.AreEqual("hello", File.ReadAllText(entry_filename));
        }
Example #4
0
        public void Try_getting_a_value_that_exists()
        {
            var sut = new FilesystemCache(CACHE_PATH);
            sut.ReplaceOrAdd("mykey", "hello");

            var value = "";
            Assert.IsTrue(sut.TryGet("mykey", out value));
            Assert.AreEqual("hello", value);
        }
Example #5
0
        public void Replace_an_existing_value()
        {
            const string entry_filename = CACHE_PATH + @"\mykey.txt";
            var sut = new FilesystemCache(CACHE_PATH);
            sut.Add("mykey", "will be overwritten");

            sut.ReplaceOrAdd("mykey", "hello");

            Assert.AreEqual("hello", File.ReadAllText(entry_filename));
        }