Exemple #1
0
        public void SaveFeedCreatesCacheFile()
        {
            //Load feed list.
            var cache = new FileStorageDataService();

            cache.Initialize(Path.GetFullPath(_cacheDirectory));

            var handler = new BanditFeedSource(ConfigurationWithoutSearchIndexerAndUnitTestCache,
                                               new SubscriptionLocation(WEBROOT_PATH + @"\NewsHandlerTestFiles\LocalTestFeedList.xml"));

            handler.LoadFeedlist();
            Assert.IsTrue(handler.FeedsListOK, "Feeds should be valid!");

            //Grab a feed.
            INewsFeed feed = handler.GetFeeds()[BASE_URL + @"LocalTestFeed.xml"];

            //feedsFeed feed = handler.FeedsTable[NewsHandlerTests.BASE_URL + "LocalTestFeed.xml"];
            Console.WriteLine("CACHEURL: " + feed.cacheurl);
            FileInfo cachedFile = new FileInfo(Path.Combine(_cacheDirectory, feed.cacheurl));

            DateTime lastWriteTime = cachedFile.LastWriteTime;

            Assert.IsNotNull(handler.GetFeedDetails(feed.link), "Feed info should not be null.");

            //Save the cache.
            Thread.Sleep(1000);
            handler.ApplyFeedModifications(feed.link);

            Assert.IsTrue(cache.FeedExists(feed), "The feed should have been saved to the cache");

            string[] files = Directory.GetFiles(_cacheDirectory);
            Assert.IsTrue(files.Length > 0, "There should be at least one cache file in the cache.");
            cachedFile = new FileInfo(Path.Combine(_cacheDirectory, feed.cacheurl));
            Assert.IsTrue(cachedFile.LastWriteTime > lastWriteTime, "Didn't overwrite the file. Original: " + lastWriteTime + "  New: " + cachedFile.LastWriteTime);
        }
Exemple #2
0
        public void FeedExistsFindsExistingFeed()
        {
            var cache = new FileStorageDataService();

            cache.Initialize(Path.GetFullPath(_cacheDirectory));
            var feed = new NewsFeed();

            feed.cacheurl = "172.0.0.1.8081.1214057202.df05c3d0bd8748e68f121451084e3e62.xml";
            Assert.IsTrue(cache.FeedExists(feed), "The feed's there, look harder.");
        }
Exemple #3
0
        public void FeedExistsReturnsFalseForNonExistentFeed()
        {
            var cache = new FileStorageDataService();

            cache.Initialize(Path.GetFullPath(_cacheDirectory));
            var feed = new NewsFeed();

            feed.cacheurl = "http://localhost/NonExistent/DoesNotExist.xml";
            Assert.IsFalse(cache.FeedExists(feed), "Can't be true. This really doesn't exist.");
        }
Exemple #4
0
        public void RemoveFeedDeletesCacheItem()
        {
            var cache = new FileStorageDataService();

            cache.Initialize(Path.GetFullPath(_cacheDirectory));
            var feed = new NewsFeed();

            feed.cacheurl = "172.0.0.1.8081.1214057202.df05c3d0bd8748e68f121451084e3e62.xml";
            Assert.IsTrue(cache.FeedExists(feed), "The feed's there, look harder.");

            cache.RemoveFeed(feed);
            Assert.IsFalse(cache.FeedExists(feed), "The cache is still there though you removed it.");
            Assert.IsFalse(File.Exists(_cacheDirectory + @"\172.0.0.1.8081.1214057202.df05c3d0bd8748e68f121451084e3e62.xml"), "The cache file was not removed!");
        }
Exemple #5
0
        public void ClearCacheRemovesCacheItem()
        {
            var cache = new FileStorageDataService();

            cache.Initialize(Path.GetFullPath(_cacheDirectory));
            var feed = new NewsFeed();

            feed.cacheurl = "172.0.0.1.8081.1214057202.df05c3d0bd8748e68f121451084e3e62.xml";
            Assert.IsTrue(cache.FeedExists(feed), "The feed's there, look harder.");

            cache.RemoveAllNewsItems();
            string[] files = Directory.GetFiles(_cacheDirectory);
            Assert.AreEqual(files.Length, 0, "There should be no files in the cache.");
        }