.net10 сервер с рабочими звонками и файлами
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using FluentAssertions;
|
||||
using NSubstitute;
|
||||
using Vortex.Modules.Identity.Application.Abstractions;
|
||||
using Vortex.Modules.Identity.Application.Users.Register;
|
||||
using Vortex.Modules.Identity.Domain;
|
||||
using Vortex.Shared.Kernel;
|
||||
using Xunit;
|
||||
|
||||
namespace Vortex.Modules.Identity.UnitTests;
|
||||
|
||||
public class RegisterUserCommandHandlerTests
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IIdentityUnitOfWork _unitOfWork;
|
||||
private readonly RegisterUserCommandHandler _handler;
|
||||
|
||||
public RegisterUserCommandHandlerTests()
|
||||
{
|
||||
_userRepository = Substitute.For<IUserRepository>();
|
||||
_unitOfWork = Substitute.For<IIdentityUnitOfWork>();
|
||||
_handler = new RegisterUserCommandHandler(_userRepository, _unitOfWork);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_ShouldReturnSuccess_WhenRegistrationIsSuccessful()
|
||||
{
|
||||
// Arrange
|
||||
var command = new RegisterUserCommand("testuser", "password123", "Test User", "test@example.com", "My bio");
|
||||
_userRepository.IsUsernameUniqueAsync(command.Username, Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
|
||||
// Act
|
||||
var result = await _handler.Handle(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsSuccess.Should().BeTrue();
|
||||
result.Value.Should().NotBeEmpty();
|
||||
|
||||
_userRepository.Received(1).Add(Arg.Is<User>(u =>
|
||||
u.Username == command.Username &&
|
||||
u.DisplayName == command.DisplayName &&
|
||||
u.Email == command.Email));
|
||||
|
||||
await _unitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_ShouldReturnFailure_WhenUsernameIsNotUnique()
|
||||
{
|
||||
// Arrange
|
||||
var command = new RegisterUserCommand("duplicate", "password123", "Test User", null, null);
|
||||
_userRepository.IsUsernameUniqueAsync(command.Username, Arg.Any<CancellationToken>())
|
||||
.Returns(false);
|
||||
|
||||
// Act
|
||||
var result = await _handler.Handle(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsFailure.Should().BeTrue();
|
||||
result.Error.Code.Should().Be("Identity.UsernameNotUnique");
|
||||
|
||||
_userRepository.DidNotReceive().Add(Arg.Any<User>());
|
||||
await _unitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user