mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17:11:10 +00:00
Replaces the per fixture random generators with the shared random instance
This commit is contained in:
1 parent
ab4d596500
commit
5aa21c0c0a
9 files changed
+31
-39
No files matched your search
+5
-6
@@ -18,7 +18,6 @@ namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Wr
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class BookEntityFixture
|
public class BookEntityFixture
|
||||||
{
|
{
|
||||||
private readonly Random _random = new();
|
|
||||||
private readonly Faker _faker = new();
|
private readonly Faker _faker = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -39,8 +38,8 @@ public class BookEntityFixture
|
|||||||
string? originalTitle = null,
|
string? originalTitle = null,
|
||||||
bool includeMetadata = true)
|
bool includeMetadata = true)
|
||||||
{
|
{
|
||||||
int releaseYear = _random.Next(2000, 2010);
|
int releaseYear = Random.Shared.Next(2000, 2010);
|
||||||
int reReleaseYear = _random.Next(2010, 2020);
|
int reReleaseYear = Random.Shared.Next(2010, 2020);
|
||||||
|
|
||||||
return new Faker<BookEntity>()
|
return new Faker<BookEntity>()
|
||||||
.RuleFor(x => x.Id, f => id ?? f.Random.Guid())
|
.RuleFor(x => x.Id, f => id ?? f.Random.Guid())
|
||||||
@@ -64,12 +63,12 @@ public class BookEntityFixture
|
|||||||
.RuleFor(x => x.Tags, f => includeMetadata ? [.. CreateTags(f.Random.Number(1, 5))] : [])
|
.RuleFor(x => x.Tags, f => includeMetadata ? [.. CreateTags(f.Random.Number(1, 5))] : [])
|
||||||
.RuleFor(x => x.Genres, f => includeMetadata ? [.. CreateGenres(f.Random.Number(1, 5))] : [])
|
.RuleFor(x => x.Genres, f => includeMetadata ? [.. CreateGenres(f.Random.Number(1, 5))] : [])
|
||||||
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
|
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
|
||||||
.RuleFor(x => x.PageCount, _random.Next(100, 300))
|
.RuleFor(x => x.PageCount, Random.Shared.Next(100, 300))
|
||||||
.RuleFor(x => x.Format, f => f.PickRandom<BookFormat>())
|
.RuleFor(x => x.Format, f => f.PickRandom<BookFormat>())
|
||||||
.RuleFor(x => x.Edition, f => f.Random.String2(f.Random.Number(1, 50)))
|
.RuleFor(x => x.Edition, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||||
.RuleFor(x => x.VolumeNumber, _random.Next(1, 3))
|
.RuleFor(x => x.VolumeNumber, Random.Shared.Next(1, 3))
|
||||||
.RuleFor(x => x.ASIN, f => f.Random.String2(10))
|
.RuleFor(x => x.ASIN, f => f.Random.String2(10))
|
||||||
.RuleFor(x => x.GoodreadsId, _random.Next(100000, 500000).ToString())
|
.RuleFor(x => x.GoodreadsId, Random.Shared.Next(100000, 500000).ToString())
|
||||||
.RuleFor(x => x.LCCN, CreateLCCN)
|
.RuleFor(x => x.LCCN, CreateLCCN)
|
||||||
.RuleFor(x => x.OCLCNumber, CreateOCLCNumber)
|
.RuleFor(x => x.OCLCNumber, CreateOCLCNumber)
|
||||||
.RuleFor(x => x.OpenLibraryId, CreateOpenLibraryId)
|
.RuleFor(x => x.OpenLibraryId, CreateOpenLibraryId)
|
||||||
|
|||||||
+2
-3
@@ -16,7 +16,6 @@ namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Wr
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class BookRatingEntityFixture
|
public class BookRatingEntityFixture
|
||||||
{
|
{
|
||||||
private readonly Random _random = new();
|
|
||||||
private readonly Faker _faker = new();
|
private readonly Faker _faker = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -36,10 +35,10 @@ public class BookRatingEntityFixture
|
|||||||
bool includeValues = true)
|
bool includeValues = true)
|
||||||
{
|
{
|
||||||
return new BookRatingEntity(
|
return new BookRatingEntity(
|
||||||
includeValues ? (value ?? _random.Next(1, 5)) : null,
|
includeValues ? (value ?? Random.Shared.Next(1, 5)) : null,
|
||||||
includeValues ? (maxValue ?? 5) : null,
|
includeValues ? (maxValue ?? 5) : null,
|
||||||
includeValues ? (source ?? _faker.PickRandom<BookRatingSource>()) : null,
|
includeValues ? (source ?? _faker.PickRandom<BookRatingSource>()) : null,
|
||||||
includeValues ? (voteCount ?? _random.Next(1, 1000)) : null
|
includeValues ? (voteCount ?? Random.Shared.Next(1, 1000)) : null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-6
@@ -15,7 +15,6 @@ namespace Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class IsbnDtoFixture
|
public class IsbnDtoFixture
|
||||||
{
|
{
|
||||||
private readonly Random _random = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an <see cref="IsbnDto"/> with a random or explicitly requested format.
|
/// Creates an <see cref="IsbnDto"/> with a random or explicitly requested format.
|
||||||
@@ -50,7 +49,7 @@ public class IsbnDtoFixture
|
|||||||
{
|
{
|
||||||
int[] digits = new int[9];
|
int[] digits = new int[9];
|
||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++)
|
||||||
digits[i] = _random.Next(0, 10);
|
digits[i] = Random.Shared.Next(0, 10);
|
||||||
|
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++)
|
||||||
@@ -68,10 +67,10 @@ public class IsbnDtoFixture
|
|||||||
/// <returns>A valid ISBN-13 value.</returns>
|
/// <returns>A valid ISBN-13 value.</returns>
|
||||||
private string GenerateValidIsbn13()
|
private string GenerateValidIsbn13()
|
||||||
{
|
{
|
||||||
string prefix = _random.Next(2) == 0 ? "978" : "979";
|
string prefix = Random.Shared.Next(2) == 0 ? "978" : "979";
|
||||||
string group = _random.Next(0, 99999).ToString().PadLeft(5, '0');
|
string group = Random.Shared.Next(0, 99999).ToString().PadLeft(5, '0');
|
||||||
string publisher = _random.Next(0, 999999).ToString().PadLeft(6, '0');
|
string publisher = Random.Shared.Next(0, 999999).ToString().PadLeft(6, '0');
|
||||||
string title = _random.Next(0, 99).ToString().PadLeft(2, '0');
|
string title = Random.Shared.Next(0, 99).ToString().PadLeft(2, '0');
|
||||||
|
|
||||||
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
|
|||||||
+2
-3
@@ -18,7 +18,6 @@ namespace Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
|
|||||||
public class ReleaseInfoFixture
|
public class ReleaseInfoFixture
|
||||||
{
|
{
|
||||||
private readonly Faker _faker = new();
|
private readonly Faker _faker = new();
|
||||||
private readonly Random _random = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a random valid <see cref="ReleaseInfo"/>.
|
/// Creates a random valid <see cref="ReleaseInfo"/>.
|
||||||
@@ -57,7 +56,7 @@ public class ReleaseInfoFixture
|
|||||||
lowerBound = Math.Min(lowerBound, resolvedReReleaseYear.Value);
|
lowerBound = Math.Min(lowerBound, resolvedReReleaseYear.Value);
|
||||||
upperBoundExclusive = Math.Min(upperBoundExclusive, resolvedReReleaseYear.Value + 1);
|
upperBoundExclusive = Math.Min(upperBoundExclusive, resolvedReReleaseYear.Value + 1);
|
||||||
}
|
}
|
||||||
int generatedYear = _random.Next(lowerBound, Math.Max(upperBoundExclusive, lowerBound + 1));
|
int generatedYear = Random.Shared.Next(lowerBound, Math.Max(upperBoundExclusive, lowerBound + 1));
|
||||||
resolvedOriginalDate = Optional<DateOnly>.Some(new DateOnly(generatedYear, 1, 1));
|
resolvedOriginalDate = Optional<DateOnly>.Some(new DateOnly(generatedYear, 1, 1));
|
||||||
resolvedOriginalYear = Optional<int>.Some(generatedYear);
|
resolvedOriginalYear = Optional<int>.Some(generatedYear);
|
||||||
}
|
}
|
||||||
@@ -66,7 +65,7 @@ public class ReleaseInfoFixture
|
|||||||
else if (!resolvedOriginalYear.HasValue)
|
else if (!resolvedOriginalYear.HasValue)
|
||||||
resolvedOriginalYear = Optional<int>.Some(resolvedOriginalDate.Value.Year);
|
resolvedOriginalYear = Optional<int>.Some(resolvedOriginalDate.Value.Year);
|
||||||
|
|
||||||
Optional<ReleaseCountry> resolvedReleaseCountry = releaseCountry ?? Optional<ReleaseCountry>.Some(Enum.GetValues<ReleaseCountry>()[_random.Next(Enum.GetValues<ReleaseCountry>().Length)]);
|
Optional<ReleaseCountry> resolvedReleaseCountry = releaseCountry ?? Optional<ReleaseCountry>.Some(Enum.GetValues<ReleaseCountry>()[Random.Shared.Next(Enum.GetValues<ReleaseCountry>().Length)]);
|
||||||
|
|
||||||
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
|
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
|
||||||
resolvedOriginalDate,
|
resolvedOriginalDate,
|
||||||
|
|||||||
+3
-4
@@ -17,7 +17,6 @@ namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBound
|
|||||||
public class BookRatingFixture
|
public class BookRatingFixture
|
||||||
{
|
{
|
||||||
private readonly Fixture _fixture = new();
|
private readonly Fixture _fixture = new();
|
||||||
private readonly Random _random = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a random valid <see cref="BookRating"/>.
|
/// Creates a random valid <see cref="BookRating"/>.
|
||||||
@@ -33,10 +32,10 @@ public class BookRatingFixture
|
|||||||
Optional<BookRatingSource>? source = null,
|
Optional<BookRatingSource>? source = null,
|
||||||
Optional<int>? voteCount = null)
|
Optional<int>? voteCount = null)
|
||||||
{
|
{
|
||||||
maxValue ??= _random.Next(5, 10);
|
maxValue ??= Random.Shared.Next(5, 10);
|
||||||
value ??= _random.Next(1, (int)maxValue.Value);
|
value ??= Random.Shared.Next(1, (int)maxValue.Value);
|
||||||
source ??= Optional<BookRatingSource>.Some(_fixture.Create<BookRatingSource>());
|
source ??= Optional<BookRatingSource>.Some(_fixture.Create<BookRatingSource>());
|
||||||
voteCount ??= Optional<int>.Some(_random.Next(1, 1000));
|
voteCount ??= Optional<int>.Some(Random.Shared.Next(1, 1000));
|
||||||
|
|
||||||
return BookRating.Create(value.Value, maxValue.Value, source.Value, voteCount.Value).Value;
|
return BookRating.Create(value.Value, maxValue.Value, source.Value, voteCount.Value).Value;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-7
@@ -15,7 +15,6 @@ namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBound
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class IsbnFixture
|
public class IsbnFixture
|
||||||
{
|
{
|
||||||
private readonly Random _random = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a valid <see cref="Isbn"/> with a random or explicitly requested format.
|
/// Creates a valid <see cref="Isbn"/> with a random or explicitly requested format.
|
||||||
@@ -34,7 +33,7 @@ public class IsbnFixture
|
|||||||
return result.Value;
|
return result.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
IsbnFormat requestedFormat = format ?? (_random.Next(2) == 0 ? IsbnFormat.Isbn10 : IsbnFormat.Isbn13);
|
IsbnFormat requestedFormat = format ?? (Random.Shared.Next(2) == 0 ? IsbnFormat.Isbn10 : IsbnFormat.Isbn13);
|
||||||
string isbn = requestedFormat == IsbnFormat.Isbn10 ? GenerateValidIsbn10() : GenerateValidIsbn13();
|
string isbn = requestedFormat == IsbnFormat.Isbn10 ? GenerateValidIsbn10() : GenerateValidIsbn13();
|
||||||
return Isbn.Create(isbn, requestedFormat).Value;
|
return Isbn.Create(isbn, requestedFormat).Value;
|
||||||
}
|
}
|
||||||
@@ -56,7 +55,7 @@ public class IsbnFixture
|
|||||||
{
|
{
|
||||||
int[] digits = new int[9];
|
int[] digits = new int[9];
|
||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++)
|
||||||
digits[i] = _random.Next(0, 10);
|
digits[i] = Random.Shared.Next(0, 10);
|
||||||
|
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++)
|
||||||
@@ -70,10 +69,10 @@ public class IsbnFixture
|
|||||||
|
|
||||||
private string GenerateValidIsbn13()
|
private string GenerateValidIsbn13()
|
||||||
{
|
{
|
||||||
string prefix = _random.Next(2) == 0 ? "978" : "979";
|
string prefix = Random.Shared.Next(2) == 0 ? "978" : "979";
|
||||||
string group = _random.Next(0, 99999).ToString().PadLeft(5, '0');
|
string group = Random.Shared.Next(0, 99999).ToString().PadLeft(5, '0');
|
||||||
string publisher = _random.Next(0, 999999).ToString().PadLeft(6, '0');
|
string publisher = Random.Shared.Next(0, 999999).ToString().PadLeft(6, '0');
|
||||||
string title = _random.Next(0, 99).ToString().PadLeft(2, '0');
|
string title = Random.Shared.Next(0, 99).ToString().PadLeft(2, '0');
|
||||||
|
|
||||||
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ public class QRCodeGeneratorFixture
|
|||||||
{
|
{
|
||||||
string username = new Faker().Person.UserName;
|
string username = new Faker().Person.UserName;
|
||||||
byte[] secret = new byte[20]; // Standard TOTP secret length
|
byte[] secret = new byte[20]; // Standard TOTP secret length
|
||||||
new Random().NextBytes(secret);
|
Random.Shared.NextBytes(secret);
|
||||||
return (username, secret);
|
return (username, secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -17,7 +17,6 @@ namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Common;
|
|||||||
public class ReleaseInfoDtoFixture
|
public class ReleaseInfoDtoFixture
|
||||||
{
|
{
|
||||||
private readonly Faker _faker = new();
|
private readonly Faker _faker = new();
|
||||||
private readonly Random _random = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="ReleaseInfoDto"/> instance with randomized test data.
|
/// Creates a new <see cref="ReleaseInfoDto"/> instance with randomized test data.
|
||||||
@@ -37,9 +36,9 @@ public class ReleaseInfoDtoFixture
|
|||||||
ReleaseCountry? releaseCountry = null,
|
ReleaseCountry? releaseCountry = null,
|
||||||
string? releaseVersion = null)
|
string? releaseVersion = null)
|
||||||
{
|
{
|
||||||
int resolvedOriginalReleaseYear = originalReleaseYear ?? (originalReleaseDate?.Year ?? _random.Next(1900, 2026));
|
int resolvedOriginalReleaseYear = originalReleaseYear ?? (originalReleaseDate?.Year ?? Random.Shared.Next(1900, 2026));
|
||||||
DateOnly resolvedOriginalReleaseDate = originalReleaseDate ?? new DateOnly(resolvedOriginalReleaseYear, 1, 1);
|
DateOnly resolvedOriginalReleaseDate = originalReleaseDate ?? new DateOnly(resolvedOriginalReleaseYear, 1, 1);
|
||||||
int resolvedReReleaseYear = reReleaseYear ?? (reReleaseDate?.Year ?? _random.Next(resolvedOriginalReleaseYear, resolvedOriginalReleaseYear + 100));
|
int resolvedReReleaseYear = reReleaseYear ?? (reReleaseDate?.Year ?? Random.Shared.Next(resolvedOriginalReleaseYear, resolvedOriginalReleaseYear + 100));
|
||||||
DateOnly resolvedReReleaseDate = reReleaseDate ?? new DateOnly(resolvedReReleaseYear, 1, 1);
|
DateOnly resolvedReReleaseDate = reReleaseDate ?? new DateOnly(resolvedReReleaseYear, 1, 1);
|
||||||
|
|
||||||
return new ReleaseInfoDto
|
return new ReleaseInfoDto
|
||||||
|
|||||||
+5
-6
@@ -15,7 +15,6 @@ namespace Lumina.Presentation.Web.Fixtures.Common.DTO.WrittenContentLibrary.Book
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class IsbnDtoFixture
|
public class IsbnDtoFixture
|
||||||
{
|
{
|
||||||
private readonly Random _random = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="IsbnDto"/> instance with a random or explicitly requested format.
|
/// Creates a new <see cref="IsbnDto"/> instance with a random or explicitly requested format.
|
||||||
@@ -51,7 +50,7 @@ public class IsbnDtoFixture
|
|||||||
{
|
{
|
||||||
int[] digits = new int[9];
|
int[] digits = new int[9];
|
||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++)
|
||||||
digits[i] = _random.Next(0, 10);
|
digits[i] = Random.Shared.Next(0, 10);
|
||||||
|
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++)
|
||||||
@@ -69,10 +68,10 @@ public class IsbnDtoFixture
|
|||||||
/// <returns>A valid ISBN-13 value.</returns>
|
/// <returns>A valid ISBN-13 value.</returns>
|
||||||
private string GenerateValidIsbn13()
|
private string GenerateValidIsbn13()
|
||||||
{
|
{
|
||||||
string prefix = _random.Next(2) == 0 ? "978" : "979";
|
string prefix = Random.Shared.Next(2) == 0 ? "978" : "979";
|
||||||
string group = _random.Next(0, 99999).ToString().PadLeft(5, '0');
|
string group = Random.Shared.Next(0, 99999).ToString().PadLeft(5, '0');
|
||||||
string publisher = _random.Next(0, 999999).ToString().PadLeft(6, '0');
|
string publisher = Random.Shared.Next(0, 999999).ToString().PadLeft(6, '0');
|
||||||
string title = _random.Next(0, 99).ToString().PadLeft(2, '0');
|
string title = Random.Shared.Next(0, 99).ToString().PadLeft(2, '0');
|
||||||
|
|
||||||
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
|
|||||||
Reference in new issue
Block a user