using FluentAssertions; using Knot.Modules.Conversations.Application.Chats.Commands.CreatePersonalChat; using Knot.Modules.Conversations.Domain; using Knot.Modules.Conversations.Application.Abstractions; using Knot.Shared.Kernel; using NSubstitute; using Xunit; using System; using System.Threading; using System.Threading.Tasks; namespace Knot.Modules.Conversations.UnitTests; public class CreatePersonalChatCommandHandlerTests { private readonly IChatRepository _chatRepository; private readonly IChatsUnitOfWork _unitOfWork; private readonly CreatePersonalChatCommandHandler _handler; public CreatePersonalChatCommandHandlerTests() { _chatRepository = Substitute.For(); _unitOfWork = Substitute.For(); _handler = new CreatePersonalChatCommandHandler(_chatRepository, _unitOfWork); } [Fact] public async Task Handle_ShouldReturnError_WhenChatAlreadyExists() { // Arrange var command = new CreatePersonalChatCommand(Guid.NewGuid(), Guid.NewGuid()); _chatRepository.GetPersonalChatAsync(command.InitiatorId, command.TargetUserId, Arg.Any()) .Returns(PersonalChat.Create(command.InitiatorId, command.TargetUserId)); // Act var result = await _handler.Handle(command, CancellationToken.None); // Assert result.IsFailure.Should().BeTrue(); result.Error.Should().Be(ChatErrors.PersonalChatAlreadyExists); } }