Files
ClaudeDo/tests/ClaudeDo.Worker.Tests/Repositories/ListRepositoryConfigTests.cs
mika kuns 36484ed45a feat(worker,ui): wire EF Core into DI and update all consumers to IDbContextFactory
Worker and App Program.cs: replace SqliteConnectionFactory+SchemaInitializer
with AddDbContextFactory<ClaudeDoDbContext> + Database.Migrate(). Repos
changed from AddSingleton to AddScoped.

All singleton services (QueueService, StaleTaskRecovery, WorktreeManager,
TaskRunner) and singleton ViewModels (MainWindowViewModel, TaskDetailViewModel,
TaskListViewModel, TaskEditorViewModel) now take IDbContextFactory<ClaudeDoDbContext>
and create short-lived contexts per operation.

Test infrastructure: DbFixture now uses EF migrations instead of SchemaInitializer;
all test classes create contexts via DbFixture.CreateContext().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 08:59:24 +02:00

69 lines
2.0 KiB
C#

using ClaudeDo.Data;
using ClaudeDo.Data.Models;
using ClaudeDo.Data.Repositories;
using ClaudeDo.Worker.Tests.Infrastructure;
namespace ClaudeDo.Worker.Tests.Repositories;
public sealed class ListRepositoryConfigTests : IDisposable
{
private readonly DbFixture _db = new();
private readonly ClaudeDoDbContext _ctx;
private readonly ListRepository _repo;
private readonly string _listId;
public ListRepositoryConfigTests()
{
_ctx = _db.CreateContext();
_repo = new ListRepository(_ctx);
_listId = Guid.NewGuid().ToString();
_repo.AddAsync(new ListEntity
{
Id = _listId, Name = "Test", CreatedAt = DateTime.UtcNow
}).GetAwaiter().GetResult();
}
[Fact]
public async Task GetConfig_Returns_Null_When_No_Config()
{
var config = await _repo.GetConfigAsync(_listId);
Assert.Null(config);
}
[Fact]
public async Task SetConfig_And_GetConfig_Roundtrips()
{
var config = new ListConfigEntity
{
ListId = _listId,
Model = "sonnet-4-6",
SystemPrompt = "You are helpful.",
AgentPath = "/home/user/.todo-app/agents/dev.md",
};
await _repo.SetConfigAsync(config);
var fetched = await _repo.GetConfigAsync(_listId);
Assert.NotNull(fetched);
Assert.Equal("sonnet-4-6", fetched.Model);
Assert.Equal("You are helpful.", fetched.SystemPrompt);
Assert.Equal("/home/user/.todo-app/agents/dev.md", fetched.AgentPath);
}
[Fact]
public async Task SetConfig_Upserts_On_Duplicate()
{
await _repo.SetConfigAsync(new ListConfigEntity { ListId = _listId, Model = "opus-4-6" });
await _repo.SetConfigAsync(new ListConfigEntity { ListId = _listId, Model = "haiku-4-5" });
var fetched = await _repo.GetConfigAsync(_listId);
Assert.NotNull(fetched);
Assert.Equal("haiku-4-5", fetched.Model);
}
public void Dispose()
{
_ctx.Dispose();
_db.Dispose();
}
}