mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Centralizes and standardizes test fixtures.
This commit is contained in:
1 parent
dfc513da4f
commit
b648e2f054
294 files changed
+3807
-4437
No files matched your search
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="EncryptionSettingsDto"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class EncryptionSettingsDtoFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a valid <see cref="EncryptionSettingsDto"/> with a random 256-bit key.
|
||||
/// </summary>
|
||||
/// <param name="secretKey">Optional. The secret key. If not provided, a valid 256-bit (32 byte) key for AES-256 is generated.</param>
|
||||
/// <returns>The created <see cref="EncryptionSettingsDto"/>.</returns>
|
||||
public EncryptionSettingsDto Create(string? secretKey = null)
|
||||
{
|
||||
byte[] key = new byte[32];
|
||||
RandomNumberGenerator.Fill(key);
|
||||
|
||||
return new EncryptionSettingsDto
|
||||
{
|
||||
SecretKey = secretKey ?? Convert.ToBase64String(key)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="EncryptionSettingsDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="EncryptionSettingsDto"/> instances.</returns>
|
||||
public List<EncryptionSettingsDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="JwtSettingsDto"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class JwtSettingsDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid <see cref="JwtSettingsDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="secretKey">Optional. The secret key used to sign the JWT.</param>
|
||||
/// <param name="expiryMinutes">Optional. The duration (in minutes) for which the JWT is valid.</param>
|
||||
/// <param name="issuer">Optional. The issuer of the JWT.</param>
|
||||
/// <param name="audience">Optional. The intended audience for the JWT.</param>
|
||||
/// <returns>The created <see cref="JwtSettingsDto"/>.</returns>
|
||||
public JwtSettingsDto Create(
|
||||
string? secretKey = null,
|
||||
int? expiryMinutes = null,
|
||||
string? issuer = null,
|
||||
string? audience = null)
|
||||
{
|
||||
byte[] key = new byte[32];
|
||||
RandomNumberGenerator.Fill(key);
|
||||
|
||||
return new JwtSettingsDto
|
||||
{
|
||||
SecretKey = secretKey ?? Convert.ToBase64String(key),
|
||||
ExpiryMinutes = expiryMinutes ?? _faker.Random.Int(1, 120),
|
||||
Issuer = issuer ?? _faker.Company.CompanyName(),
|
||||
Audience = audience ?? _faker.Company.CompanyName()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="JwtSettingsDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="JwtSettingsDto"/> instances.</returns>
|
||||
public List<JwtSettingsDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user