PlanTempusApp/PlanTempus.X.BDD/FeatureFixtures/AccountRegistrationSpecs.cs

91 lines
2.4 KiB
C#
Raw Normal View History

using LightBDD.Framework;
2025-02-27 17:24:58 +01:00
using LightBDD.Framework.Scenarios;
using LightBDD.MsTest3;
2025-02-28 17:56:14 +01:00
using PlanTempus.X.Services;
2025-02-27 17:24:58 +01:00
using Shouldly;
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")]
public partial class AccountRegistrationSpecs : FeatureFixture
2025-02-27 17:24:58 +01:00
{
protected Account _currentAccount;
2025-02-28 17:56:14 +01:00
protected string _currentEmail;
protected Exception _registrationError;
IAccountService _accountService;
2025-02-28 17:56:14 +01:00
IEmailService _emailService;
IOrganizationService _organizationService;
public async Task Given_no_account_exists_with_email(string email)
2025-02-28 17:56:14 +01:00
{
// Ensure account doesn't exist with email
var account = await _accountService.GetAccountByEmailAsync(email);
account.ShouldBeNull();
2025-02-28 17:56:14 +01:00
_currentEmail = email;
}
public async Task When_I_submit_registration_with_email_and_password(string email, string password)
2025-02-28 17:56:14 +01:00
{
try
{
_currentAccount = await _accountService.CreateAccountAsync(email, password);
2025-02-28 17:56:14 +01:00
_currentEmail = email;
}
catch (Exception ex)
{
_registrationError = ex;
}
}
public async Task When_I_submit_registration_with_email(string email)
{
try
{
_currentAccount = await _accountService.CreateAccountAsync(email, "TestPassword123!");
2025-02-28 17:56:14 +01:00
_currentEmail = email;
}
catch (Exception ex)
2025-02-27 17:24:58 +01:00
{
2025-02-28 17:56:14 +01:00
_registrationError = ex;
}
}
public async Task Then_a_new_account_should_be_created_with_email_and_confirmation_status(string email, bool confirmationStatus)
2025-02-28 17:56:14 +01:00
{
_currentAccount.ShouldNotBeNull();
_currentAccount.Email.ShouldBe(email);
_currentAccount.EmailConfirmed.ShouldBe(confirmationStatus);
2025-02-28 17:56:14 +01:00
2025-03-03 00:42:20 +01:00
await Task.CompletedTask;
}
public async Task Then_a_confirmation_email_should_be_sent()
2025-02-28 17:56:14 +01:00
{
var emailSent = _emailService.WasConfirmationEmailSent(_currentEmail);
emailSent.ShouldBeTrue();
2025-02-27 17:24:58 +01:00
2025-03-03 00:42:20 +01:00
await Task.CompletedTask;
}
public async Task Given_an_account_already_exists_with_email(string email)
2025-02-28 17:56:14 +01:00
{
// Create an account first to ensure it exists
_currentAccount = await _accountService.CreateAccountAsync(email, "ExistingPassword123!");
_currentAccount.ShouldNotBeNull();
2025-02-28 17:56:14 +01:00
_currentEmail = email;
2025-03-03 00:42:20 +01:00
await Task.CompletedTask;
}
2025-02-28 17:56:14 +01:00
2025-03-03 00:42:20 +01:00
public async Task Then_registration_should_fail_with_error(string expectedErrorMessage)
2025-02-28 17:56:14 +01:00
{
2025-03-03 00:42:20 +01:00
_registrationError.ShouldNotBeNull();
_registrationError.Message.ShouldBe(expectedErrorMessage);
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
}