build-flow.api/tests/BuildFlow.IM.Tests/Chat/GetGroupQueryHandlerTests.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

57 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BuildFlow.Shared.Domain.Errors;
using BuildFlow.Shared.Domain.Exceptions;
using FluentAssertions;
using IM.Application.Chat.Handlers;
using IM.Application.Chat.Queries;
using IM.Infrastructure.Persistence;
using Xunit;
namespace BuildFlow.IM.Tests.Chat;
/// <summary>
/// GetGroupQueryHandler:群不存在 NotFound;非成员拒绝(Forbidden);成员返回群详情。
/// </summary>
public class GetGroupQueryHandlerTests
{
private static readonly Guid OwnerId = Guid.Parse("22222222-2222-2222-2222-222222222222");
private static readonly Guid MemberId = Guid.Parse("33333333-3333-3333-3333-333333333333");
private const string Name = "group-1";
[Fact]
public async Task Throws_not_found_when_group_missing()
{
await using var db = IMTestDb.Create();
var handler = new GetGroupQueryHandler(db);
var act = async () => await handler.Handle(new GetGroupQuery(Guid.NewGuid(), OwnerId), CancellationToken.None);
var ex = await act.Should().ThrowAsync<NotFoundException>();
ex.Which.Code.Should().Be(ErrorCode.NotFound);
}
[Fact]
public async Task Throws_forbidden_when_not_member()
{
await using var db = IMTestDb.Create();
var (_, groupId) = await IMTestDb.SeedGroupAsync(db, Name, OwnerId, MemberId);
var handler = new GetGroupQueryHandler(db);
var act = async () => await handler.Handle(new GetGroupQuery(groupId, Guid.NewGuid()), CancellationToken.None);
var ex = await act.Should().ThrowAsync<UnauthorizedException>();
ex.Which.Code.Should().Be(ErrorCode.Forbidden);
}
[Fact]
public async Task Returns_group_for_member()
{
await using var db = IMTestDb.Create();
var (_, groupId) = await IMTestDb.SeedGroupAsync(db, Name, OwnerId, MemberId);
var handler = new GetGroupQueryHandler(db);
var result = await handler.Handle(new GetGroupQuery(groupId, OwnerId), CancellationToken.None);
result.Id.Should().Be(groupId);
result.Name.Should().Be(Name);
result.OwnerId.Should().Be(OwnerId);
}
}