Newsbot.Collector/Newsbot.Collector.Tests/Tables/ArticlesTableTests.cs
James Tombleson df348bea5a
All checks were successful
continuous-integration/drone/pr Build is passing
Test updated for ef
2023-07-09 22:12:41 -07:00

63 lines
1.8 KiB
C#

using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Database.Repositories;
using Newsbot.Collector.Domain.Entities;
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 dbconn = cfg.GetConnectionString("Database");
var client = new ArticlesTable(dbconn ?? "");
client.List(0, 25);
}
[Fact]
public void GetByIDTest()
{
var uid = Guid.Parse("4ac46772-253c-4c3d-8a2c-29239abd2ad4");
var cfg = GetConfiguration();
var dbconn = cfg.GetConnectionString("Database");
var client = new ArticlesTable(dbconn ?? "");
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 dbconn = cfg.GetConnectionString("Database");
var client = new ArticlesTable(dbconn ?? "");
var m = new ArticlesEntity
{
Id = Guid.NewGuid(),
SourceId = Guid.NewGuid(),
Tags = "thing, thing2",
Title = "Unit Testing!",
Url = "https://google.com",
PubDate = DateTime.Now.ToUniversalTime(),
};
client.New(m);
}
}