mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21: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
+3
-4
@@ -17,7 +17,6 @@ namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBound
|
||||
public class BookRatingFixture
|
||||
{
|
||||
private readonly Fixture _fixture = new();
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="BookRating"/>.
|
||||
@@ -33,10 +32,10 @@ public class BookRatingFixture
|
||||
Optional<BookRatingSource>? source = null,
|
||||
Optional<int>? voteCount = null)
|
||||
{
|
||||
maxValue ??= _random.Next(5, 10);
|
||||
value ??= _random.Next(1, (int)maxValue.Value);
|
||||
maxValue ??= Random.Shared.Next(5, 10);
|
||||
value ??= Random.Shared.Next(1, (int)maxValue.Value);
|
||||
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;
|
||||
}
|
||||
|
||||
+6
-7
@@ -15,7 +15,6 @@ namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBound
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnFixture
|
||||
{
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid <see cref="Isbn"/> with a random or explicitly requested format.
|
||||
@@ -34,7 +33,7 @@ public class IsbnFixture
|
||||
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();
|
||||
return Isbn.Create(isbn, requestedFormat).Value;
|
||||
}
|
||||
@@ -56,7 +55,7 @@ public class IsbnFixture
|
||||
{
|
||||
int[] digits = new int[9];
|
||||
for (int i = 0; i < 9; i++)
|
||||
digits[i] = _random.Next(0, 10);
|
||||
digits[i] = Random.Shared.Next(0, 10);
|
||||
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
@@ -70,10 +69,10 @@ public class IsbnFixture
|
||||
|
||||
private string GenerateValidIsbn13()
|
||||
{
|
||||
string prefix = _random.Next(2) == 0 ? "978" : "979";
|
||||
string group = _random.Next(0, 99999).ToString().PadLeft(5, '0');
|
||||
string publisher = _random.Next(0, 999999).ToString().PadLeft(6, '0');
|
||||
string title = _random.Next(0, 99).ToString().PadLeft(2, '0');
|
||||
string prefix = Random.Shared.Next(2) == 0 ? "978" : "979";
|
||||
string group = Random.Shared.Next(0, 99999).ToString().PadLeft(5, '0');
|
||||
string publisher = Random.Shared.Next(0, 999999).ToString().PadLeft(6, '0');
|
||||
string title = Random.Shared.Next(0, 99).ToString().PadLeft(2, '0');
|
||||
|
||||
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
||||
int sum = 0;
|
||||
|
||||
Reference in new issue
Block a user