2026-01-09 22:14:46 +01:00
|
|
|
using LightBDD.Framework;
|
2025-02-27 17:24:58 +01:00
|
|
|
using LightBDD.Framework.Scenarios;
|
2026-01-10 11:13:33 +01:00
|
|
|
using PlanTempus.Components.Accounts.Create;
|
|
|
|
|
using PlanTempus.Components.Accounts.Exceptions;
|
|
|
|
|
using PlanTempus.Core.CommandQueries;
|
2025-02-27 17:24:58 +01:00
|
|
|
using Shouldly;
|
2026-01-10 11:13:33 +01:00
|
|
|
|
2025-02-27 17:24:58 +01:00
|
|
|
namespace PlanTempus.X.BDD.FeatureFixtures;
|
2025-02-28 17:56:14 +01:00
|
|
|
|
2025-02-27 17:24:58 +01:00
|
|
|
[TestClass]
|
2025-02-28 17:56:14 +01:00
|
|
|
[FeatureDescription(@"As a new user
|
|
|
|
|
I want to register with my email
|
|
|
|
|
So I can start using the system")]
|
2026-01-10 11:13:33 +01:00
|
|
|
public partial class AccountRegistrationSpecs : BddTestFixture
|
2025-02-27 17:24:58 +01:00
|
|
|
{
|
2026-01-10 11:13:33 +01:00
|
|
|
protected CommandResponse _commandResponse;
|
|
|
|
|
protected string _currentEmail;
|
|
|
|
|
protected Exception _registrationError;
|
2025-02-28 17:56:14 +01:00
|
|
|
|
2026-01-10 11:13:33 +01:00
|
|
|
public async Task Given_a_unique_email_address()
|
|
|
|
|
{
|
|
|
|
|
// Generate a unique email to ensure no account exists
|
|
|
|
|
_currentEmail = $"{GetRandomWord()}_{Guid.NewGuid():N}@test.example.com";
|
|
|
|
|
await Task.CompletedTask;
|
|
|
|
|
}
|
2025-02-28 17:56:14 +01:00
|
|
|
|
2026-01-10 11:13:33 +01:00
|
|
|
public async Task When_I_submit_registration_with_valid_credentials()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var command = new CreateAccountCommand
|
|
|
|
|
{
|
|
|
|
|
Email = _currentEmail,
|
|
|
|
|
Password = "TestPassword123!",
|
|
|
|
|
IsActive = true,
|
|
|
|
|
CorrelationId = Guid.NewGuid()
|
|
|
|
|
};
|
2025-02-28 17:56:14 +01:00
|
|
|
|
2026-01-10 11:13:33 +01:00
|
|
|
_commandResponse = await CommandHandler.Handle(command);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_registrationError = ex;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-28 17:56:14 +01:00
|
|
|
|
2026-01-10 11:13:33 +01:00
|
|
|
public async Task When_I_submit_registration_with_email(string email, string password)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var command = new CreateAccountCommand
|
|
|
|
|
{
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password,
|
|
|
|
|
IsActive = true,
|
|
|
|
|
CorrelationId = Guid.NewGuid()
|
|
|
|
|
};
|
2025-02-28 17:56:14 +01:00
|
|
|
|
2026-01-10 11:13:33 +01:00
|
|
|
_commandResponse = await CommandHandler.Handle(command);
|
|
|
|
|
_currentEmail = email;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_registrationError = ex;
|
|
|
|
|
}
|
2025-03-03 00:42:20 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-10 11:13:33 +01:00
|
|
|
public async Task Then_the_account_should_be_created_successfully()
|
|
|
|
|
{
|
|
|
|
|
_registrationError.ShouldBeNull();
|
|
|
|
|
_commandResponse.ShouldNotBeNull();
|
|
|
|
|
_commandResponse.RequestId.ShouldNotBe(Guid.Empty);
|
|
|
|
|
_commandResponse.CommandName.ShouldBe(nameof(CreateAccountCommand));
|
2025-02-27 17:24:58 +01:00
|
|
|
|
2025-03-03 00:42:20 +01:00
|
|
|
await Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-09 22:14:46 +01:00
|
|
|
public async Task Given_an_account_already_exists_with_email(string email)
|
2026-01-10 11:13:33 +01:00
|
|
|
{
|
|
|
|
|
// Create an account first to ensure it exists
|
|
|
|
|
var command = new CreateAccountCommand
|
|
|
|
|
{
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = "ExistingPassword123!",
|
|
|
|
|
IsActive = true,
|
|
|
|
|
CorrelationId = Guid.NewGuid()
|
|
|
|
|
};
|
2025-02-28 17:56:14 +01:00
|
|
|
|
2026-01-10 11:13:33 +01:00
|
|
|
await CommandHandler.Handle(command);
|
|
|
|
|
_currentEmail = email;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task When_I_try_to_register_with_the_same_email()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var command = new CreateAccountCommand
|
|
|
|
|
{
|
|
|
|
|
Email = _currentEmail,
|
|
|
|
|
Password = "AnotherPassword123!",
|
|
|
|
|
IsActive = true,
|
|
|
|
|
CorrelationId = Guid.NewGuid()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_commandResponse = await CommandHandler.Handle(command);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_registrationError = ex;
|
|
|
|
|
}
|
2025-03-03 00:42:20 +01:00
|
|
|
}
|
2025-02-28 17:56:14 +01:00
|
|
|
|
2026-01-10 11:13:33 +01:00
|
|
|
public async Task Then_registration_should_fail_with_duplicate_email_error()
|
|
|
|
|
{
|
|
|
|
|
_registrationError.ShouldNotBeNull();
|
|
|
|
|
_registrationError.ShouldBeOfType<EmailAlreadyRegistreredException>();
|
2025-02-28 17:56:14 +01:00
|
|
|
|
2025-03-03 00:42:20 +01:00
|
|
|
await Task.CompletedTask;
|
|
|
|
|
}
|
2025-02-28 17:56:14 +01:00
|
|
|
}
|