using BuildFlow.Domain.Entities.Conversation; using BuildFlow.Infrastructure.Persistence; using FluentAssertions; using Microsoft.EntityFrameworkCore; using Xunit; namespace BuildFlow.Rag.Tests.Chat; /// 会话知识库导航必须复用现有显式外键,禁止产生影子列。 public sealed class ConversationModelConfigurationTests { [Fact] public void KnowledgeBaseNavigationUsesKnowledgeBaseId() { using var db = new RagDbContext( new DbContextOptionsBuilder() .UseInMemoryDatabase($"conversation-model-{Guid.NewGuid():N}") .Options); var entityType = db.Model.FindEntityType(typeof(ConversationEntity)); entityType.Should().NotBeNull(); entityType!.FindProperty("KnowledgeBaseEntityId").Should().BeNull(); var navigation = entityType.FindNavigation(nameof(ConversationEntity.KnowledgeBaseEntity)); navigation.Should().NotBeNull(); navigation!.ForeignKey.Properties.Select(x => x.Name) .Should().Equal(nameof(ConversationEntity.KnowledgeBaseId)); } }