build-flow.api/tests/BuildFlow.IM.Tests/Chat/CreateGroupCommandHandlerTests.cs
xiangning 7479521546 feat(rag): 实现RAG模块的Hybrid检索和向量索引优化
- 添加HNSW向量索引提升检索性能
- 实现Hybrid检索模式支持向量和关键词双路召回
- 采用RRF算法融合多路召回结果
- 支持ParentChild分块模式的上下文回填
- 优化向量写入采用批量SQL操作提升性能
- 添加RAG PostgreSQL连接字符串配置
- 更新部署脚本增加PGVector集成测试
- 修正表名引用从document_chunks到b_document_chunks
- 重构RagRetrievalService实现完整的检索流程
- 增加重排策略支持关键词和LLM重排
- 修改服务器部署地址配置
2026-08-11 10:59:09 +08:00

50 lines
2.0 KiB
C#

using FluentAssertions;
using IM.Application.Chat.Commands;
using IM.Application.Chat.Handlers;
using IM.Domain.Enums;
using IM.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Xunit;
namespace BuildFlow.IM.Tests.Chat;
/// <summary>
/// CreateGroupCommandHandler 成功路径:建群+会话+成员,群主 Owner 角色,成员去重。
/// </summary>
public class CreateGroupCommandHandlerTests
{
private static readonly Guid OwnerId = Guid.Parse("22222222-2222-2222-2222-222222222222");
private static readonly Guid MemberA = Guid.Parse("33333333-3333-3333-3333-333333333333");
private static readonly Guid MemberB = Guid.Parse("30000000-0000-0000-0000-000000000001");
[Fact]
public async Task Creates_group_with_owner_and_members()
{
await using var db = IMTestDb.Create();
var handler = new CreateGroupCommandHandler(db);
var result = await handler.Handle(
new CreateGroupCommand("group-1", null, "desc", OwnerId, new List<Guid> { MemberA, MemberB }),
CancellationToken.None);
result.Name.Should().Be("group-1");
result.OwnerId.Should().Be(OwnerId);
result.MemberCount.Should().Be(3);
(await db.Groups.CountAsync()).Should().Be(1);
(await db.ConversationParticipants.CountAsync(p => p.ConversationId == result.ConversationId)).Should().Be(3);
(await db.GroupMembers.CountAsync(m => m.GroupId == result.Id && m.Role == GroupMemberRoleEnum.Owner)).Should().Be(1);
}
[Fact]
public async Task Dedups_owner_inside_member_list()
{
await using var db = IMTestDb.Create();
var handler = new CreateGroupCommandHandler(db);
var result = await handler.Handle(
new CreateGroupCommand("group-2", null, null, OwnerId, new List<Guid> { OwnerId, MemberA }),
CancellationToken.None);
result.MemberCount.Should().Be(2);
(await db.GroupMembers.CountAsync(m => m.GroupId == result.Id)).Should().Be(2);
}
}