예제 #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);
        }
예제 #2
0
        [Test]//, Ignore("New API changes makes this hard to test."), FileIOPermission(SecurityAction.Demand)]
        public void MarkAllCachedItemsAsReadPlacesItemsIntoTheRecentlyViewedCount()
        {
            //Load feed list.

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

            handler.MaxItemAge = TimeSpan.MaxValue.Subtract(TimeSpan.FromDays(1));
            handler.LoadFeedlist();

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

            //Grab a feed.
            var          feed     = handler.GetFeeds()[BASE_URL + "LocalTestFeed.xml"];
            IFeedDetails feedInfo = handler.GetFeedDetails(feed.link);

            Assert.IsNotNull(feedInfo);
            Console.WriteLine("CACHEURL: " + feed.cacheurl);

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

            Assert.AreEqual(feed.title, "Rss Bandit Unit Test Feed");
            Assert.AreEqual(1, feed.storiesrecentlyviewed.Count);

            //Grab feed items
            var items = handler.GetItemsForFeed(feed.link, false);

            Assert.AreEqual(2, items.Count);

            //The first one should have been read. the second not.
            NewsItem item = (NewsItem)items[0];

            Assert.IsTrue(item.BeenRead);
            item = (NewsItem)items[1];
            Assert.IsTrue(!item.BeenRead);

            //So let's read the second item.
            handler.MarkAllCachedItemsAsRead(feed);
            handler.ApplyFeedModifications(feed.link);

            //Let's save this guy.
            using (FileStream newFeedStream = File.OpenWrite(Path.Combine(WEBROOT_PATH, @"NewsHandlerTestFiles\LocalTestFeedList_NEW.xml")))
            {
                handler.SaveFeedList(newFeedStream, FeedListFormat.NewsHandler);
                newFeedStream.Close();
                Assert.IsTrue(File.Exists(Path.Combine(WEBROOT_PATH, @"NewsHandlerTestFiles\LocalTestFeedList_NEW.xml")));
            }

            //Let's reload and see what happens.
            handler = new BanditFeedSource(ConfigurationWithoutSearchIndexerAndUnitTestCache, new SubscriptionLocation(BASE_URL + "LocalTestFeedList_NEW.xml"));
            handler.LoadFeedlist();

            feed = handler.GetFeeds().Values.FirstOrDefault();
            //Assertion.AssertEquals("Should be two now.", 2, feed.storiesrecentlyviewed.Count);
            Assert.AreEqual(2, feed.storiesrecentlyviewed.Count, "Should be two now.");
        }
예제 #3
0
        private FeedSource CreateNewsHandlerWithFeedList()
        {
            var handler = new BanditFeedSource(ConfigurationWithoutSearchIndexer, new SubscriptionLocation(WEBROOT_PATH + @"\NewsHandlerTestFiles\FeedList03Feeds.xml"));

            handler.LoadFeedlist();

            //handler.LoadFeedlist(new FileStream(WEBROOT_PATH + @"\NewsHandlerTestFiles\FeedList03Feeds.xml", FileMode.Open), null);
            Assert.IsTrue(handler.FeedsListOK, "Feeds should be valid!");
            //Assert.AreEqual(3, handler.Feeds.Count, "FeedList03Feeds.xml should contain 3 feeds. Hence the name");

            return(handler);
        }
예제 #4
0
        public void LoadNonExistentEnsureExceptionThrown()
        {
            var handler = new BanditFeedSource(ConfigurationWithoutSearchIndexer, new SubscriptionLocation(BASE_URL + "ThisFeedDoesNotExist.xml"));

            Assert.Throws <System.Net.WebException>(() => handler.LoadFeedlist());
        }