Refactors the test fixtures and their consumers to compose other fixtures instead of instantiating models inline

This commit is contained in:
BinaryAlley committed 2026-10-02 14:37:23 +03:00
1 parent 0abda472c6
commit 3aadd6de84
157 files changed
+1312 -597

No files matched your search

@@ -23,19 +23,27 @@ public class ChangePasswordRequestFixture
/// <param name="currentPassword">Optional. The current password.</param>
/// <param name="newPassword">Optional. The new password.</param>
/// <param name="newPasswordConfirm">Optional. The new password confirmation.</param>
/// <param name="includeUsername">Whether the username should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeCurrentPassword">Whether the current password should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeNewPassword">Whether the new password should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeNewPasswordConfirm">Whether the new password confirmation should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="ChangePasswordRequest"/>.</returns>
public ChangePasswordRequest Create(
string? username = null,
string? currentPassword = null,
string? newPassword = null,
string? newPasswordConfirm = null)
string? newPasswordConfirm = null,
bool includeUsername = true,
bool includeCurrentPassword = true,
bool includeNewPassword = true,
bool includeNewPasswordConfirm = true)
{
string generatedNewPassword = newPassword ?? _faker.Internet.Password();
return new ChangePasswordRequest(
username ?? _faker.Internet.UserName(),
currentPassword ?? _faker.Internet.Password(),
generatedNewPassword,
newPasswordConfirm ?? generatedNewPassword
includeUsername ? (username ?? _faker.Internet.UserName()) : null,
includeCurrentPassword ? (currentPassword ?? _faker.Internet.Password()) : null,
includeNewPassword ? generatedNewPassword : null,
includeNewPasswordConfirm ? (newPasswordConfirm ?? generatedNewPassword) : null
);
}
@@ -22,16 +22,22 @@ public class LoginRequestFixture
/// <param name="username">Optional. The username for login.</param>
/// <param name="password">Optional. The password for login.</param>
/// <param name="totpCode">Optional. The TOTP code for two-factor authentication.</param>
/// <param name="includeUsername">Whether the username should be included, or forced to <see langword="null"/>.</param>
/// <param name="includePassword">Whether the password should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeTotpCode">Whether the TOTP code should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="LoginRequest"/>.</returns>
public LoginRequest Create(
string? username = null,
string? password = null,
string? totpCode = null)
string? totpCode = null,
bool includeUsername = true,
bool includePassword = true,
bool includeTotpCode = true)
{
return new LoginRequest(
username ?? _faker.Internet.UserName(),
password ?? _faker.Internet.Password(),
totpCode ?? _faker.Random.Number(100000, 999999).ToString()
includeUsername ? (username ?? _faker.Internet.UserName()) : null,
includePassword ? (password ?? _faker.Internet.Password()) : null,
includeTotpCode ? (totpCode ?? _faker.Random.Number(100000, 999999).ToString()) : null
);
}
@@ -21,14 +21,18 @@ public class RecoverPasswordRequestFixture
/// </summary>
/// <param name="username">Optional. The username for password recovery.</param>
/// <param name="totpCode">Optional. The TOTP code for verification.</param>
/// <param name="includeUsername">Whether the username should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeTotpCode">Whether the TOTP code should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="RecoverPasswordRequest"/>.</returns>
public RecoverPasswordRequest Create(
string? username = null,
string? totpCode = null)
string? totpCode = null,
bool includeUsername = true,
bool includeTotpCode = true)
{
return new RecoverPasswordRequest(
username ?? _faker.Internet.UserName(),
totpCode ?? _faker.Random.Number(100000, 999999).ToString()
includeUsername ? (username ?? _faker.Internet.UserName()) : null,
includeTotpCode ? (totpCode ?? _faker.Random.Number(100000, 999999).ToString()) : null
);
}
@@ -23,18 +23,24 @@ public class RegistrationRequestFixture
/// <param name="password">Optional. The password for registration.</param>
/// <param name="passwordConfirm">Optional. The password confirmation.</param>
/// <param name="use2fa">Optional. Whether to use two-factor authentication.</param>
/// <param name="includeUsername">Whether the username should be included, or forced to <see langword="null"/>.</param>
/// <param name="includePassword">Whether the password should be included, or forced to <see langword="null"/>.</param>
/// <param name="includePasswordConfirm">Whether the password confirmation should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="RegistrationRequest"/>.</returns>
public RegistrationRequest Create(
string? username = null,
string? password = null,
string? passwordConfirm = null,
bool? use2fa = null)
bool? use2fa = null,
bool includeUsername = true,
bool includePassword = true,
bool includePasswordConfirm = true)
{
string generatedPassword = password ?? _faker.Internet.Password();
return new RegistrationRequest(
username ?? _faker.Internet.UserName(),
generatedPassword,
passwordConfirm ?? generatedPassword,
includeUsername ? (username ?? _faker.Internet.UserName()) : null,
includePassword ? generatedPassword : null,
includePasswordConfirm ? (passwordConfirm ?? generatedPassword) : null,
use2fa ?? _faker.Random.Bool()
);
}