Пример #1
0
        public void GetRssItemsFromFeed_GuidCacheIsOnlyLoadedFirstTime_True()
        {
            MockRepository  mocks           = new MockRepository();
            IFileController iFileController = mocks.StrictMock <IFileController>();
            IXmlController  iXmlController  = mocks.Stub <IXmlController>();
            List <string>   lstGuidItems    = new List <string>();

            lstGuidItems.Add("GuidItem1");
            lstGuidItems.Add("GuidItem2");

            List <RSSLib.Model.RssItem> lstRssItems = new List <RSSLib.Model.RssItem>();

            lstRssItems.Add(new RSSLib.Model.RssItem {
                Title = "Item1", Guid = "GuidItem1", Link = "LinkItem1"
            });
            lstRssItems.Add(new RSSLib.Model.RssItem {
                Title = "Item2", Guid = "GuidItem2", Link = "LinkItem2"
            });

            using (mocks.Record())
            {
                //The first time we call the GetRssItemsFromFeed the following thow methods will be called form our mock
                Expect.Call(iFileController.LoadRowsFromFile(_rssController.PathGuidCache)).Return(lstGuidItems);
                Expect.Call(iXmlController.GetRssItemsFromFeed("FakeRssLocation")).Return(lstRssItems);
                //The second time we call the GetRssItemsFromFeed, only on method will be called (the cache doesn't need to be loaded from the files
                //system because it is cashed already.
                Expect.Call(iXmlController.GetRssItemsFromFeed("FakeRssLocation")).Return(lstRssItems);
            }
            _rssController.FileController = iFileController;
            _rssController.XmlController  = iXmlController;
            _rssController.GetRssItemsFromFeed(new RSSLib.Model.RssFeed {
                Title = "APO Test", Location = "FakeRssLocation"
            });
            _rssController.GetRssItemsFromFeed(new RSSLib.Model.RssFeed {
                Title = "APO Test", Location = "FakeRssLocation"
            });
            mocks.VerifyAll();
        }
Пример #2
0
        }//end LoadRssFeeds

        /// <summary>
        /// Loads the RssItems from a particular RssFeed
        /// </summary>
        /// <param name="rssFeed">The RssFeed for which you want the RssItems</param>
        /// <returns>A list of RssItems</returns>
        public List <RssItem> GetRssItemsFromFeed(RssFeed rssFeed)
        {
            List <RssItem> lstResult = new List <RssItem>();

            if (_lstCacheRssItems == null || _lstCacheRssItems.Count == 0)
            {
                LoadGuidCache();
            }
            foreach (RssItem rssItem in _xmlController.GetRssItemsFromFeed(rssFeed.Location))
            {
                if (!_lstCacheRssItems.Contains(rssItem.Guid))
                {
                    lstResult.Add(rssItem);
                }
            }
            return(lstResult);
        }