2023-02-19 21:39:03 -08:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2023-02-16 22:19:05 -08:00
|
|
|
using Newsbot.Collector.Database.Repositories;
|
2023-06-23 20:09:57 -07:00
|
|
|
using Newsbot.Collector.Domain.Entities;
|
2023-02-16 22:19:05 -08:00
|
|
|
using Newsbot.Collector.Domain.Models;
|
|
|
|
|
|
|
|
namespace Newsbot.Collector.Tests.Tables;
|
|
|
|
|
|
|
|
public class ArticlesTableTests
|
|
|
|
{
|
2023-02-19 21:39:03 -08:00
|
|
|
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;
|
|
|
|
}
|
2023-02-16 22:19:05 -08:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ArticlesListTest()
|
|
|
|
{
|
2023-02-19 21:39:03 -08:00
|
|
|
var cfg = GetConfiguration();
|
|
|
|
var client = new ArticlesTable(cfg);
|
2023-06-23 20:09:57 -07:00
|
|
|
client.List(0, 25);
|
2023-02-16 22:19:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void GetByIDTest()
|
|
|
|
{
|
|
|
|
var uid = Guid.Parse("4ac46772-253c-4c3d-8a2c-29239abd2ad4");
|
|
|
|
|
2023-02-19 21:39:03 -08:00
|
|
|
var cfg = GetConfiguration();
|
|
|
|
var client = new ArticlesTable(cfg);
|
2023-02-16 22:19:05 -08:00
|
|
|
var res = client.GetById(uid);
|
2023-06-23 20:09:57 -07:00
|
|
|
if (!res.Id.Equals(uid))
|
2023-02-16 22:19:05 -08:00
|
|
|
{
|
|
|
|
Assert.Fail("Incorrect record or not found");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void NewRecordTest()
|
|
|
|
{
|
2023-02-19 21:39:03 -08:00
|
|
|
var cfg = GetConfiguration();
|
|
|
|
var client = new ArticlesTable(cfg);
|
2023-06-23 20:09:57 -07:00
|
|
|
var m = new ArticlesEntity
|
2023-02-16 22:19:05 -08:00
|
|
|
{
|
2023-06-23 20:09:57 -07:00
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
SourceId = Guid.NewGuid(),
|
2023-02-19 21:39:03 -08:00
|
|
|
Tags = "thing, thing2",
|
|
|
|
Title = "Unit Testing!",
|
2023-06-23 20:09:57 -07:00
|
|
|
Url = "https://google.com",
|
|
|
|
PubDate = DateTime.Now.ToUniversalTime(),
|
2023-02-19 21:39:03 -08:00
|
|
|
};
|
|
|
|
client.New(m);
|
2023-02-16 22:19:05 -08:00
|
|
|
}
|
|
|
|
}
|