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

95 lines
2.3 KiB
C#
Raw Normal View History

2025-02-27 17:24:58 +01:00
using LightBDD.Framework;
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")]
2025-02-27 17:24:58 +01:00
public partial class UserRegistrationSpecs : FeatureFixture
{
2025-02-28 17:56:14 +01:00
protected User _currentUser;
protected string _currentEmail;
protected Exception _registrationError;
IUserService _userService;
IEmailService _emailService;
IOrganizationService _organizationService;
public async Task Given_no_user_exists_with_email(string email)
{
// Ensure user doesn't exist with email
var user = await _userService.GetUserByEmailAsync(email);
user.ShouldBeNull();
_currentEmail = email;
}
public async Task When_I_submit_registration_with_name_and_email(string name, string email)
{
try
{
_currentUser = await _userService.CreateUserAsync(email, name);
_currentEmail = email;
}
catch (Exception ex)
{
_registrationError = ex;
}
}
public async Task When_I_submit_registration_with_email(string email)
{
try
{
_currentUser = await _userService.CreateUserAsync(email, "Test User");
_currentEmail = email;
}
catch (Exception ex)
2025-02-27 17:24:58 +01:00
{
2025-02-28 17:56:14 +01:00
_registrationError = ex;
}
}
2025-03-03 00:42:20 +01:00
public async Task Then_a_new_user_should_be_created_with_email_and_confirmation_status(string email, bool confirmationStatus)
2025-02-28 17:56:14 +01:00
{
_currentUser.ShouldNotBeNull();
_currentUser.Email.ShouldBe(email);
_currentUser.EmailConfirmed.ShouldBe(confirmationStatus);
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_a_user_already_exists_with_email(string email)
2025-02-28 17:56:14 +01:00
{
// Create a user first to ensure it exists
_currentUser = await _userService.CreateUserAsync(email, "Existing User");
_currentUser.ShouldNotBeNull();
_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
}
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
2025-03-03 00:42:20 +01:00
}
2025-02-28 17:56:14 +01:00
}