2023-02-26 09:40:04 -08:00
|
|
|
using Newsbot.Collector.Services.HtmlParser;
|
|
|
|
|
|
|
|
namespace Newsbot.Collector.Tests.Services;
|
|
|
|
|
|
|
|
public class HtmlPageReaderTests
|
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void BaseSiteContainsRssFeed()
|
|
|
|
{
|
2023-03-31 22:49:39 -07:00
|
|
|
var client = new HtmlPageReader(new HtmlPageReaderOptions
|
|
|
|
{
|
|
|
|
Url = "https://dotnettutorials.net/"
|
|
|
|
});
|
2023-02-26 09:40:04 -08:00
|
|
|
var headClient = new HeadParserClient(client.GetSiteContent());
|
|
|
|
var feedUri = headClient.GetSiteFeed();
|
2023-03-31 22:49:39 -07:00
|
|
|
if (feedUri == "") Assert.Fail("Failed to find the RSS feed");
|
2023-02-26 09:40:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void SiteDoesNotReturnRssFeed()
|
|
|
|
{
|
2023-03-31 22:49:39 -07:00
|
|
|
var client = new HtmlPageReader(new HtmlPageReaderOptions
|
|
|
|
{
|
|
|
|
Url = "https://www.engadget.com/"
|
|
|
|
});
|
2023-02-26 09:40:04 -08:00
|
|
|
var headClient = new HeadParserClient(client.GetSiteContent());
|
|
|
|
var feedUri = headClient.GetSiteFeed();
|
2023-03-31 22:49:39 -07:00
|
|
|
if (feedUri == "") Assert.Fail("");
|
2023-02-26 09:40:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void CanFindBodyOfTheArticle()
|
|
|
|
{
|
2023-03-31 22:49:39 -07:00
|
|
|
var client = new HtmlPageReader(new HtmlPageReaderOptions
|
|
|
|
{
|
|
|
|
Url = "https://www.engadget.com/apple-is-convinced-my-dog-is-stalking-me-143100932.html"
|
|
|
|
});
|
2023-02-26 09:40:04 -08:00
|
|
|
var c = client.CollectPostContent();
|
|
|
|
Console.WriteLine(c);
|
|
|
|
}
|
2023-03-31 22:49:39 -07:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void FindYoutubeChannelId()
|
|
|
|
{
|
|
|
|
var url = "https://www.youtube.com/@CityPlannerPlays";
|
|
|
|
//var b = new BrowserClient();
|
|
|
|
//var pageSource = b.GetPageSource(url);
|
|
|
|
|
|
|
|
var client = new HtmlPageReader(new HtmlPageReaderOptions
|
|
|
|
{
|
|
|
|
Url = url
|
|
|
|
});
|
|
|
|
client.Parse();
|
|
|
|
if (client.Data.Header.YoutubeChannelID is null) Assert.Fail("missing youtube id");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void CanExtractHeadersFromReddit()
|
|
|
|
{
|
|
|
|
var url = "https://www.reddit.com/";
|
|
|
|
var client = new HtmlPageReader(new HtmlPageReaderOptions
|
|
|
|
{
|
|
|
|
Url = url
|
|
|
|
});
|
|
|
|
client.Parse();
|
|
|
|
if (client.Data.Header.Image == "") Assert.Fail("missing an expected image from the reddit header.");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void CanExtractHeadersFromSubreddit()
|
|
|
|
{
|
|
|
|
var url = "https://www.reddit.com/r/ffxiv";
|
|
|
|
var client = new HtmlPageReader(new HtmlPageReaderOptions
|
|
|
|
{
|
|
|
|
Url = url
|
|
|
|
});
|
|
|
|
client.Parse();
|
|
|
|
if (client.Data.Header.Image == "") Assert.Fail("missing an expected image from the reddit header.");
|
|
|
|
}
|
2023-02-26 09:40:04 -08:00
|
|
|
}
|