mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Centralizes and standardizes test fixtures.
This commit is contained in:
1 parent
dfc513da4f
commit
b648e2f054
294 files changed
+3807
-4437
No files matched your search
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats;
|
||||
using SixLabors.ImageSharp.Formats.Bmp;
|
||||
using SixLabors.ImageSharp.Formats.Gif;
|
||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||
using SixLabors.ImageSharp.Formats.Png;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Common.Enums.PhotoLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Test-support class providing image byte data for each supported <see cref="ImageType"/>.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ImageTypeFixture : TheoryData<ImageType, byte[]>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ImageTypeFixture"/> class.
|
||||
/// </summary>
|
||||
public ImageTypeFixture()
|
||||
{
|
||||
Add(ImageType.JPEG, CreateImage(new JpegEncoder()));
|
||||
Add(ImageType.PNG, CreateImage(new PngEncoder()));
|
||||
Add(ImageType.BMP, CreateImage(new BmpEncoder()));
|
||||
Add(ImageType.GIF, CreateImage(new GifEncoder()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a byte array representing a thumbnail fixture.
|
||||
/// </summary>
|
||||
/// <param name="encoder">The encoder used for the image.</param>
|
||||
/// <returns>The byte array of the created image.</returns>
|
||||
private static byte[] CreateImage(IImageEncoder encoder)
|
||||
{
|
||||
using Image<Rgba32> image = new(10, 10);
|
||||
using MemoryStream ms = new();
|
||||
image.Save(ms, encoder);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture.Kernel;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a specimen builder for the <see cref="DateOnly"/> type.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DateOnlySpecimenBuilder : ISpecimenBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds <see cref="DateOnly"/> support to the AutoFixture library.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to process.</param>
|
||||
/// <param name="context">The context within which the specimen is created.</param>
|
||||
/// <returns>A specimen based on the request.</returns>
|
||||
public object Create(object request, ISpecimenContext context)
|
||||
{
|
||||
if (request is Type type && type == typeof(DateOnly))
|
||||
return DateOnly.FromDateTime(DateTime.Now);
|
||||
return new NoSpecimen();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture.Kernel;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a specimen builder for the <see cref="DateOnly?"/> type.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class NullableDateOnlySpecimenBuilder : ISpecimenBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds <see cref="DateOnly?"/> support to the AutoFixture library.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to process.</param>
|
||||
/// <param name="context">The context within which the specimen is created.</param>
|
||||
/// <returns>A specimen based on the request.</returns>
|
||||
public object Create(object request, ISpecimenContext context)
|
||||
{
|
||||
if (request is Type type && type == typeof(DateOnly?))
|
||||
return (DateOnly?)DateOnly.FromDateTime(DateTime.Now);
|
||||
return new NoSpecimen();
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Directory"/> entity.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DirectoryFixture
|
||||
{
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DirectoryFixture"/> class.
|
||||
/// </summary>
|
||||
public DirectoryFixture()
|
||||
{
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="Directory"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">Optional. The directory path. If not provided, a random path is generated.</param>
|
||||
/// <param name="name">Optional. The directory name. If not provided, a random name is generated.</param>
|
||||
/// <param name="dateCreated">Optional. The directory's creation date. If not provided, a random past date is generated.</param>
|
||||
/// <param name="dateModified">Optional. The directory's modification date. If not provided, a recent date is generated.</param>
|
||||
/// <param name="status">Optional. The directory's status. If not provided, a random status is assigned.</param>
|
||||
/// <param name="childItems">Optional. A list of child items to be added to the directory.</param>
|
||||
/// <returns>A newly created <see cref="Directory"/> instance.</returns>
|
||||
/// <exception cref="InvalidOperationException">Thrown if the <see cref="Directory"/> creation fails.</exception>
|
||||
public Directory Create(
|
||||
string? path = null,
|
||||
string? name = null,
|
||||
Optional<DateTime>? dateCreated = null,
|
||||
Optional<DateTime>? dateModified = null,
|
||||
FileSystemItemStatus? status = null,
|
||||
List<FileSystemItem>? childItems = null)
|
||||
{
|
||||
path ??= _faker.System.FilePath();
|
||||
name ??= _faker.System.FileName();
|
||||
dateCreated ??= Optional<DateTime>.Some(_faker.Date.Past());
|
||||
dateModified ??= Optional<DateTime>.Some(_faker.Date.Recent());
|
||||
status ??= _faker.PickRandom<FileSystemItemStatus>();
|
||||
|
||||
Result<Directory> directoryResult = Directory.Create(path, name, dateCreated.Value, dateModified.Value, status.Value);
|
||||
|
||||
if (directoryResult.IsFailure)
|
||||
throw new InvalidOperationException("Failed to create Directory: " + string.Join(", ", directoryResult.Errors));
|
||||
Directory directory = directoryResult.Value;
|
||||
|
||||
if (childItems != null)
|
||||
foreach (FileSystemItem item in childItems)
|
||||
directory.AddItem(item);
|
||||
return directory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="Directory"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<Directory> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of nested <see cref="Directory"/> objects with a hierarchical structure.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of top-level directories to create. Default is 3.</param>
|
||||
/// <param name="maxDepth">The maximum depth of the directory hierarchy. Default is 3.</param>
|
||||
/// <param name="maxChildrenPerDirectory">The maximum number of child items (files or directories) per directory. Default is 3.</param>
|
||||
/// <returns>A list of <see cref="Directory"/> objects with nested structures.</returns>
|
||||
public List<Directory> CreateManyNested(int count = 3, int maxDepth = 3, int maxChildrenPerDirectory = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => CreateNestedDirectory(1, maxDepth, maxChildrenPerDirectory))];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recursively creates a nested <see cref="Directory"/> structure.
|
||||
/// </summary>
|
||||
/// <param name="currentDepth">The current depth in the directory hierarchy.</param>
|
||||
/// <param name="maxDepth">The maximum allowed depth for the directory hierarchy.</param>
|
||||
/// <param name="maxChildrenPerDirectory">The maximum number of child items (files or directories) allowed per directory.</param>
|
||||
/// <returns>A <see cref="Directory"/> object that may contain nested directories and files.</returns>
|
||||
private Directory CreateNestedDirectory(int currentDepth, int maxDepth, int maxChildrenPerDirectory)
|
||||
{
|
||||
List<FileSystemItem> childItems = [];
|
||||
|
||||
if (currentDepth < maxDepth)
|
||||
{
|
||||
int childCount = _faker.Random.Int(0, maxChildrenPerDirectory);
|
||||
for (int i = 0; i < childCount; i++)
|
||||
childItems.Add(CreateNestedDirectory(currentDepth + 1, maxDepth, maxChildrenPerDirectory));
|
||||
}
|
||||
return Create(childItems: childItems);
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="File"/> entity.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileFixture
|
||||
{
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileFixture"/> class.
|
||||
/// </summary>
|
||||
public FileFixture()
|
||||
{
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="File"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">Optional. The file path. If not provided, a random path is generated.</param>
|
||||
/// <param name="name">Optional. The file name. If not provided, a random name is generated.</param>
|
||||
/// <param name="dateCreated">Optional. The file's creation date. If not provided, a random past date is generated.</param>
|
||||
/// <param name="dateModified">Optional. The file's modification date. If not provided, a recent date is generated.</param>
|
||||
/// <param name="size">Optional. The file size. If not provided, a random size is generated.</param>
|
||||
/// <param name="status">Optional. The file's status. If not provided, a random status is assigned.</param>
|
||||
/// <param name="includeDates">Whether the file should include creation and modification dates.</param>
|
||||
/// <returns>The created <see cref="File"/>.</returns>
|
||||
public File Create(
|
||||
string? path = null,
|
||||
string? name = null,
|
||||
Optional<DateTime>? dateCreated = null,
|
||||
Optional<DateTime>? dateModified = null,
|
||||
long? size = null,
|
||||
FileSystemItemStatus? status = null,
|
||||
bool includeDates = true)
|
||||
{
|
||||
path ??= _faker.System.FilePath();
|
||||
name ??= _faker.System.FileName();
|
||||
dateCreated ??= includeDates ? Optional<DateTime>.Some(_faker.Date.Past()) : Optional<DateTime>.None();
|
||||
dateModified ??= includeDates ? Optional<DateTime>.Some(_faker.Date.Recent()) : Optional<DateTime>.None();
|
||||
size ??= _faker.Random.Long();
|
||||
status ??= _faker.PickRandom<FileSystemItemStatus>();
|
||||
|
||||
Result<File> fileResult = File.Create(path, name, dateCreated.Value, dateModified.Value, size.Value, status.Value);
|
||||
|
||||
if (fileResult.IsFailure)
|
||||
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", fileResult.Errors));
|
||||
return fileResult.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="File"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<File> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="UnixRootItem"/> entity.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UnixRootItemFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="UnixRootItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="status">Optional. The root item status.</param>
|
||||
/// <returns>The created <see cref="UnixRootItem"/>.</returns>
|
||||
public UnixRootItem Create(FileSystemItemStatus? status = null)
|
||||
{
|
||||
Result<UnixRootItem> unixRootItemResult = UnixRootItem.Create(
|
||||
status ?? _faker.PickRandom<FileSystemItemStatus>()
|
||||
);
|
||||
if (unixRootItemResult.IsFailure)
|
||||
throw new InvalidOperationException("Failed to create UnixRootItem: " + string.Join(", ", unixRootItemResult.Errors));
|
||||
return unixRootItemResult.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="UnixRootItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<UnixRootItem> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="WindowsRootItem"/> entity.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class WindowsRootItemFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="WindowsRootItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">Optional. The root item path.</param>
|
||||
/// <param name="name">Optional. The root item name.</param>
|
||||
/// <param name="status">Optional. The root item status.</param>
|
||||
/// <returns>The created <see cref="WindowsRootItem"/>.</returns>
|
||||
public WindowsRootItem Create(
|
||||
string? path = null,
|
||||
string? name = null,
|
||||
FileSystemItemStatus? status = null)
|
||||
{
|
||||
Result<WindowsRootItem> windowsRootItemResult = WindowsRootItem.Create(
|
||||
path ?? _faker.System.FilePath(),
|
||||
name ?? _faker.System.FileName(),
|
||||
status ?? _faker.PickRandom<FileSystemItemStatus>()
|
||||
);
|
||||
if (windowsRootItemResult.IsFailure)
|
||||
throw new InvalidOperationException("Failed to create WindowsRootItem: " + string.Join(", ", windowsRootItemResult.Errors));
|
||||
return windowsRootItemResult.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="WindowsRootItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<WindowsRootItem> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Test-support class that allows the abstract <see cref="FileSystemItem"/> type to be instantiated in tests.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemItemFixture : FileSystemItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileSystemItemFixture"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier for the file system path.</param>
|
||||
/// <param name="name">The name of the file system item.</param>
|
||||
/// <param name="fileSystemItemType">The type of the file system item.</param>
|
||||
public FileSystemItemFixture(FileSystemPathId id, string name, FileSystemItemType fileSystemItemType)
|
||||
: base(id, name, fileSystemItemType)
|
||||
{
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Platform;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Platform;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture interface for non existing platform context.
|
||||
/// </summary>
|
||||
public interface INonExistentPlatformContextFixture : IPlatformContext
|
||||
{
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FileSystemPathId"/> value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemPathIdFixture
|
||||
{
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileSystemPathIdFixture"/> class.
|
||||
/// </summary>
|
||||
public FileSystemPathIdFixture()
|
||||
{
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="FileSystemPathId"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">Optional. The path of the file system path element.</param>
|
||||
/// <returns>The created <see cref="FileSystemPathId"/>.</returns>
|
||||
public FileSystemPathId Create(string? path = null)
|
||||
{
|
||||
path ??= _faker.System.FilePath();
|
||||
|
||||
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
|
||||
if (fileSystemPathIdResult.IsFailure)
|
||||
throw new InvalidOperationException("Failed to create FileSystemPathId: " + string.Join(", ", fileSystemPathIdResult.Errors));
|
||||
return fileSystemPathIdResult.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="FileSystemPathId"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<FileSystemPathId> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PathSegment"/> value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PathSegmentFixture
|
||||
{
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PathSegmentFixture"/> class.
|
||||
/// </summary>
|
||||
public PathSegmentFixture()
|
||||
{
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="PathSegment"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">Optional. The segment name.</param>
|
||||
/// <param name="isDirectory">Whether the segment is a directory.</param>
|
||||
/// <param name="isDrive">Whether the segment is a drive.</param>
|
||||
/// <returns>The created <see cref="PathSegment"/>.</returns>
|
||||
public PathSegment Create(
|
||||
string? name = null,
|
||||
bool? isDirectory = null,
|
||||
bool? isDrive = null)
|
||||
{
|
||||
name ??= _faker.System.FileName();
|
||||
isDirectory ??= true;
|
||||
isDrive ??= false;
|
||||
|
||||
Result<PathSegment> pathResult = PathSegment.Create(name, isDirectory.Value, isDrive.Value);
|
||||
|
||||
if (pathResult.IsFailure)
|
||||
throw new InvalidOperationException("Failed to create PathSegment: " + string.Join(", ", pathResult.Errors));
|
||||
return pathResult.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="PathSegment"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<PathSegment> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="StreamInfo"/> value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class StreamInfoFixture
|
||||
{
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StreamInfoFixture"/> class.
|
||||
/// </summary>
|
||||
public StreamInfoFixture()
|
||||
{
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="StreamInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="streamId">Optional. The unique identifier for the stream.</param>
|
||||
/// <param name="mimeType">Optional. The MIME type of the stream.</param>
|
||||
/// <param name="bitrate">Optional. The bitrate of the stream in kbps.</param>
|
||||
/// <param name="codec">Optional. The codec used for the stream.</param>
|
||||
/// <param name="resolution">Optional. The video resolution.</param>
|
||||
/// <param name="frameRate">Optional. The frame rate of the video stream.</param>
|
||||
/// <param name="sampleRate">Optional. The sample rate of the audio stream.</param>
|
||||
/// <param name="channels">Optional. The number of audio channels.</param>
|
||||
/// <returns>The created <see cref="StreamInfo"/>.</returns>
|
||||
public StreamInfo Create(
|
||||
string? streamId = null,
|
||||
string? mimeType = null,
|
||||
int? bitrate = null,
|
||||
string? codec = null,
|
||||
Optional<string>? resolution = null,
|
||||
Optional<float>? frameRate = null,
|
||||
Optional<int>? sampleRate = null,
|
||||
Optional<int>? channels = null)
|
||||
{
|
||||
streamId ??= _faker.Random.AlphaNumeric(10);
|
||||
mimeType ??= _faker.System.MimeType();
|
||||
bitrate ??= _faker.Random.Number(1, 10000);
|
||||
codec ??= _faker.Random.Word();
|
||||
resolution ??= Optional<string>.FromNullable(_faker.Random.Bool() ? $"{_faker.Random.Number(100, 4000)}x{_faker.Random.Number(100, 4000)}" : null);
|
||||
frameRate ??= Optional<float>.FromNullable(_faker.Random.Bool() ? (float?)_faker.Random.Float(1, 120) : null);
|
||||
sampleRate ??= Optional<int>.FromNullable(_faker.Random.Bool() ? (int?)_faker.Random.Number(8000, 192000) : null);
|
||||
channels ??= Optional<int>.FromNullable(_faker.Random.Bool() ? (int?)_faker.Random.Number(1, 8) : null);
|
||||
|
||||
Result<StreamInfo> streamInfoResult = StreamInfo.Create(
|
||||
streamId, mimeType, bitrate.Value, codec, resolution.Value, frameRate.Value, sampleRate.Value, channels.Value);
|
||||
|
||||
if (streamInfoResult.IsFailure)
|
||||
throw new InvalidOperationException("Failed to create StreamInfo: " + string.Join(", ", streamInfoResult.Errors));
|
||||
return streamInfoResult.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="StreamInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<StreamInfo> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Thumbnail"/> value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThumbnailFixture
|
||||
{
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ThumbnailFixture"/> class.
|
||||
/// </summary>
|
||||
public ThumbnailFixture()
|
||||
{
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="Thumbnail"/>.
|
||||
/// </summary>
|
||||
/// <param name="type">Optional. The <see cref="ImageType"/> of the thumbnail. If not provided, a random image type is selected.</param>
|
||||
/// <param name="bytes">Optional. The byte array representing the image data. If not provided, a random 1KB byte array is generated.</param>
|
||||
/// <returns>A newly created <see cref="Thumbnail"/> instance.</returns>
|
||||
public Thumbnail Create(ImageType? type = null, byte[]? bytes = null)
|
||||
{
|
||||
type ??= _faker.PickRandom<ImageType>();
|
||||
bytes ??= _faker.Random.Bytes(1024); // Generate 1KB of random bytes
|
||||
|
||||
return new Thumbnail(type.Value, bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="Thumbnail"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<Thumbnail> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Library"/> domain aggregate.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryFixture
|
||||
{
|
||||
private readonly Faker _faker;
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryFixture"/> class.
|
||||
/// </summary>
|
||||
public LibraryFixture()
|
||||
{
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="Library"/> domain aggregate.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The library Id.</param>
|
||||
/// <param name="userId">Optional. The Id of the user that owns the library.</param>
|
||||
/// <param name="title">Optional. The library title.</param>
|
||||
/// <param name="libraryType">Optional. The library type.</param>
|
||||
/// <param name="contentLocations">Optional. The content locations of the library.</param>
|
||||
/// <param name="coverImage">Optional. The cover image of the library.</param>
|
||||
/// <param name="isEnabled">Whether the library is enabled.</param>
|
||||
/// <param name="isLocked">Whether the library is locked.</param>
|
||||
/// <param name="downloadMetadataFromWeb">Whether metadata download from the web is enabled.</param>
|
||||
/// <param name="shouldSaveMetadataInMediaDirectories">Whether metadata should be saved in the media directories.</param>
|
||||
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Whether unchanged directories should be skipped during scan.</param>
|
||||
/// <param name="scanIds">Optional. The scan Ids associated with the library.</param>
|
||||
/// <returns>The created <see cref="Library"/>.</returns>
|
||||
public Library 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 = false,
|
||||
bool shouldSkipUnchangedDirectoriesDuringScan = false,
|
||||
IEnumerable<Guid>? scanIds = null)
|
||||
{
|
||||
List<string> validPaths =
|
||||
[
|
||||
"C:/Media",
|
||||
"D:/Books",
|
||||
"E:/Digital Library",
|
||||
"F:/Content"
|
||||
];
|
||||
|
||||
List<ScanId> resolvedScanIds = scanIds is null ? [ScanId.CreateUnique(), ScanId.CreateUnique()] : [.. scanIds.Select(scanId => ScanId.Create(scanId))];
|
||||
|
||||
Result<Library> library = id is null ?
|
||||
Library.Create(
|
||||
userId is not null ? UserId.Create(userId.Value) : UserId.CreateUnique(),
|
||||
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
libraryType ?? _faker.PickRandom<LibraryType>(),
|
||||
contentLocations ?? validPaths.Take(_random.Next(1, validPaths.Count)),
|
||||
coverImage ?? _faker.System.FilePath(),
|
||||
isEnabled,
|
||||
isLocked,
|
||||
downloadMetadataFromWeb,
|
||||
shouldSaveMetadataInMediaDirectories,
|
||||
shouldSkipUnchangedDirectoriesDuringScan,
|
||||
resolvedScanIds
|
||||
) :
|
||||
Library.Create(
|
||||
LibraryId.Create(id.Value),
|
||||
userId is not null ? UserId.Create(userId.Value) : UserId.CreateUnique(),
|
||||
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
libraryType ?? _faker.PickRandom<LibraryType>(),
|
||||
contentLocations ?? validPaths.Take(_random.Next(1, validPaths.Count)),
|
||||
coverImage ?? _faker.System.FilePath(),
|
||||
isEnabled,
|
||||
isLocked,
|
||||
downloadMetadataFromWeb,
|
||||
shouldSaveMetadataInMediaDirectories,
|
||||
shouldSkipUnchangedDirectoriesDuringScan,
|
||||
resolvedScanIds
|
||||
);
|
||||
|
||||
return library.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="Library"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="Library"/> instances.</returns>
|
||||
public List<Library> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Common.Setup;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Book"/> domain aggregate.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly IsbnFixture _isbnFixture;
|
||||
private readonly BookRatingFixture _bookRatingFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookFixture"/> class.
|
||||
/// </summary>
|
||||
public BookFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
|
||||
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
|
||||
_isbnFixture = new IsbnFixture();
|
||||
_bookRatingFixture = new BookRatingFixture();
|
||||
ConfigureCustomDomainTypes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="Book"/> domain aggregate.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="Book"/> domain aggregate.</returns>
|
||||
public Book Create()
|
||||
{
|
||||
return Book.Create(
|
||||
LibraryId.Create(_fixture.Create<Guid>()),
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<WrittenContentMetadata>(),
|
||||
_fixture.Create<BookFormat>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<int>>(),
|
||||
_fixture.Create<Optional<BookSeries>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<List<Isbn>>(),
|
||||
_fixture.Create<List<MediaContributorId>>(),
|
||||
_fixture.Create<List<BookRating>>()
|
||||
).Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="Book"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="Book"/> instances.</returns>
|
||||
public List<Book> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
|
||||
private void ConfigureCustomDomainTypes()
|
||||
{
|
||||
_fixture.Register(() => Optional<string>.Some(_fixture.Create<string>()));
|
||||
_fixture.Register(() => Optional<int>.Some(_fixture.Create<int>()));
|
||||
|
||||
_fixture.Register(() =>
|
||||
{
|
||||
int originalYear = _fixture.Create<Generator<int>>().First(year => year >= 1900 && year <= 2025);
|
||||
int reReleaseYear = _fixture.Create<Generator<int>>().First(year => year >= originalYear && year <= 2025);
|
||||
|
||||
return ReleaseInfo.Create(
|
||||
Optional<DateOnly>.Some(DateOnly.FromDateTime(new DateTime(originalYear, 1, 1))),
|
||||
Optional<int>.Some(originalYear),
|
||||
Optional<DateOnly>.Some(DateOnly.FromDateTime(new DateTime(reReleaseYear, 1, 1))),
|
||||
Optional<int>.Some(reReleaseYear),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>()
|
||||
).Value;
|
||||
});
|
||||
|
||||
_fixture.Register(() => Genre.Create(
|
||||
_fixture.Create<string>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => Tag.Create(
|
||||
_fixture.Create<string>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => WrittenContentMetadata.Create(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<ReleaseInfo>(),
|
||||
_fixture.Create<List<Genre>>(),
|
||||
_fixture.Create<List<Tag>>(),
|
||||
_fixture.Create<Optional<LanguageInfo>>(),
|
||||
_fixture.Create<Optional<LanguageInfo>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<int>>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => _isbnFixture.Create());
|
||||
|
||||
_fixture.Register(() => _bookRatingFixture.Create());
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BookRating"/> domain value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookRatingFixture"/> class.
|
||||
/// </summary>
|
||||
public BookRatingFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="BookRating"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Optional. The rating value.</param>
|
||||
/// <param name="maxValue">Optional. The maximum possible rating value.</param>
|
||||
/// <param name="source">Optional. The rating source. If not provided, a random source is selected.</param>
|
||||
/// <param name="voteCount">Optional. The number of votes. If not provided, a random vote count is selected.</param>
|
||||
/// <returns>The created <see cref="BookRating"/>.</returns>
|
||||
public BookRating Create(
|
||||
decimal? value = null,
|
||||
decimal? maxValue = null,
|
||||
Optional<BookRatingSource>? source = null,
|
||||
Optional<int>? voteCount = null)
|
||||
{
|
||||
maxValue ??= _random.Next(5, 10);
|
||||
value ??= _random.Next(1, (int)maxValue.Value);
|
||||
source ??= Optional<BookRatingSource>.Some(_fixture.Create<BookRatingSource>());
|
||||
voteCount ??= Optional<int>.Some(_random.Next(1, 1000));
|
||||
|
||||
return BookRating.Create(value.Value, maxValue.Value, source.Value, voteCount.Value).Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="BookRating"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="BookRating"/> instances.</returns>
|
||||
public List<BookRating> CreateMany(int count = 3)
|
||||
{
|
||||
List<BookRating> result = [];
|
||||
for (int i = 0; i < count; i++)
|
||||
result.Add(Create());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Isbn"/> domain value object.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnFixture
|
||||
{
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid <see cref="Isbn"/> with a random or explicitly requested format.
|
||||
/// </summary>
|
||||
/// <param name="format">Optional. The requested <see cref="IsbnFormat"/>. If not provided, a random format is selected.</param>
|
||||
/// <returns>The created <see cref="Isbn"/>.</returns>
|
||||
public Isbn Create(IsbnFormat? format = null)
|
||||
{
|
||||
IsbnFormat targetFormat = format ?? (_random.Next(2) == 0 ? IsbnFormat.Isbn10 : IsbnFormat.Isbn13);
|
||||
string isbn = targetFormat == IsbnFormat.Isbn10 ? GenerateValidIsbn10() : GenerateValidIsbn13();
|
||||
return Isbn.Create(isbn, targetFormat).Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="Isbn"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="Isbn"/> instances.</returns>
|
||||
public List<Isbn> CreateMany(int count = 3)
|
||||
{
|
||||
List<Isbn> result = [];
|
||||
for (int i = 0; i < count; i++)
|
||||
result.Add(Create());
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GenerateValidIsbn10()
|
||||
{
|
||||
int[] digits = new int[9];
|
||||
for (int i = 0; i < 9; i++)
|
||||
digits[i] = _random.Next(0, 10);
|
||||
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
|
||||
int checkDigit = (11 - sum % 11) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
}
|
||||
|
||||
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 isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
|
||||
int checkDigit = (10 - sum % 10) % 10;
|
||||
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>false</IsTestProject>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Lumina.Domain\Lumina.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Lumina.Domain.Fixtures")]
|
||||
[assembly: AssemblyProduct("Lumina.Domain.Fixtures")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("A1B2C3D4-0001-4A5B-9C0D-111111111111")]
|
||||
|
||||
[assembly: InternalsVisibleTo("Lumina.Domain.UnitTests")]
|
||||
[assembly: InternalsVisibleTo("Lumina.Application.UnitTests")]
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
Reference in new issue
Block a user