コード例 #1
0
    public void Store_And_delete_multiple_entry()
    {
        // create storage and fill it with 5 FileCacheEntry
        FileCacheStorage storage = createAndFillStorage(5);

        // verify all FileCacheEntry
        Assert.AreEqual(true, storage.Has("1"));
        Assert.AreEqual(true, storage.Has("2"));
        Assert.AreEqual(true, storage.Has("3"));
        Assert.AreEqual(true, storage.Has("4"));
        Assert.AreEqual(true, storage.Has("5"));

        storage.SaveCacheStorageFile();
        // check FileCacheEntry count
        Assert.AreEqual(5, storage.CacheEntries.Count);

        // delete FileCacheEntry with id = "2"
        storage.Delete("2");
        Assert.AreEqual(null, storage.Get("2"));
        Assert.AreNotEqual(null, storage.Get("3"));
        Assert.AreEqual(false, storage.Has("2"));


        storage.SaveCacheStorageFile();
        // check FileCacheEntry count
        Assert.AreEqual(4, storage.CacheEntries.Count);

        // delete all and check
        storage.DeleteAll();
        storage.SaveCacheStorageFile();

        // check FileCacheEntry count
        Assert.AreEqual(0, storage.CacheEntries.Count);
    }
コード例 #2
0
    public void Test_Empty_Storage_After_Creation()
    {
        // create storage
        FileCacheStorage storage = new FileCacheStorage(_curDir, _curFile, _fileSystemMock.Object, _serializerMock.Object);

        // check new storage: should not have FileCacheEntry and version
        Assert.AreEqual(false, storage.Has("1"));
        Assert.AreEqual(null, storage.Version);
        Assert.AreEqual(null, storage.Get("2"));
        Assert.AreEqual(0, storage.CacheEntries.Count);

        try
        {
            // should not have exception, if delete FileCacheEntry in empty storage
            storage.Delete("3");
        }
        catch (Exception ex)
        {
            Assert.Fail("No exception should be thrown in Delete() for empty storage, but got " + ex.Message);
        }

        // check storage version after saving storage to file
        storage.SaveCacheStorageFile();
        Assert.AreEqual("1.0", storage.Version);
    }