示例#1
0
        public void Clear_removes_all_entries()
        {
            var sut = new FilesystemCache(CACHE_PATH);
            sut.Add("key1", "1");
            sut.Add("key2", "2");

            sut.Clear();

            Assert.AreEqual(0, Directory.GetFiles(CACHE_PATH).Length);
        }
示例#2
0
        public void Adding_existing_key_does_not_overwrite_value()
        {
            const string entry_filename = CACHE_PATH + @"\mykey.txt";
            File.Delete(entry_filename);
            var sut = new FilesystemCache(CACHE_PATH);

            sut.Add("mykey", "hello");
            sut.Add("mykey", "world");

            Assert.AreEqual("hello", File.ReadAllText(entry_filename));
        }
示例#3
0
        public void Adding_key_creates_file_and_stores_value()
        {
            const string entry_filename = CACHE_PATH + @"\mykey.txt";
            File.Delete(entry_filename);
            var sut = new FilesystemCache(CACHE_PATH);

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

            Assert.AreEqual("hello", File.ReadAllText(entry_filename));
        }
示例#4
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));
        }
示例#5
0
        public void Remove_a_key()
        {
            const string entry_filename = CACHE_PATH + @"\mykey.txt";
            var sut = new FilesystemCache(CACHE_PATH);
            sut.Add("mykey", "to be deleted");

            sut.Remove("mykey");

            Assert.IsFalse(File.Exists(entry_filename));
        }