Newsbot.Collector/Newsbot.Collector.Tests/Jobs/RssWatcherJobTest.cs

73 lines
2.0 KiB
C#

using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Domain.Models.Config;
using Newsbot.Collector.Services.Jobs;
using Xunit.Abstractions;
namespace Newsbot.Collector.Tests.Jobs;
public class RssWatcherJobTest
{
private readonly ITestOutputHelper _testOutputHelper;
public RssWatcherJobTest(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}
private IConfiguration GetConfiguration()
{
var inMemorySettings = new Dictionary<string, string>
{
{
"ConnectionStrings:database",
"Host=localhost;Username=postgres;Password=postgres;Database=postgres;sslmode=disable"
}
};
IConfiguration configuration = new ConfigurationBuilder()
.AddInMemoryCollection(inMemorySettings)
.Build();
return configuration;
}
private string ConnectionString()
{
return "Host=localhost;Username=postgres;Password=postgres;Database=postgres;sslmode=disable";
}
[Fact]
public void CanFindItemsNoDb()
{
const string url = "https://www.engadget.com/rss.xml";
var client = new RssWatcherJob();
client.Collect(url, Guid.NewGuid(), 0);
}
[Fact]
public void CanAddItemsToDb()
{
var url = "https://www.engadget.com/rss.xml";
var client = new RssWatcherJob();
client.InitAndExecute(new RssWatcherJobOptions
{
ConnectionString = ConnectionString(),
OpenTelemetry = "",
IsEnabled = true
});
var items = client.Collect(url, Guid.NewGuid(), 0);
client.UpdateDatabase(items);
}
[Fact]
public void CanReadHtmlDrivenFeedPage()
{
//var url = "https://www.howtogeek.com/feed/";
var client = new RssWatcherJob();
client.InitAndExecute(new RssWatcherJobOptions
{
ConnectionString = ConnectionString(),
OpenTelemetry = "",
IsEnabled = true
});
}
}