Add tests

This commit is contained in:
rossmill76 committed 2026-03-01 19:00:23 +00:00
1 parent d5127c7405
commit 88aaaecb1a
15 files changed
+1755 -34

No files matched your search

@@ -0,0 +1,51 @@
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using BudgetApp.Data;
namespace BudgetApp.Tests.Helpers;
public sealed class TestDbContextFactory : IDisposable
{
private readonly SqliteConnection _connection;
public const string TestUserId = "test-user-id";
public const string OtherUserId = "other-user-id";
public TestDbContextFactory()
{
_connection = new SqliteConnection("DataSource=:memory:");
_connection.Open();
using var context = CreateContext();
context.Database.EnsureCreated();
context.Users.AddRange(
new ApplicationUser
{
Id = TestUserId,
UserName = "test@test.com",
NormalizedUserName = "TEST@TEST.COM",
Email = "test@test.com",
NormalizedEmail = "TEST@TEST.COM"
},
new ApplicationUser
{
Id = OtherUserId,
UserName = "other@test.com",
NormalizedUserName = "OTHER@TEST.COM",
Email = "other@test.com",
NormalizedEmail = "OTHER@TEST.COM"
});
context.SaveChanges();
}
public ApplicationDbContext CreateContext()
{
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseSqlite(_connection)
.Options;
return new ApplicationDbContext(options);
}
public void Dispose() => _connection.Dispose();
}