Перепиливание под чистый DDD
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
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<IChatRepository>();
|
||||
_unitOfWork = Substitute.For<IChatsUnitOfWork>();
|
||||
_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<CancellationToken>())
|
||||
.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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user