mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Adds test fixtures and endpoint test coverage
This commit is contained in:
1 parent
c82fadc7a2
commit
7aeed04255
198 files changed
+11649
No files matched your search
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DTO.Filtering;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BaseFilterDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BaseFilterDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="BaseFilterDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="searchTerm">Optional. The search term used to filter results.</param>
|
||||
/// <returns>The created <see cref="BaseFilterDto"/>.</returns>
|
||||
public BaseFilterDto Create(string? searchTerm = null)
|
||||
{
|
||||
return new BaseFilterDto
|
||||
{
|
||||
SearchTerm = searchTerm ?? _faker.Lorem.Sentence()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="BaseFilterDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<BaseFilterDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DTO.Filtering;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="LibraryFilterDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryFilterDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="LibraryFilterDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">Optional. The Id of the media library used to filter data.</param>
|
||||
/// <param name="searchTerm">Optional. The search term used to filter results.</param>
|
||||
/// <param name="filterAlphaKey">Optional. The alpha key used to filter by the first character of the item title.</param>
|
||||
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether the leading "The " prefix should be ignored when computing the alpha key, or not.</param>
|
||||
/// <returns>The created <see cref="LibraryFilterDto"/>.</returns>
|
||||
public LibraryFilterDto Create(
|
||||
Guid? libraryId = null,
|
||||
string? searchTerm = null,
|
||||
string? filterAlphaKey = null,
|
||||
bool shouldIgnoreThePrefixForAlphaPicker = false)
|
||||
{
|
||||
return new LibraryFilterDto
|
||||
{
|
||||
LibraryId = libraryId ?? _faker.Random.Guid(),
|
||||
SearchTerm = searchTerm,
|
||||
FilterAlphaKey = filterAlphaKey,
|
||||
ShouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="LibraryFilterDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="LibraryFilterDto"/> instances.</returns>
|
||||
public List<LibraryFilterDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DTO.Pagination;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PaginatedResultDto{TData}"/> record.
|
||||
/// </summary>
|
||||
/// <typeparam name="TData">The type of the data items contained in the paginated result.</typeparam>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PaginatedResultDtoFixture<TData>
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="PaginatedResultDto{TData}"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">Optional. The collection of data items.</param>
|
||||
/// <param name="currentPage">Optional. The current page number.</param>
|
||||
/// <param name="perPage">Optional. The number of items per page.</param>
|
||||
/// <param name="count">Optional. The total number of elements available.</param>
|
||||
/// <param name="numberOfPages">Optional. The total number of pages.</param>
|
||||
/// <returns>The created <see cref="PaginatedResultDto{TData}"/>.</returns>
|
||||
public PaginatedResultDto<TData> Create(
|
||||
IReadOnlyList<TData>? data = null,
|
||||
int? currentPage = null,
|
||||
int? perPage = null,
|
||||
int? count = null,
|
||||
int? numberOfPages = null)
|
||||
{
|
||||
return new PaginatedResultDto<TData>
|
||||
{
|
||||
Data = data ?? [],
|
||||
CurrentPage = currentPage ?? _faker.Random.Int(1, 10),
|
||||
PerPage = perPage ?? _faker.Random.Int(1, 100),
|
||||
Count = count ?? _faker.Random.Int(0, 1000),
|
||||
NumberOfPages = numberOfPages ?? _faker.Random.Int(1, 100)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="PaginatedResultDto{TData}"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="PaginatedResultDto{TData}"/> instances.</returns>
|
||||
public List<PaginatedResultDto<TData>> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DTO.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>
|
||||
/// <returns>The created <see cref="PaginationDataDto"/>.</returns>
|
||||
public PaginationDataDto Create(
|
||||
int? currentPage = null,
|
||||
int? perPage = null)
|
||||
{
|
||||
return new PaginationDataDto
|
||||
{
|
||||
CurrentPage = currentPage ?? _faker.Random.Int(1, 100),
|
||||
PerPage = perPage ?? _faker.Random.Int(1, 200)
|
||||
};
|
||||
}
|
||||
|
||||
/// <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())];
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="RoleEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RoleEntityFixture
|
||||
{
|
||||
private readonly RolePermissionEntityFixture _rolePermissionEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="RoleEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the role.</param>
|
||||
/// <param name="roleName">Optional. The name of the role.</param>
|
||||
/// <param name="rolePermissions">Optional. The role permission associations of the role.</param>
|
||||
/// <param name="includeRolePermissions">Whether the role should include role permission associations or not.</param>
|
||||
/// <param name="createdBy">Optional. The Id of the user that created the role.</param>
|
||||
/// <param name="createdOnUtc">Optional. The time and date when the role was added.</param>
|
||||
/// <returns>The created <see cref="RoleEntity"/>.</returns>
|
||||
public RoleEntity Create(
|
||||
Guid? id = null,
|
||||
string? roleName = null,
|
||||
IEnumerable<RolePermissionEntity>? rolePermissions = null,
|
||||
bool includeRolePermissions = false,
|
||||
Guid? createdBy = null,
|
||||
DateTime? createdOnUtc = null)
|
||||
{
|
||||
return new Faker<RoleEntity>()
|
||||
.CustomInstantiator(faker => new RoleEntity
|
||||
{
|
||||
Id = id ?? faker.Random.Guid(),
|
||||
RoleName = roleName ?? faker.Random.String2(faker.Random.Number(1, 50)),
|
||||
RolePermissions = includeRolePermissions ? (rolePermissions ?? _rolePermissionEntityFixture.CreateMany()).ToList() : [],
|
||||
CreatedOnUtc = createdOnUtc ?? faker.Date.Past(),
|
||||
CreatedBy = createdBy ?? faker.Random.Guid(),
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="RoleEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="RoleEntity"/> instances.</returns>
|
||||
public List<RoleEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GenreEntity"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GenreEntityFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="GenreEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">Optional. The name of the genre.</param>
|
||||
/// <param name="includeName">Whether the name should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="GenreEntity"/>.</returns>
|
||||
public GenreEntity Create(
|
||||
string? name = null,
|
||||
bool includeName = true)
|
||||
{
|
||||
return new GenreEntity(includeName ? name ?? _faker.Lorem.Word() : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="GenreEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<GenreEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="TagEntity"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TagEntityFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="TagEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">Optional. The name of the tag.</param>
|
||||
/// <param name="includeName">Whether the name should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="TagEntity"/>.</returns>
|
||||
public TagEntity Create(
|
||||
string? name = null,
|
||||
bool includeName = true)
|
||||
{
|
||||
return new TagEntity(includeName ? name ?? _faker.Lorem.Word() : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="TagEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<TagEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="IsbnEntity"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnEntityFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="IsbnEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Optional. The ISBN value.</param>
|
||||
/// <param name="format">Optional. The format of the ISBN.</param>
|
||||
/// <param name="includeValue">Whether the value should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="IsbnEntity"/>.</returns>
|
||||
public IsbnEntity Create(
|
||||
string? value = null,
|
||||
IsbnFormat? format = null,
|
||||
bool includeValue = true)
|
||||
{
|
||||
return new IsbnEntity(
|
||||
includeValue ? value ?? _faker.Random.String2(13, "0123456789") : null,
|
||||
format);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="IsbnEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<IsbnEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ThemeArchiveDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeArchiveDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ThemeArchiveDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="bytes">Optional. The bytes of the ZIP archive.</param>
|
||||
/// <param name="fileName">Optional. The file name to expose when downloading the archive.</param>
|
||||
/// <param name="contentType">Optional. The MIME content type of the archive.</param>
|
||||
/// <returns>The created <see cref="ThemeArchiveDto"/>.</returns>
|
||||
public ThemeArchiveDto Create(
|
||||
byte[]? bytes = null,
|
||||
string? fileName = null,
|
||||
string? contentType = null)
|
||||
{
|
||||
return new ThemeArchiveDto(
|
||||
bytes ?? _faker.Random.Bytes(10),
|
||||
fileName ?? _faker.System.FileName(),
|
||||
contentType ?? _faker.System.MimeType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ThemeArchiveDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<ThemeArchiveDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ThemeAssetDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeAssetDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ThemeAssetDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="bytes">Optional. The bytes of the asset file.</param>
|
||||
/// <param name="contentType">Optional. The MIME content type of the asset file.</param>
|
||||
/// <returns>The created <see cref="ThemeAssetDto"/>.</returns>
|
||||
public ThemeAssetDto Create(
|
||||
byte[]? bytes = null,
|
||||
string? contentType = null)
|
||||
{
|
||||
return new ThemeAssetDto(
|
||||
bytes ?? _faker.Random.Bytes(10),
|
||||
contentType ?? _faker.System.MimeType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ThemeAssetDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<ThemeAssetDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user