mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 19:21:10 +00:00
Refactors the test fixtures and their consumers to compose other fixtures instead of instantiating models inline
This commit is contained in:
1 parent
0abda472c6
commit
3aadd6de84
157 files changed
+1312
-597
No files matched your search
+3
-2
@@ -19,8 +19,9 @@ public class RecoverPasswordCommandFixture
|
||||
/// </summary>
|
||||
/// <param name="username">Optional. The username.</param>
|
||||
/// <param name="totpCode">Optional. The TOTP code.</param>
|
||||
/// <param name="includeTotpCode">Whether the TOTP code should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created command.</returns>
|
||||
public RecoverPasswordCommand Create(string? username = null, string? totpCode = null)
|
||||
public RecoverPasswordCommand Create(string? username = null, string? totpCode = null, bool includeTotpCode = true)
|
||||
{
|
||||
return new Faker<RecoverPasswordCommand>()
|
||||
.CustomInstantiator(f => new RecoverPasswordCommand(
|
||||
@@ -28,7 +29,7 @@ public class RecoverPasswordCommandFixture
|
||||
default!
|
||||
))
|
||||
.RuleFor(x => x.Username, f => username ?? f.Person.UserName)
|
||||
.RuleFor(x => x.TotpCode, f => totpCode ?? f.Random.Replace("######"));
|
||||
.RuleFor(x => x.TotpCode, f => includeTotpCode ? (totpCode ?? f.Random.Replace("######")) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+6
-3
@@ -20,13 +20,16 @@ public class LoginUserQueryFixture
|
||||
/// <param name="username">Optional. The username.</param>
|
||||
/// <param name="password">Optional. The password.</param>
|
||||
/// <param name="includeTotpCode">Whether the TOTP code should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="totpCode">Optional. The TOTP code. When provided, the TOTP code is included even if <paramref name="includeTotpCode"/> is <see langword="false"/>.</param>
|
||||
/// <returns>The created query.</returns>
|
||||
public LoginUserQuery Create(
|
||||
string? username = null,
|
||||
string? password = null,
|
||||
bool includeTotpCode = false)
|
||||
bool includeTotpCode = false,
|
||||
string? totpCode = null)
|
||||
{
|
||||
string resolvedPassword = password ?? "Abcd123$";
|
||||
bool shouldIncludeTotpCode = includeTotpCode || totpCode is not null;
|
||||
Faker<LoginUserQuery> faker = new Faker<LoginUserQuery>()
|
||||
.CustomInstantiator(f => new LoginUserQuery(
|
||||
default!,
|
||||
@@ -36,8 +39,8 @@ public class LoginUserQueryFixture
|
||||
.RuleFor(x => x.Username, f => username ?? f.Person.UserName)
|
||||
.RuleFor(x => x.Password, resolvedPassword);
|
||||
|
||||
if (includeTotpCode)
|
||||
faker.RuleFor(x => x.TotpCode, f => f.Random.Replace("######")); // generates 6 random digits
|
||||
if (shouldIncludeTotpCode)
|
||||
faker.RuleFor(x => x.TotpCode, f => totpCode ?? f.Random.Replace("######")); // generates 6 random digits when no code is pinned
|
||||
return faker.Generate();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user