コード例 #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));
        }
コード例 #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));
        }
コード例 #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();
        }
コード例 #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));
        }
コード例 #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");
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #8
0
        private static string GetTestFileContent(string file)
        {
            string responseData = TestHelperForCurrentProject.GetTestFileContent($"GitHubIssueCrawlerTests/Sample/repo_{file}.json");

            return(responseData);
        }
コード例 #9
0
        private static string GetTestFileContent()
        {
            string responseData = TestHelperForCurrentProject.GetTestFileContent("TwitterTimelineCrawlerTests/Sample/user_timeline.json");

            return(responseData);
        }
コード例 #10
0
        private static string GetTestFileContentFor(string topic)
        {
            string responseData = TestHelperForCurrentProject.GetTestFileContent($"GitHubEventCrawlerTests/Sample/{topic}.json");

            return(responseData);
        }
コード例 #11
0
        private static string GetTestFileContent()
        {
            string responseData = TestHelperForCurrentProject.GetTestFileContent("TwitterUserCrawlerTests/Sample/lookup.json");

            return(responseData);
        }
コード例 #12
0
        private static string GetTestFileContent()
        {
            string responseData = TestHelperForCurrentProject.GetTestFileContent($"LocatorTests/GitHubLocator.json");

            return(responseData);
        }