mirror of
https://github.com/alex289/CleanArchitecture.git
synced 2025-06-29 18:21:08 +00:00
55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using System;
|
|
using CleanArchitecture.Domain.Commands.Users.CreateUser;
|
|
using CleanArchitecture.Domain.Errors;
|
|
using CleanArchitecture.Domain.Events.User;
|
|
using Xunit;
|
|
|
|
namespace CleanArchitecture.Domain.Tests.CommandHandler.User.CreateUser;
|
|
|
|
public sealed class CreateUserCommandHandlerTests
|
|
{
|
|
private readonly CreateUserCommandTestFixture _fixture = new();
|
|
|
|
[Fact]
|
|
public void Should_Create_User()
|
|
{
|
|
_fixture.SetupUser();
|
|
|
|
var command = new CreateUserCommand(
|
|
Guid.NewGuid(),
|
|
"test@email.com",
|
|
"Test",
|
|
"Email",
|
|
"Po=PF]PC6t.?8?ks)A6W");
|
|
|
|
_fixture.CommandHandler.Handle(command, default).Wait();
|
|
|
|
_fixture
|
|
.VerifyNoDomainNotification()
|
|
.VerifyCommit()
|
|
.VerifyRaisedEvent<UserCreatedEvent>(x => x.UserId == command.UserId);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_Not_Create_Already_Existing_User()
|
|
{
|
|
var user = _fixture.SetupUser();
|
|
|
|
var command = new CreateUserCommand(
|
|
user.Id,
|
|
"test@email.com",
|
|
"Test",
|
|
"Email",
|
|
"Po=PF]PC6t.?8?ks)A6W");
|
|
|
|
_fixture.CommandHandler.Handle(command, default).Wait();
|
|
|
|
_fixture
|
|
.VerifyNoCommit()
|
|
.VerifyNoRaisedEvent<UserCreatedEvent>()
|
|
.VerifyAnyDomainNotification()
|
|
.VerifyExistingNotification(
|
|
DomainErrorCodes.UserAlreadyExists,
|
|
$"There is already a User with Id {command.UserId}");
|
|
}
|
|
} |