45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using System.Security.Cryptography;
|
|
using VolcanicCore.Persistence;
|
|
using VolcanicCore.Persistence.Encryption;
|
|
using VolcanicCore.Persistence.Migrations;
|
|
using VolcanicCore.Persistence.Repositories;
|
|
|
|
namespace VolcanicCore.Tests;
|
|
|
|
public class AdminConfigRepositoryTests
|
|
{
|
|
private static (AdminConfigRepository repo, string dbPath) Setup()
|
|
{
|
|
var path = Path.Combine(Path.GetTempPath(), $"vc-{Guid.NewGuid():N}.db");
|
|
var f = new SqliteConnectionFactory(path);
|
|
using (var conn = f.Open())
|
|
new Migrator(new IMigration[] { new Migration001Initial() }).Apply(conn);
|
|
var key = new byte[32]; RandomNumberGenerator.Fill(key);
|
|
return (new AdminConfigRepository(f, new EncryptionService(key), new HashSet<string>()), path);
|
|
}
|
|
|
|
[Fact]
|
|
public void Get_returns_null_for_unknown_key()
|
|
{
|
|
var (repo, _) = Setup();
|
|
Assert.Null(repo.Get("nope"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Set_inserts_new_row_and_get_reads_it_back()
|
|
{
|
|
var (repo, _) = Setup();
|
|
repo.Set("k", "v");
|
|
Assert.Equal("v", repo.Get("k"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Set_updates_existing_row_via_upsert()
|
|
{
|
|
var (repo, _) = Setup();
|
|
repo.Set("k", "v1");
|
|
repo.Set("k", "v2");
|
|
Assert.Equal("v2", repo.Get("k"));
|
|
}
|
|
}
|