mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18: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
+50
@@ -0,0 +1,50 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.DTO.Common.Pagination;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.DTO.Common.Pagination;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PaginationDataDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PaginationDataDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="PaginationDataDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="currentPage">Optional. The current page number in a paginated collection.</param>
|
||||
/// <param name="perPage">Optional. The number of items to include per page in paginated results.</param>
|
||||
/// <param name="includeCurrentPage">Whether the current page should be included, or left at its default value.</param>
|
||||
/// <param name="includePerPage">Whether the per page count should be included, or left at its default value.</param>
|
||||
/// <returns>The created <see cref="PaginationDataDto"/>.</returns>
|
||||
public PaginationDataDto Create(
|
||||
int? currentPage = null,
|
||||
int? perPage = null,
|
||||
bool includeCurrentPage = true,
|
||||
bool includePerPage = true)
|
||||
{
|
||||
PaginationDataDto dto = new();
|
||||
if (includeCurrentPage)
|
||||
dto.CurrentPage = currentPage ?? _faker.Random.Int(1, 100);
|
||||
if (includePerPage)
|
||||
dto.PerPage = perPage ?? _faker.Random.Int(1, 200);
|
||||
return dto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="PaginationDataDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="PaginationDataDto"/> instances.</returns>
|
||||
public List<PaginationDataDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -16,6 +16,7 @@ namespace Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
|
||||
public class MediaContributorDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaContributorNameDtoFixture _mediaContributorNameDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="MediaContributorDto"/>.
|
||||
@@ -38,9 +39,12 @@ public class MediaContributorDtoFixture
|
||||
bool includeRole = true)
|
||||
{
|
||||
return new MediaContributorDto(
|
||||
Name: includeName ? new MediaContributorNameDto(
|
||||
DisplayName: includeDisplayName ? displayName ?? _faker.Name.FullName() : null,
|
||||
LegalName: includeLegalName ? legalName : null) : null,
|
||||
Name: includeName ? _mediaContributorNameDtoFixture.Create(
|
||||
displayName: displayName,
|
||||
legalName: legalName,
|
||||
includeDisplayName: includeDisplayName,
|
||||
// this fixture historically left the legal name null unless one was explicitly supplied, so the name fixture is only asked for one when a value is passed
|
||||
includeLegalName: includeLegalName && legalName is not null) : null,
|
||||
Role: includeRole ? role ?? _faker.PickRandom<MediaContributorRole>() : null);
|
||||
}
|
||||
|
||||
|
||||
+7
-3
@@ -21,14 +21,18 @@ public class MediaContributorNameDtoFixture
|
||||
/// </summary>
|
||||
/// <param name="displayName">Optional. The display name of the media contributor.</param>
|
||||
/// <param name="legalName">Optional. The legal name of the media contributor.</param>
|
||||
/// <param name="includeDisplayName">Whether the display name should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeLegalName">Whether the legal name should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="MediaContributorNameDto"/>.</returns>
|
||||
public MediaContributorNameDto Create(
|
||||
string? displayName = null,
|
||||
string? legalName = null)
|
||||
string? legalName = null,
|
||||
bool includeDisplayName = true,
|
||||
bool includeLegalName = true)
|
||||
{
|
||||
return new MediaContributorNameDto(
|
||||
displayName ?? _faker.Name.FullName(),
|
||||
legalName ?? _faker.Name.FullName());
|
||||
includeDisplayName ? displayName ?? _faker.Name.FullName() : null,
|
||||
includeLegalName ? legalName ?? _faker.Name.FullName() : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user