mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Hardens test assertions and adds missing test coverage.
This commit is contained in:
1 parent
6b86fd5805
commit
1189bbaf36
489 files changed
+39982
-512
No files matched your search
+52
@@ -0,0 +1,52 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="DirectoryScanFingerprintEntity"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DirectoryScanFingerprintEntityFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DirectoryScanFingerprintEntity"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the directory scan fingerprint.</param>
|
||||
/// <param name="libraryId">Optional. The Id of the media library to which the fingerprint belongs.</param>
|
||||
/// <param name="path">Optional path of the directory to which the fingerprint belongs.</param>
|
||||
/// <param name="lastWriteTimeUtc">Optional last write time of the directory, in UTC.</param>
|
||||
/// <returns>A configured <see cref="DirectoryScanFingerprintEntity"/> instance.</returns>
|
||||
public DirectoryScanFingerprintEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? libraryId = null,
|
||||
string? path = null,
|
||||
DateTime? lastWriteTimeUtc = null)
|
||||
{
|
||||
return new Faker<DirectoryScanFingerprintEntity>()
|
||||
.CustomInstantiator(faker => new DirectoryScanFingerprintEntity
|
||||
{
|
||||
Id = id ?? Guid.NewGuid(),
|
||||
LibraryId = libraryId ?? Guid.NewGuid(),
|
||||
Path = path ?? faker.System.DirectoryPath(),
|
||||
LastWriteTimeUtc = lastWriteTimeUtc ?? faker.Date.Recent()
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="DirectoryScanFingerprintEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="DirectoryScanFingerprintEntity"/> instances.</returns>
|
||||
public List<DirectoryScanFingerprintEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="LibraryEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryEntityFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="LibraryEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the media library.</param>
|
||||
/// <param name="userId">Optional. The Id of the user that owns the media library.</param>
|
||||
/// <param name="title">Optional. The title of the media library.</param>
|
||||
/// <param name="libraryType">Optional. The type of the media library.</param>
|
||||
/// <param name="contentLocations">Optional. The content locations of the media library.</param>
|
||||
/// <param name="coverImage">Optional. The cover image path of the media library.</param>
|
||||
/// <param name="isEnabled">Whether the media library is enabled or not.</param>
|
||||
/// <param name="isLocked">Whether the media library is locked or not.</param>
|
||||
/// <param name="downloadMetadataFromWeb">Whether the media library should download metadata from the web or not.</param>
|
||||
/// <param name="shouldSaveMetadataInMediaDirectories">Whether the metadata should be saved in the media directories or not.</param>
|
||||
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Whether unchanged directories should be skipped during a scan or not.</param>
|
||||
/// <returns>The created media library entity.</returns>
|
||||
public LibraryEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? userId = null,
|
||||
string? title = null,
|
||||
LibraryType? libraryType = null,
|
||||
IEnumerable<string>? contentLocations = null,
|
||||
string? coverImage = null,
|
||||
bool isEnabled = true,
|
||||
bool isLocked = false,
|
||||
bool downloadMetadataFromWeb = true,
|
||||
bool shouldSaveMetadataInMediaDirectories = true,
|
||||
bool shouldSkipUnchangedDirectoriesDuringScan = false)
|
||||
{
|
||||
return new Faker<LibraryEntity>()
|
||||
.CustomInstantiator(f => new LibraryEntity
|
||||
{
|
||||
Id = id ?? Guid.NewGuid(),
|
||||
UserId = userId ?? Guid.NewGuid(),
|
||||
Title = default!,
|
||||
CoverImage = default,
|
||||
LibraryType = default,
|
||||
ContentLocations = [],
|
||||
LibraryScans = [],
|
||||
IsEnabled = isEnabled,
|
||||
IsLocked = isLocked,
|
||||
DownloadMetadataFromWeb = downloadMetadataFromWeb,
|
||||
ShouldSaveMetadataInMediaDirectories = shouldSaveMetadataInMediaDirectories,
|
||||
ShouldSkipUnchangedDirectoriesDuringScan = shouldSkipUnchangedDirectoriesDuringScan,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
})
|
||||
.RuleFor(library => library.Title, f => title ?? f.Lorem.Word())
|
||||
.RuleFor(library => library.LibraryType, f => libraryType ?? f.PickRandom<LibraryType>())
|
||||
.RuleFor(library => library.CoverImage, f => coverImage ?? f.System.FilePath())
|
||||
.RuleFor(library => library.ContentLocations, f =>
|
||||
{
|
||||
IEnumerable<string> paths = contentLocations ?? [f.System.DirectoryPath(), f.System.DirectoryPath()];
|
||||
return [.. paths.Select(path => new LibraryContentLocationEntity() { Path = path })];
|
||||
})
|
||||
.RuleFor(library => library.CreatedOnUtc, f => f.Date.Past())
|
||||
.RuleFor(library => library.CreatedBy, f => f.Random.Guid())
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="LibraryEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="LibraryEntity"/> instances.</returns>
|
||||
public List<LibraryEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="LibraryScanEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryScanEntityFixture
|
||||
{
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="LibraryScanEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the media library scan.</param>
|
||||
/// <param name="libraryId">Optional. The Id of the media library that is scanned.</param>
|
||||
/// <param name="userId">Optional. The Id of the user that initiated the media library scan.</param>
|
||||
/// <param name="status">The status of the media library scan.</param>
|
||||
/// <param name="libraryEntity">Optional. The media library that is scanned.</param>
|
||||
/// <param name="createdOnUtc">Optional. The time and date when the entity was added.</param>
|
||||
/// <returns>The created media library scan entity.</returns>
|
||||
public LibraryScanEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? libraryId = null,
|
||||
Guid? userId = null,
|
||||
LibraryScanJobStatus? status = null,
|
||||
LibraryEntity? libraryEntity = null,
|
||||
DateTime? createdOnUtc = null)
|
||||
{
|
||||
Guid resolvedLibraryId = libraryId ?? Guid.NewGuid();
|
||||
Guid resolvedUserId = userId ?? Guid.NewGuid();
|
||||
LibraryEntity resolvedLibrary = libraryEntity ?? _libraryEntityFixture.Create(id: resolvedLibraryId, userId: resolvedUserId);
|
||||
|
||||
return new Faker<LibraryScanEntity>()
|
||||
.CustomInstantiator(f => new LibraryScanEntity
|
||||
{
|
||||
Id = id ?? Guid.NewGuid(),
|
||||
LibraryId = resolvedLibraryId,
|
||||
UserId = resolvedUserId,
|
||||
Status = status ?? LibraryScanJobStatus.Running,
|
||||
Library = resolvedLibrary,
|
||||
User = null!,
|
||||
LibraryScanResults = [],
|
||||
CreatedOnUtc = createdOnUtc ?? f.Date.Past(),
|
||||
CreatedBy = resolvedUserId,
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="LibraryScanEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="LibraryScanEntity"/> instances.</returns>
|
||||
public List<LibraryScanEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="LibraryScanResultEntity"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryScanResultEntityFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="LibraryScanResultEntity"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the media library scan result.</param>
|
||||
/// <param name="libraryScanId">Optional. The Id of the media library scan that this result belongs to.</param>
|
||||
/// <param name="status">Optional status of the media library scan file.</param>
|
||||
/// <param name="path">Optional path of the media library scan file.</param>
|
||||
/// <param name="contentHash">Optional hash calculated for the media library scan file.</param>
|
||||
/// <param name="fileSize">Optional size of the media library scan file.</param>
|
||||
/// <param name="ticks">Optional last write time of the media library scan file, stored in ticks.</param>
|
||||
/// <returns>A configured <see cref="LibraryScanResultEntity"/> instance.</returns>
|
||||
public LibraryScanResultEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? libraryScanId = null,
|
||||
LibraryScanFileStatus? status = null,
|
||||
string? path = null,
|
||||
ulong? contentHash = null,
|
||||
long? fileSize = null,
|
||||
long? ticks = null)
|
||||
{
|
||||
return new Faker<LibraryScanResultEntity>()
|
||||
.CustomInstantiator(faker => new LibraryScanResultEntity
|
||||
{
|
||||
Id = id ?? Guid.NewGuid(),
|
||||
LibraryScanId = libraryScanId ?? Guid.NewGuid(),
|
||||
Status = status ?? faker.PickRandom<LibraryScanFileStatus>(),
|
||||
Path = path ?? faker.System.FilePath(),
|
||||
ContentHash = contentHash ?? faker.Random.ULong(),
|
||||
FileSize = fileSize ?? faker.Random.Long(1, long.MaxValue),
|
||||
Ticks = ticks ?? faker.Random.Long(0, long.MaxValue),
|
||||
LibraryScan = null!
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="LibraryScanResultEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="LibraryScanResultEntity"/> instances.</returns>
|
||||
public List<LibraryScanResultEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="LibraryScanSnapshotEntity"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryScanSnapshotEntityFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="LibraryScanSnapshotEntity"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the media library scan snapshot item.</param>
|
||||
/// <param name="libraryId">Optional. The Id of the media library to which the snapshot item belongs.</param>
|
||||
/// <param name="path">Optional path of the media library scan snapshot item.</param>
|
||||
/// <param name="contentHash">Optional hash calculated for the media library scan snapshot item.</param>
|
||||
/// <param name="fileSize">Optional size of the media library scan snapshot item.</param>
|
||||
/// <param name="ticks">Optional last write time of the media library scan snapshot item, stored in ticks.</param>
|
||||
/// <returns>A configured <see cref="LibraryScanSnapshotEntity"/> instance.</returns>
|
||||
public LibraryScanSnapshotEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? libraryId = null,
|
||||
string? path = null,
|
||||
ulong? contentHash = null,
|
||||
long? fileSize = null,
|
||||
long? ticks = null)
|
||||
{
|
||||
return new Faker<LibraryScanSnapshotEntity>()
|
||||
.CustomInstantiator(faker => new LibraryScanSnapshotEntity
|
||||
{
|
||||
Id = id ?? Guid.NewGuid(),
|
||||
LibraryId = libraryId ?? Guid.NewGuid(),
|
||||
Path = path ?? faker.System.FilePath(),
|
||||
ContentHash = contentHash ?? faker.Random.ULong(),
|
||||
FileSize = fileSize ?? faker.Random.Long(1, long.MaxValue),
|
||||
Ticks = ticks ?? faker.Random.Long(0, long.MaxValue),
|
||||
Library = null!,
|
||||
CreatedOnUtc = faker.Date.Past(),
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedOnUtc = faker.Random.Bool() ? faker.Date.Recent() : null,
|
||||
UpdatedBy = faker.Random.Bool() ? Guid.NewGuid() : null
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="LibraryScanSnapshotEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="LibraryScanSnapshotEntity"/> instances.</returns>
|
||||
public List<LibraryScanSnapshotEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="LibraryScanStagingResultsEntity"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryScanStagingResultsEntityFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="LibraryScanStagingResultsEntity"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the media library scan staging result.</param>
|
||||
/// <param name="libraryScanId">Optional. The Id of the media library scan that this staging result belongs to.</param>
|
||||
/// <param name="path">Optional path of the media library scan staging result.</param>
|
||||
/// <param name="size">Optional size of the media library scan staging result.</param>
|
||||
/// <param name="ticks">Optional last write time of the file system item, stored in ticks.</param>
|
||||
/// <param name="contentHash">Optional hash calculated for the media library scan staging result.</param>
|
||||
/// <param name="previousContentHash">Optional hash stored in the media library scan snapshot of a previous scan.</param>
|
||||
/// <param name="needsRehash">Optional value indicating whether the file system item needs its content hashed.</param>
|
||||
/// <param name="isNew">Optional value indicating whether the file system item is new.</param>
|
||||
/// <returns>A configured <see cref="LibraryScanStagingResultsEntity"/> instance.</returns>
|
||||
public LibraryScanStagingResultsEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? libraryScanId = null,
|
||||
string? path = null,
|
||||
long? size = null,
|
||||
long? ticks = null,
|
||||
ulong? contentHash = null,
|
||||
ulong? previousContentHash = null,
|
||||
bool? needsRehash = null,
|
||||
bool? isNew = null)
|
||||
{
|
||||
return new Faker<LibraryScanStagingResultsEntity>()
|
||||
.CustomInstantiator(faker => new LibraryScanStagingResultsEntity
|
||||
{
|
||||
Id = id ?? Guid.NewGuid(),
|
||||
LibraryScanId = libraryScanId ?? Guid.NewGuid(),
|
||||
Path = path ?? faker.System.FilePath(),
|
||||
Size = size ?? faker.Random.Long(1, long.MaxValue),
|
||||
Ticks = ticks ?? faker.Random.Long(0, long.MaxValue),
|
||||
ContentHash = contentHash ?? faker.Random.ULong(),
|
||||
PreviousContentHash = previousContentHash ?? faker.Random.ULong(),
|
||||
NeedsRehash = needsRehash ?? faker.Random.Bool(),
|
||||
IsNew = isNew ?? faker.Random.Bool()
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="LibraryScanStagingResultsEntity"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="LibraryScanStagingResultsEntity"/> instances.</returns>
|
||||
public List<LibraryScanStagingResultsEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+16
-6
@@ -23,18 +23,28 @@ public class BookEntityFixture
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="BookEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the book.</param>
|
||||
/// <param name="libraryId">Optional. The Id of the media library that owns the book.</param>
|
||||
/// <param name="path">Optional. The file system path of the book.</param>
|
||||
/// <param name="title">Optional. The title of the book.</param>
|
||||
/// <param name="originalTitle">Optional. The original title of the book.</param>
|
||||
/// <returns>The created <see cref="BookEntity"/>.</returns>
|
||||
public BookEntity Create()
|
||||
public BookEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? libraryId = null,
|
||||
string? path = null,
|
||||
string? title = null,
|
||||
string? originalTitle = null)
|
||||
{
|
||||
int releaseYear = _random.Next(2000, 2010);
|
||||
int reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
return new Faker<BookEntity>()
|
||||
.RuleFor(x => x.Id, f => f.Random.Guid())
|
||||
.RuleFor(x => x.LibraryId, f => f.Random.Guid())
|
||||
.RuleFor(x => x.Path, f => f.System.FilePath())
|
||||
.RuleFor(x => x.Title, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.OriginalTitle, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.Id, f => id ?? f.Random.Guid())
|
||||
.RuleFor(x => x.LibraryId, f => libraryId ?? f.Random.Guid())
|
||||
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
|
||||
.RuleFor(x => x.Title, f => title ?? f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.OriginalTitle, f => originalTitle ?? f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.Description, f => f.Random.String2(f.Random.Number(1, 2000)))
|
||||
.RuleFor(x => x.OriginalReleaseDate, _faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)))
|
||||
.RuleFor(x => x.OriginalReleaseYear, releaseYear)
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.MediaLibraryScanJobPayloads;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.MediaLibraryScanJobPayloads;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="HashedFileSystemFileDto"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class HashedFileSystemFileDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="HashedFileSystemFileDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">Optional. The path of the file system file.</param>
|
||||
/// <param name="size">Optional. The size of the file system file.</param>
|
||||
/// <param name="currentHash">Optional. The current hash obtained by sampling the file system file contents.</param>
|
||||
/// <param name="oldHash">Optional. The old hash of the file system file, stored at the previous scan.</param>
|
||||
/// <param name="ticks">Optional. The time and date when the file system file was last modified, stored in ticks.</param>
|
||||
/// <returns>The created <see cref="HashedFileSystemFileDto"/>.</returns>
|
||||
public HashedFileSystemFileDto Create(
|
||||
string? path = null,
|
||||
long? size = null,
|
||||
ulong? currentHash = null,
|
||||
ulong? oldHash = null,
|
||||
long? ticks = null)
|
||||
{
|
||||
return new HashedFileSystemFileDto
|
||||
{
|
||||
Path = path ?? _faker.System.FilePath(),
|
||||
Size = size ?? _faker.Random.Long(1, 1_000_000),
|
||||
CurrentHash = currentHash ?? _faker.Random.ULong(),
|
||||
OldHash = oldHash ?? _faker.Random.ULong(),
|
||||
Ticks = ticks ?? _faker.Date.Recent().Ticks
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="HashedFileSystemFileDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="HashedFileSystemFileDto"/> instances.</returns>
|
||||
public List<HashedFileSystemFileDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration used to exercise the <see cref="Lumina.Application.Common.Utilities.ValidatorUtilities.IsInEnum{TRequest, TEnum}(FluentValidation.IRuleBuilder{TRequest, TEnum})"/> extension method.
|
||||
/// </summary>
|
||||
public enum ValidatorUtilitiesTestEnum
|
||||
{
|
||||
First,
|
||||
Second
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Request used to exercise the <see cref="Lumina.Application.Common.Utilities.ValidatorUtilities"/> extension methods.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed record ValidatorUtilitiesTestRequest(
|
||||
int IntValue,
|
||||
int? NullableIntValue,
|
||||
decimal DecimalValue,
|
||||
decimal? NullableDecimalValue,
|
||||
TimeSpan TimeSpanValue,
|
||||
int IntValue2,
|
||||
int? NullableIntValue2,
|
||||
decimal? NullableDecimalValue2,
|
||||
string? NotNullValue,
|
||||
string? NotEmptyValue,
|
||||
Guid NotEmptyGuidValue,
|
||||
List<string>? NotEmptyCollectionValue,
|
||||
ValidatorUtilitiesTestEnum EnumValue,
|
||||
ValidatorUtilitiesTestEnum? NullableEnumValue,
|
||||
string? MaxLengthValue,
|
||||
string? MinLengthValue,
|
||||
string? ExactLengthValue,
|
||||
string? RangeLengthValue,
|
||||
string? MatchValue,
|
||||
string? SelectorMatchValue,
|
||||
string PatternValue,
|
||||
int InclusiveIntValue,
|
||||
int? InclusiveNullableIntValue,
|
||||
string? EqualValue,
|
||||
string? EqualComparisonValue);
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="ValidatorUtilitiesTestRequest"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ValidatorUtilitiesTestRequestFixture
|
||||
{
|
||||
private const string ValidPattern = "^[a-z]{3}-\\d{3}$";
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ValidatorUtilitiesTestRequest"/> instance with randomized test data that satisfies all validation rules.
|
||||
/// </summary>
|
||||
/// <param name="intValue">Optional. The integer value that must be greater than 3.</param>
|
||||
/// <param name="nullableIntValue">Optional. The nullable integer value that must be greater than 3.</param>
|
||||
/// <param name="decimalValue">Optional. The decimal value that must be greater than 3.</param>
|
||||
/// <param name="nullableDecimalValue">Optional. The nullable decimal value that must be greater than 3.</param>
|
||||
/// <param name="timeSpanValue">Optional. The time span value that must be greater than 3 hours.</param>
|
||||
/// <param name="intValue2">Optional. The integer value that must be greater than or equal to 5.</param>
|
||||
/// <param name="nullableIntValue2">Optional. The nullable integer value that must be greater than or equal to 5.</param>
|
||||
/// <param name="nullableDecimalValue2">Optional. The nullable decimal value that must be greater than or equal to 5.</param>
|
||||
/// <param name="notNullValue">Optional. The value that must not be null.</param>
|
||||
/// <param name="notEmptyValue">Optional. The value that must not be empty.</param>
|
||||
/// <param name="notEmptyGuidValue">Optional. The Guid that must not be empty.</param>
|
||||
/// <param name="notEmptyCollectionValue">Optional. The collection that must not be empty.</param>
|
||||
/// <param name="enumValue">Optional. The enum value that must be defined.</param>
|
||||
/// <param name="nullableEnumValue">Optional. The nullable enum value that must be defined.</param>
|
||||
/// <param name="maxLengthValue">Optional. The value that must not exceed 5 characters.</param>
|
||||
/// <param name="minLengthValue">Optional. The value that must be at least 3 characters.</param>
|
||||
/// <param name="exactLengthValue">Optional. The value that must be exactly 3 characters.</param>
|
||||
/// <param name="rangeLengthValue">Optional. The value that must be between 3 and 5 characters.</param>
|
||||
/// <param name="matchValue">Optional. The value that must match the valid pattern.</param>
|
||||
/// <param name="selectorMatchValue">Optional. The value that must match the pattern selected from the request.</param>
|
||||
/// <param name="patternValue">Optional. The pattern the selector match value must match.</param>
|
||||
/// <param name="inclusiveIntValue">Optional. The integer value that must be between 1 and 10.</param>
|
||||
/// <param name="inclusiveNullableIntValue">Optional. The nullable integer value that must be between 1 and 10.</param>
|
||||
/// <param name="equalValue">Optional. The value that must equal the comparison value.</param>
|
||||
/// <param name="equalComparisonValue">Optional. The comparison value.</param>
|
||||
/// <returns>A configured <see cref="ValidatorUtilitiesTestRequest"/> instance.</returns>
|
||||
public ValidatorUtilitiesTestRequest Create(
|
||||
int? intValue = null,
|
||||
int? nullableIntValue = null,
|
||||
decimal? decimalValue = null,
|
||||
decimal? nullableDecimalValue = null,
|
||||
TimeSpan? timeSpanValue = null,
|
||||
int? intValue2 = null,
|
||||
int? nullableIntValue2 = null,
|
||||
decimal? nullableDecimalValue2 = null,
|
||||
string? notNullValue = null,
|
||||
string? notEmptyValue = null,
|
||||
Guid? notEmptyGuidValue = null,
|
||||
List<string>? notEmptyCollectionValue = null,
|
||||
ValidatorUtilitiesTestEnum? enumValue = null,
|
||||
ValidatorUtilitiesTestEnum? nullableEnumValue = null,
|
||||
string? maxLengthValue = null,
|
||||
string? minLengthValue = null,
|
||||
string? exactLengthValue = null,
|
||||
string? rangeLengthValue = null,
|
||||
string? matchValue = null,
|
||||
string? selectorMatchValue = null,
|
||||
string? patternValue = null,
|
||||
int? inclusiveIntValue = null,
|
||||
int? inclusiveNullableIntValue = null,
|
||||
string? equalValue = null,
|
||||
string? equalComparisonValue = null)
|
||||
{
|
||||
string resolvedPattern = patternValue ?? ValidPattern;
|
||||
return new Faker<ValidatorUtilitiesTestRequest>()
|
||||
.CustomInstantiator(f => new ValidatorUtilitiesTestRequest(
|
||||
IntValue: intValue ?? f.Random.Int(4, 100),
|
||||
NullableIntValue: nullableIntValue ?? f.Random.Int(4, 100),
|
||||
DecimalValue: decimalValue ?? f.Random.Decimal(4m, 100m),
|
||||
NullableDecimalValue: nullableDecimalValue ?? f.Random.Decimal(4m, 100m),
|
||||
TimeSpanValue: timeSpanValue ?? f.Date.BetweenTimeOnly(new TimeOnly(4, 0), new TimeOnly(23, 0)).ToTimeSpan(),
|
||||
IntValue2: intValue2 ?? f.Random.Int(5, 100),
|
||||
NullableIntValue2: nullableIntValue2 ?? f.Random.Int(5, 100),
|
||||
NullableDecimalValue2: nullableDecimalValue2 ?? f.Random.Decimal(5m, 100m),
|
||||
NotNullValue: notNullValue ?? f.Lorem.Word(),
|
||||
NotEmptyValue: notEmptyValue ?? f.Lorem.Word(),
|
||||
NotEmptyGuidValue: notEmptyGuidValue ?? f.Random.Guid(),
|
||||
NotEmptyCollectionValue: notEmptyCollectionValue ?? [f.Lorem.Word()],
|
||||
EnumValue: enumValue ?? f.PickRandom<ValidatorUtilitiesTestEnum>(),
|
||||
NullableEnumValue: nullableEnumValue ?? f.PickRandom<ValidatorUtilitiesTestEnum>(),
|
||||
MaxLengthValue: maxLengthValue ?? f.Random.String2(1, 5),
|
||||
MinLengthValue: minLengthValue ?? f.Random.String2(3, 5),
|
||||
ExactLengthValue: exactLengthValue ?? f.Random.String2(3, 3),
|
||||
RangeLengthValue: rangeLengthValue ?? f.Random.String2(3, 5),
|
||||
MatchValue: matchValue ?? GenerateMatchingValue(f),
|
||||
SelectorMatchValue: selectorMatchValue ?? GenerateMatchingValue(f),
|
||||
PatternValue: resolvedPattern,
|
||||
InclusiveIntValue: inclusiveIntValue ?? f.Random.Int(1, 10),
|
||||
InclusiveNullableIntValue: inclusiveNullableIntValue ?? f.Random.Int(1, 10),
|
||||
EqualValue: equalValue ?? "same",
|
||||
EqualComparisonValue: equalComparisonValue ?? "same"))
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="ValidatorUtilitiesTestRequest"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ValidatorUtilitiesTestRequest"/> instances.</returns>
|
||||
public List<ValidatorUtilitiesTestRequest> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
|
||||
private static string GenerateMatchingValue(Faker f)
|
||||
{
|
||||
string letters = new(Enumerable.Range(0, 3).Select(_ => f.Random.Char('a', 'z')).ToArray());
|
||||
return $"{letters}-{f.Random.Replace("###")}";
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Plugins.Queries.GetLibraryMetadataProviders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Plugins.Queries.GetLibraryMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetLibraryMetadataProvidersQuery"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryMetadataProvidersQueryFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid query to get the metadata providers of a media library.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">Optional. The Id of the media library whose metadata providers are retrieved.</param>
|
||||
/// <returns>The created query.</returns>
|
||||
public GetLibraryMetadataProvidersQuery Create(Guid? libraryId = null)
|
||||
{
|
||||
return new Faker<GetLibraryMetadataProvidersQuery>()
|
||||
.CustomInstantiator(f => new GetLibraryMetadataProvidersQuery(
|
||||
libraryId ?? Guid.NewGuid()))
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="GetLibraryMetadataProvidersQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<GetLibraryMetadataProvidersQuery> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.Plugins.Queries.GetPluginSettings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Fixtures.Core.Plugins.Queries.GetPluginSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetPluginSettingsQuery"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPluginSettingsQueryFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid query to get the settings of a plugin.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">Optional. The unique identifier of the plugin.</param>
|
||||
/// <returns>The created query.</returns>
|
||||
public GetPluginSettingsQuery Create(Guid? pluginId = null)
|
||||
{
|
||||
return new Faker<GetPluginSettingsQuery>()
|
||||
.CustomInstantiator(f => new GetPluginSettingsQuery(
|
||||
pluginId ?? Guid.NewGuid()))
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="GetPluginSettingsQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<GetPluginSettingsQuery> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user