public void CanGetImagesFromRssFeed()
        {
            string description = string.Format(@"<p><a href=""{0}""><img src=""http://thepaperwall.com/wallpapers/people/small/small_584778739bace9b64fb91975340190ed2f64a51d.jpg?x=130&y=89&q=85&sig=SVA2qhNVOsYltxwW7ULPyQ--"" align=""left"" height=""150"" width=""240""/>", expectedImageUrl);
            var rssChannelItem = new rssChannelItem
            {
                description =
                    description
            };
            var rssChannelItem2 = new rssChannelItem
            {
                description =
                    description
            };

            RssReader reader = new RssReader();

            var rss = new rss
            {
                channel = new rssChannel
                {
                    item = new rssChannelItem[] { rssChannelItem, rssChannelItem2 }
                }
            };
            List<PWImage> imageUrls = reader.GetImageUrls(rss);

            Assert.AreEqual(2, imageUrls.Count);

            foreach (var image in imageUrls)
            {
                Assert.AreEqual(expectedImageUrl, image.imageUrl);
            }
        }
        public void GetRssItemsParseTheUrlImagesFromFeedFilterOutAlreadyDownloadedImagesAndSetTheThemeOnEachImage()
        {
            var rssReader = MockRepository.GenerateMock<IRssReader>();

            PaperWallRssParser parser = new PaperWallRssParser(rssReader);
            var themes = new List<Theme>();
            themes.Add(new Theme{FeedUrl= "url1"});
            themes.Add(new Theme { FeedUrl = "url2" });
            var url1Rss = new rss();
             var url2Rss = new rss();
            var url1RssTask = Task<rss>.Run(() => { return url1Rss; });
            var url2RssTask = Task<rss>.Run(() => { return url2Rss; });

            rssReader.Expect(a => a.GetFeed(Arg<string>.Is.Equal("url1"))).Return(url1RssTask);
            rssReader.Expect(a => a.GetFeed(Arg<string>.Is.Equal("url2"))).Return(url2RssTask);

            var url1Images = new List<PWImage>{new PWImage()};
            var url2Image =new List<PWImage> { new PWImage(), new PWImage() };
            rssReader.Expect(a => a.GetImageUrls(Arg<rss>.Is.Equal(url1Rss))).Return(url1Images);
            rssReader.Expect(a => a.GetImageUrls(Arg<rss>.Is.Equal(url2Rss))).Return(url2Image);

            var pwImages = parser.GetImages(themes).Result;

            rssReader.VerifyAllExpectations();

            Assert.AreEqual(3, pwImages.Count);
            Assert.AreEqual(themes[0],pwImages[0].Theme);
            Assert.AreEqual(themes[1], pwImages[1].Theme);
            Assert.AreEqual(themes[1], pwImages[2].Theme);
        }
        public List<PWImage> GetImageUrls(rss feed)
        {
            var images = new List<PWImage>();
            HtmlDocument doc = new HtmlDocument();
            foreach (var rssChannelItem in feed.channel.item)
            {
                var html = rssChannelItem.description;

                doc.LoadHtml(html);
                var imageUrl = doc.DocumentNode.ChildNodes[1].Attributes[0].Value;
                images.Add(new PWImage { imageUrl = imageUrl });
            }
            return images;
        }