2023-02-19 21:39:03 -08:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2023-03-31 22:49:39 -07:00
|
|
|
using Newsbot.Collector.Domain.Models.Config;
|
2023-02-16 22:19:05 -08:00
|
|
|
using Newsbot.Collector.Services.Jobs;
|
2023-03-31 22:49:39 -07:00
|
|
|
using Xunit.Abstractions;
|
2023-02-16 22:19:05 -08:00
|
|
|
|
|
|
|
namespace Newsbot.Collector.Tests.Jobs;
|
|
|
|
|
|
|
|
public class RssWatcherJobTest
|
|
|
|
{
|
2023-03-31 22:49:39 -07:00
|
|
|
private readonly ITestOutputHelper _testOutputHelper;
|
|
|
|
|
|
|
|
public RssWatcherJobTest(ITestOutputHelper testOutputHelper)
|
|
|
|
{
|
|
|
|
_testOutputHelper = testOutputHelper;
|
|
|
|
}
|
|
|
|
|
2023-02-19 21:39:03 -08:00
|
|
|
private IConfiguration GetConfiguration()
|
|
|
|
{
|
2023-03-31 22:49:39 -07:00
|
|
|
var inMemorySettings = new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"ConnectionStrings:database",
|
|
|
|
"Host=localhost;Username=postgres;Password=postgres;Database=postgres;sslmode=disable"
|
|
|
|
}
|
2023-02-19 21:39:03 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2023-03-31 22:49:39 -07:00
|
|
|
const string url = "https://www.engadget.com/rss.xml";
|
2023-02-19 21:39:03 -08:00
|
|
|
var client = new RssWatcherJob();
|
2023-03-31 22:49:39 -07:00
|
|
|
client.Collect(url, Guid.NewGuid(), 0);
|
2023-02-19 21:39:03 -08:00
|
|
|
}
|
|
|
|
|
2023-02-16 22:19:05 -08:00
|
|
|
[Fact]
|
2023-02-19 21:39:03 -08:00
|
|
|
public void CanAddItemsToDb()
|
2023-02-16 22:19:05 -08:00
|
|
|
{
|
|
|
|
var url = "https://www.engadget.com/rss.xml";
|
2023-02-19 21:39:03 -08:00
|
|
|
var client = new RssWatcherJob();
|
2023-03-31 22:49:39 -07:00
|
|
|
client.InitAndExecute(new RssWatcherJobOptions
|
|
|
|
{
|
2023-04-01 08:53:34 -07:00
|
|
|
ConnectionString = ConnectionString(),
|
|
|
|
OpenTelemetry = "",
|
|
|
|
IsEnabled = true
|
2023-03-31 22:49:39 -07:00
|
|
|
});
|
2023-02-26 09:40:04 -08:00
|
|
|
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
|
|
|
|
{
|
2023-04-01 08:53:34 -07:00
|
|
|
ConnectionString = ConnectionString(),
|
|
|
|
OpenTelemetry = "",
|
|
|
|
IsEnabled = true
|
2023-02-26 09:40:04 -08:00
|
|
|
});
|
2023-02-16 22:19:05 -08:00
|
|
|
}
|
|
|
|
}
|