Exemplo n.º 1
0
        public async Task <FeedResult> InvokeRssWithCategories(List <string> categories, string feed = "https://blogs.msdn.microsoft.com/webdev/feed/", int truncateAt = 0)
        {
            var sut = new FeedCrawler();

            if (feed != string.Empty)
            {
                string responseData = TestHelperForCurrentProject.GetTestFileContent(TestHelperForCurrentProject.GetTestFilePath(samplesDirectory, msWebDevRssSample));

                var messageResponse = FakeHttpMessageHandler.GetStringHttpResponseMessage(responseData);

                var fakeMessageHandler = new FakeHttpMessageHandler(new HttpMessageOptions()
                {
                    HttpResponseMessage = messageResponse, RequestUri = new Uri(feed)
                });
                var facebokLoaderMock = A.Fake <IFacebookShareCountLoader>();

                sut = new FeedCrawler(fakeMessageHandler, facebokLoaderMock);
            }


            var config = new FeedCrawlerConfig
            {
                Url = feed,
                LoadSocialLinkCounters = false,
                IncludeRawContent      = true,
                SummaryTruncateAt      = truncateAt,
                FilterByCategories     = categories
            };

            return(await sut.DoWorkAsync(config));
        }
Exemplo n.º 2
0
        public async Task <FeedResult> InvokeRssWithSocialLinksEnabled(int twitterCounts = 0, int facebookShares = 0, string feed = "http://rss.slashdot.org/Slashdot/slashdot", int truncateAt = 0)
        {
            var sut = new FeedCrawler();

            if (feed != string.Empty)
            {
                string responseData = TestHelperForCurrentProject.GetTestFileContent(TestHelperForCurrentProject.GetTestFilePath(samplesDirectory, slashdotRssSample));

                var messageResponse = FakeHttpMessageHandler.GetStringHttpResponseMessage(responseData);

                var fakeMessageHandler = new FakeHttpMessageHandler(new HttpMessageOptions()
                {
                    HttpResponseMessage = messageResponse, RequestUri = new Uri(feed)
                });
                var facebokLoaderMock = A.Fake <IFacebookShareCountLoader>();
                A.CallTo(() => facebokLoaderMock.GetAsync(string.Empty)).WithAnyArguments().Returns(facebookShares);

                sut = new FeedCrawler(fakeMessageHandler, facebokLoaderMock);
            }


            var config = new FeedCrawlerConfig
            {
                Url = feed,
                LoadSocialLinkCounters = true,
                IncludeRawContent      = true,
                SummaryTruncateAt      = truncateAt
            };

            return(await sut.DoWorkAsync(config));
        }
Exemplo n.º 3
0
        public async Task Crawler_Should_Not_Reach_Out_To_Facebook_If_Disabled()
        {
            string responseData = TestHelperForCurrentProject.GetTestFileContent(TestHelperForCurrentProject.GetTestFilePath(samplesDirectory, gitHubAtomSample));

            var messageResponse = FakeHttpMessageHandler.GetStringHttpResponseMessage(responseData);

            var fakeMessageHandler = new FakeHttpMessageHandler(new HttpMessageOptions()
            {
                HttpResponseMessage = messageResponse, RequestUri = new Uri("https://github.com/robertmuehsig.atom")
            });

            var facebokLoaderMock = A.Fake <IFacebookShareCountLoader>();

            var sut = new FeedCrawler(fakeMessageHandler, facebokLoaderMock);

            var config = new FeedCrawlerConfig
            {
                Url = "https://github.com/robertmuehsig.atom",
                LoadSocialLinkCounters = false
            };

            var result = await sut.DoWorkAsync(config);

            A.CallTo(() => facebokLoaderMock.GetAsync(string.Empty)).WithAnyArguments().MustNotHaveHappened();
        }
Exemplo n.º 4
0
        public async Task <FeedResult> InvokeAtomSut(int twitterCounts = 0, int facebookShares = 0, string feed = "https://github.com/robertmuehsig.atom", int truncateAt = 0)
        {
            var atomXmlFile = gitHubAtomSample;

            if (feed == "https://blog.nuget.org/feeds/atom.xml")
            {
                atomXmlFile = nugetBlogAtomSample;
            }

            string responseData = TestHelperForCurrentProject.GetTestFileContent(TestHelperForCurrentProject.GetTestFilePath(samplesDirectory, atomXmlFile));

            var messageResponse = FakeHttpMessageHandler.GetStringHttpResponseMessage(responseData);

            var fakeMessageHandler = new FakeHttpMessageHandler(new HttpMessageOptions()
            {
                HttpResponseMessage = messageResponse, RequestUri = new Uri(feed)
            });

            var facebokLoaderMock = A.Fake <IFacebookShareCountLoader>();

            A.CallTo(() => facebokLoaderMock.GetAsync(string.Empty)).WithAnyArguments().Returns(facebookShares);

            var sut = new FeedCrawler(fakeMessageHandler, facebokLoaderMock);

            var config = new FeedCrawlerConfig
            {
                Url = feed,
                SummaryTruncateAt = truncateAt
            };

            return(await sut.DoWorkAsync(config));
        }
