using BuildFlow.Shared.Domain.Errors; using BuildFlow.Shared.Domain.Exceptions; 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; /// /// SetConversationMutedCommandHandler:成功置免打扰 / 参与者不存在抛 NotFound。 /// public class SetConversationMutedCommandHandlerTests { private static readonly Guid UserId = Guid.Parse("22222222-2222-2222-2222-222222222222"); private static readonly Guid ConvId = Guid.Parse("11111111-1111-1111-1111-111111111111"); [Fact] public async Task Sets_muted_for_participant() { await using var db = IMTestDb.Create(); db.Conversations.Add(ImTestData.BuildConversation(ConvId, ConversationTypeEnum.Private, (UserId, 0))); await db.SaveChangesAsync(); var handler = new SetConversationMutedCommandHandler(db); await handler.Handle(new SetConversationMutedCommand(ConvId, UserId, true), CancellationToken.None); var p = await db.ConversationParticipants.FirstAsync(x => x.ConversationId == ConvId && x.UserId == UserId); p.IsMuted.Should().BeTrue(); } [Fact] public async Task Throws_not_found_when_participant_missing() { await using var db = IMTestDb.Create(); var handler = new SetConversationMutedCommandHandler(db); var act = async () => await handler.Handle(new SetConversationMutedCommand(ConvId, UserId, true), CancellationToken.None); var ex = await act.Should().ThrowAsync(); ex.Which.Code.Should().Be(ErrorCode.NotFound); } }