feat: added Sdn repo and added some initial tests

This commit is contained in:
Stevan Freeborn
2024-08-21 09:57:24 -05:00
parent 00994cd4d9
commit ecc26d86f6
18 changed files with 474 additions and 373 deletions
@@ -1,8 +1,9 @@
namespace SanctionsSearch.Worker.Persistence;
class AppDbContext(DbOptions options) : DbContext
class AppDbContext(DbOptions options, TimeProvider timeProvider) : DbContext
{
private readonly DbOptions _options = options;
private readonly TimeProvider _timeProvider = timeProvider;
private SqliteConnection? _connection;
internal string DatabasePath { get; private set; } = string.Empty;
public DbSet<Sdn> Sdns { get; set; } = default!;
@@ -32,8 +33,7 @@ class AppDbContext(DbOptions options) : DbContext
public async override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
// TODO: Use TimeProvider instead of DateTime.UtcNow
var now = DateTime.UtcNow;
var now = _timeProvider.GetUtcNow().DateTime;
foreach (var changedEntity in ChangeTracker.Entries())
{
@@ -2,10 +2,10 @@ namespace SanctionsSearch.Worker.Persistence;
class EfRepository<T> : IRepository<T> where T : Entity
{
protected readonly AppDbContext _context;
protected readonly DbContext _context;
protected readonly ILogger<EfRepository<T>> _logger;
public EfRepository(AppDbContext context, ILogger<EfRepository<T>> logger)
public EfRepository(DbContext context, ILogger<EfRepository<T>> logger)
{
_context = context;
_logger = logger;
@@ -1,7 +1,7 @@
namespace SanctionsSearch.Worker.Persistence;
class SdnRepository(
AppDbContext dbContext,
DbContext dbContext,
ILogger<SdnRepository> logger
) : EfRepository<Sdn>(dbContext, logger), ISdnRepository
{