Newsbot.Collector/Newsbot.Collector.Tests/Tables/ArticlesTableTests.cs
James Tombleson 17e97b4e09
Features/table clients (#5)
* inital table clients are almost ready

* adding new repo interfaces

* adding MS DI to the tables

* adding tables and MS DI to jobs

* updated how the config builder works and pass Iconfig to jobs

* Updated how articles interface returns a value

* updated constructors to support DI and removed static call

* added source consts and model notes

* updated sources.type to contain the value to link what job collects it

* added RssWatcherJob to hangfire

* DI and hangfire jobs wont work.  Defering to options classes

* Services updated to have options exposed over DI

* Tests have been updated.. more to come
2023-02-19 21:39:03 -08:00

59 lines
1.6 KiB
C#

using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Database.Repositories;
using Newsbot.Collector.Domain.Models;
namespace Newsbot.Collector.Tests.Tables;
public class ArticlesTableTests
{
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;
}
[Fact]
public void ArticlesListTest()
{
var cfg = GetConfiguration();
var client = new ArticlesTable(cfg);
client.List();
}
[Fact]
public void GetByIDTest()
{
var uid = Guid.Parse("4ac46772-253c-4c3d-8a2c-29239abd2ad4");
var cfg = GetConfiguration();
var client = new ArticlesTable(cfg);
var res = client.GetById(uid);
if (!res.ID.Equals(uid))
{
Assert.Fail("Incorrect record or not found");
}
}
[Fact]
public void NewRecordTest()
{
var cfg = GetConfiguration();
var client = new ArticlesTable(cfg);
var m = new ArticlesModel
{
ID = Guid.NewGuid(),
SourceID = Guid.NewGuid(),
Tags = "thing, thing2",
Title = "Unit Testing!",
URL = "https://google.com",
PubDate = DateTime.Now.ToLocalTime(),
};
client.New(m);
}
}