using BuildFlow.Application.Document.Handlers; using BuildFlow.Application.Document.Queries; using BuildFlow.Infrastructure.Persistence; using BuildFlow.Shared.Domain.Errors; using BuildFlow.Shared.Domain.Exceptions; using FluentAssertions; using Microsoft.EntityFrameworkCore; using Xunit; namespace BuildFlow.Rag.Tests; /// /// Get 文档分块查询处理器测试。 /// 注意:该 Handler 在取回分块后执行 raw SQL(针对 b_document_chunks),依赖真实关系型(Postgres)库; /// 当前存在已知 P0 表名漂移(document_chunks vs b_document_chunks),此处仅覆盖「依赖调用之前」的 /// 文档不存在→NotFound 前置分支,不假设该 bug 已修复,raw SQL 分支交由集成测试覆盖。 /// public class GetDocumentChunksQueryHandlerTests { [Fact] public async Task Handle_DocumentNotFound_ThrowsNotFound() { await using var db = CreateDb(); var handler = new GetDocumentChunksQueryHandler(db); var act = async () => await handler.Handle( new GetDocumentChunksQuery(Guid.NewGuid()), CancellationToken.None); var ex = await act.Should().ThrowAsync(); ex.Which.Code.Should().Be(ErrorCode.NotFound); } private static RagDbContext CreateDb() { var options = new DbContextOptionsBuilder() .UseInMemoryDatabase($"rag-get-chunks-{Guid.NewGuid():N}") .Options; var db = new RagDbContext(options); db.SavingChanges += (_, _) => RagTestDb.FillAudit(db); return db; } }