- 添加HNSW向量索引提升检索性能 - 实现Hybrid检索模式支持向量和关键词双路召回 - 采用RRF算法融合多路召回结果 - 支持ParentChild分块模式的上下文回填 - 优化向量写入采用批量SQL操作提升性能 - 添加RAG PostgreSQL连接字符串配置 - 更新部署脚本增加PGVector集成测试 - 修正表名引用从document_chunks到b_document_chunks - 重构RagRetrievalService实现完整的检索流程 - 增加重排策略支持关键词和LLM重排 - 修改服务器部署地址配置
58 lines
2.4 KiB
C#
58 lines
2.4 KiB
C#
using BuildFlow.Shared.Domain.Errors;
|
||
using BuildFlow.Shared.Domain.Exceptions;
|
||
using FluentAssertions;
|
||
using IM.Application.Chat.Commands;
|
||
using IM.Application.Chat.Handlers;
|
||
using IM.Infrastructure.Persistence;
|
||
using Microsoft.EntityFrameworkCore;
|
||
using Xunit;
|
||
|
||
namespace BuildFlow.IM.Tests.Chat;
|
||
|
||
/// <summary>
|
||
/// RemoveGroupMemberCommandHandler:群不存在 NotFound;管理员移除群主 Business;
|
||
/// 普通成员自助退群成功(同步移出会话参与者)。
|
||
/// </summary>
|
||
public class RemoveGroupMemberCommandHandlerTests
|
||
{
|
||
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 static readonly Guid AdminId = Guid.Parse("30000000-0000-0000-0000-000000000001");
|
||
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 RemoveGroupMemberCommandHandler(db);
|
||
var act = async () => await handler.Handle(new RemoveGroupMemberCommand(Guid.NewGuid(), OwnerId, MemberId), CancellationToken.None);
|
||
|
||
var ex = await act.Should().ThrowAsync<NotFoundException>();
|
||
ex.Which.Code.Should().Be(ErrorCode.NotFound);
|
||
}
|
||
|
||
[Fact]
|
||
public async Task Admin_cannot_remove_owner()
|
||
{
|
||
await using var db = IMTestDb.Create();
|
||
var (_, groupId) = await IMTestDb.SeedGroupAsync(db, Name, OwnerId, AdminId);
|
||
var handler = new RemoveGroupMemberCommandHandler(db);
|
||
var act = async () => await handler.Handle(new RemoveGroupMemberCommand(groupId, AdminId, OwnerId), CancellationToken.None);
|
||
|
||
var ex = await act.Should().ThrowAsync<BusinessException>();
|
||
ex.Which.Code.Should().Be(ErrorCode.Business);
|
||
}
|
||
|
||
[Fact]
|
||
public async Task Member_can_remove_self()
|
||
{
|
||
await using var db = IMTestDb.Create();
|
||
var (convId, groupId) = await IMTestDb.SeedGroupAsync(db, Name, OwnerId, MemberId);
|
||
var handler = new RemoveGroupMemberCommandHandler(db);
|
||
await handler.Handle(new RemoveGroupMemberCommand(groupId, MemberId, MemberId), CancellationToken.None);
|
||
|
||
(await db.GroupMembers.AnyAsync(m => m.GroupId == groupId && m.UserId == MemberId)).Should().BeFalse();
|
||
(await db.ConversationParticipants.AnyAsync(p => p.ConversationId == convId && p.UserId == MemberId)).Should().BeFalse();
|
||
}
|
||
}
|