Newsbot.Collector/Newsbot.Collector.Tests/Jobs/RssWatcherJobTest.cs
James Tombleson 09fe274752
Features/less comples config managment (#16)
* New single const file for all config info

* seed was updated to reflect route params

* Adjusting config loads to make it easier to follow

* test updates for config loading
2023-04-01 08:53:34 -07:00

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
});
}
}