Exemplo n.º 5
0
        public async Task Crawler_Can_Read_Media_Thumbnail()
        {
            string responseData = TestHelperForCurrentProject.GetTestFileContent(TestHelperForCurrentProject.GetTestFilePath(samplesDirectory, youtubeWithMedia));
            string feed         = "https://www.youtube.com/feeds/videos.xml?channel_id=UCqE3og-pkA7DO90lqNHAR5Q";

            var messageResponse = FakeHttpMessageHandler.GetStringHttpResponseMessage(responseData);

            var fakeMessageHandler = new FakeHttpMessageHandler(new HttpMessageOptions()
            {
                HttpResponseMessage = messageResponse, RequestUri = new Uri(feed)
            });
            var facebokLoaderMock = A.Fake <IFacebookShareCountLoader>();

            var sut = new FeedCrawler(fakeMessageHandler, facebokLoaderMock);


            var config = new FeedCrawlerConfig
            {
                Url = feed,
                LoadSocialLinkCounters = false,
                IncludeRawContent      = true,
                SummaryTruncateAt      = 100
            };

            var result = await sut.DoWorkAsync(config);

            Assert.True(result.FeedItems.Count == 6);
            Assert.True(result.FeedItems[0].Thumbnail == "https://i1.ytimg.com/vi/dNaIOGQj15M/hqdefault.jpg");
            Assert.True(result.FeedItems[5].Thumbnail == "https://i3.ytimg.com/vi/27yknlB8xeg/hqdefault.jpg");
        }
Exemplo n.º 6
0
        public async Task Crawler_Should_Embed_The_RawContent_From_The_ActualRssItem()
        {
            var result = await InvokeSlashdotSutWithSocialLinksEnabled();


            var staticFeed   = SyndicationFeed.Load(new XmlTextReader(TestHelperForCurrentProject.GetTestFilePath(samplesDirectory, slashdotRssSample)));
            var expectedItem = staticFeed.Items.First();

            var firstResult = result.FeedItems.Single(x => x.Title == expectedItem.Title.Text);

            StringBuilder builder = new StringBuilder();
            XmlWriter     writer  = XmlWriter.Create(builder);

            expectedItem.SaveAsRss20(writer);
            writer.Close();

            var expected = builder.ToString();

            Assert.Equal(expected, firstResult.RawContent);
        }
Exemplo n.º 7
0
        public async Task <FeedCrawlerResult> InvokeSlashdotSutWithSocialLinksEnabled(int twitterCounts = 0, int facebookShares = 0, string feed = "http://rss.slashdot.org/Slashdot/slashdot")
        {
            var feedLoaderMock = A.Fake <ISyndicationFeedAbstraction>();
            var staticFeed     = SyndicationFeed.Load(new XmlTextReader(TestHelperForCurrentProject.GetTestFilePath(samplesDirectory, slashdotRssSample)));

            A.CallTo(() => feedLoaderMock.Get("http://rss.slashdot.org/Slashdot/slashdot")).Returns(staticFeed);

            var twitterLoaderMock = A.Fake <ITwitterTweetCountLoader>();

            A.CallTo(() => twitterLoaderMock.GetAsync(string.Empty)).WithAnyArguments().Returns(twitterCounts);

            var facebokLoaderMock = A.Fake <IFacebookShareCountLoader>();

            A.CallTo(() => facebokLoaderMock.GetAsync(string.Empty)).WithAnyArguments().Returns(facebookShares);

            var sut = new FeedCrawler(feedLoaderMock, twitterLoaderMock, facebokLoaderMock);

            var config = new FeedCrawlerConfig();

            config.Url = feed;
            config.LoadSocialLinkCounters = true;
            return(await sut.DoWorkAsync(config));
        }
Exemplo n.º 8
0
        public async Task <FeedCrawlerResult> InvokeGitHubSut(int twitterCounts = 0, int facebookShares = 0, string feed = "https://github.com/robertmuehsig.atom")
        {
            var feedLoaderMock = A.Fake <ISyndicationFeedAbstraction>();
            var staticFeed     = SyndicationFeed.Load(new XmlTextReader(TestHelperForCurrentProject.GetTestFilePath(samplesDirectory, gitHubAtomSample)));

            A.CallTo(() => feedLoaderMock.Get("https://github.com/robertmuehsig.atom")).Returns(staticFeed);

            var twitterLoaderMock = A.Fake <ITwitterTweetCountLoader>();

            A.CallTo(() => twitterLoaderMock.GetAsync(string.Empty)).WithAnyArguments().Returns(twitterCounts);

            var facebokLoaderMock = A.Fake <IFacebookShareCountLoader>();

            A.CallTo(() => facebokLoaderMock.GetAsync(string.Empty)).WithAnyArguments().Returns(facebookShares);

            var sut = new FeedCrawler(feedLoaderMock, twitterLoaderMock, facebokLoaderMock);

            var config = new FeedCrawlerConfig();

            config.Url = feed;

            return(await sut.DoWorkAsync(config));
        }