build-flow.api/tests/BuildFlow.Rag.Tests/Chat/ConversationModelConfigurationTests.cs
2026-07-24 09:50:16 +08:00

30 lines
1.1 KiB
C#

using BuildFlow.Domain.Entities.Conversation;
using BuildFlow.Infrastructure.Persistence;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using Xunit;
namespace BuildFlow.Rag.Tests.Chat;
/// <summary>会话知识库导航必须复用现有显式外键,禁止产生影子列。</summary>
public sealed class ConversationModelConfigurationTests
{
[Fact]
public void KnowledgeBaseNavigationUsesKnowledgeBaseId()
{
using var db = new RagDbContext(
new DbContextOptionsBuilder<RagDbContext>()
.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));
}
}