Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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));
        }
Ejemplo 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();
        }
Ejemplo 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));
        }
Ejemplo 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");
        }
Ejemplo n.º 6
0
        public void Deserialize_Of_Secrets_In_Testdata_To_Config_Works()
        {
            string yaml = TestHelperForCurrentProject.GetTestFileContent("CrawlerConfigTests/Sample.yaml");

            var deserializer = Constants.SloaderYamlDeserializer;
            var result       = deserializer.Deserialize <SloaderConfig>(new StringReader(yaml));

            Assert.NotNull(result.Secrets);
            Assert.Equal("HelloWorldKey", result.Secrets.TwitterConsumerKey);
            Assert.Equal("HelloWorldSecret", result.Secrets.TwitterConsumerSecret);
        }
Ejemplo n.º 7
0
        public void Deserialize_Of_Testdata_To_Config_Works()
        {
            string yaml = TestHelperForCurrentProject.GetTestFileContent("CrawlerConfigTests/Sample.yaml");

            var deserializer = Constants.SloaderYamlDeserializer;
            var result       = deserializer.Deserialize <SloaderConfig>(new StringReader(yaml));

            Assert.NotNull(result.Crawler);
            Assert.Equal(3, result.Crawler.FeedsToCrawl.Count);
            Assert.Equal(3, result.Crawler.TwitterTimelinesToCrawl.Count);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
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));
        }
Ejemplo n.º 11
0
        private static string GetTestFileContent(string file)
        {
            string responseData = TestHelperForCurrentProject.GetTestFileContent($"GitHubIssueCrawlerTests/Sample/repo_{file}.json");

            return(responseData);
        }
Ejemplo n.º 12
0
        private static string GetTestFileContent()
        {
            string responseData = TestHelperForCurrentProject.GetTestFileContent("TwitterTimelineCrawlerTests/Sample/user_timeline.json");

            return(responseData);
        }
Ejemplo n.º 13
0
        private static string GetTestFileContentFor(string topic)
        {
            string responseData = TestHelperForCurrentProject.GetTestFileContent($"GitHubEventCrawlerTests/Sample/{topic}.json");

            return(responseData);
        }
Ejemplo n.º 14
0
        private static string GetTestFileContent()
        {
            string responseData = TestHelperForCurrentProject.GetTestFileContent("TwitterUserCrawlerTests/Sample/lookup.json");

            return(responseData);
        }
Ejemplo n.º 15
0
        private static string GetTestFileContent()
        {
            string responseData = TestHelperForCurrentProject.GetTestFileContent($"LocatorTests/GitHubLocator.json");

            return(responseData);
        }