Centralizes and standardizes test fixtures.

This commit is contained in:
BinaryAlley committed 2026-08-15 02:58:17 -07:00
1 parent dfc513da4f
commit b648e2f054
294 files changed
+3807 -4437

No files matched your search

@@ -1,115 +0,0 @@
#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.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
/// <summary>
/// Fixture class for the <see cref="Directory"/> class.
/// </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 Directory instance.</returns>
/// <exception cref="InvalidOperationException">Thrown if the Directory creation fails.</exception>
public Directory CreateDirectory(
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(_ => CreateDirectory())];
}
/// <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 = [];
// ensure we create at least one child if we haven't reached max depth
if (currentDepth < maxDepth)
{
// force at least 1 child, up to maxChildrenPerDirectory
int childCount = _faker.Random.Int(1, maxChildrenPerDirectory);
for (int i = 0; i < childCount; i++)
{
Directory childDirectory = CreateNestedDirectory(currentDepth + 1, maxDepth, maxChildrenPerDirectory);
Result<Updated> addResult = childDirectory.SetParent(childDirectory);
if (!addResult.IsFailure)
childItems.Add(childDirectory);
}
}
return CreateDirectory(childItems: childItems);
}
}
@@ -1,46 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
/// <summary>
/// Fixture class for the <see cref="DirectoryResponse"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class DirectoryResponseFixture
{
private readonly Faker _faker = new();
private readonly FileSystemItemDtoFixture _fileSystemItemModelFixture = new();
/// <summary>
/// Creates a random valid <see cref="DirectoryResponse"/>.
/// </summary>
/// <param name="itemCount">The number of children elements to create.</param>
/// <returns>The created <see cref="DirectoryResponse"/>.</returns>
public DirectoryResponse Create(int itemCount = 3)
{
return new DirectoryResponse(
_faker.System.FilePath(),
_faker.System.FileName(),
_faker.Date.Past(),
_faker.Date.Recent(),
_fileSystemItemModelFixture.CreateMany(itemCount)
);
}
/// <summary>
/// Creates a list of <see cref="DirectoryResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <param name="itemCount">The number of children elemens to create for each element.</param>
/// <returns>The created list.</returns>
public List<DirectoryResponse> CreateMany(int count = 3, int itemCount = 3)
{
return Enumerable.Range(0, count).Select(_ => Create(itemCount)).ToList();
}
}
@@ -1,42 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.DTO.FileSystemManagement;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
/// <summary>
/// Fixture class for the <see cref="FileSystemItemDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class FileSystemItemDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="FileSystemItemDto"/>.
/// </summary>
/// <returns>The created <see cref="FileSystemItemDto"/>.</returns>
public FileSystemItemDto Create()
{
return new FileSystemItemDto(
_faker.System.FilePath(),
_faker.System.FileName(),
_faker.Date.Past(),
_faker.Date.Recent()
);
}
/// <summary>
/// Creates a list of <see cref="FileSystemItemDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<FileSystemItemDto> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
}
}
@@ -1,58 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
/// <summary>
/// Fixture class for the <see cref="FileSystemTreeNodeResponse"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class FileSystemTreeNodeResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a single <see cref="FileSystemTreeNodeResponse"/> with a nested structure.
/// </summary>
/// <param name="currentDepth">The current depth in the tree structure. Default is 0 (root level).</param>
/// <param name="maxDepth">The maximum depth of the tree structure. Default is 2.</param>
/// <param name="maxChildren">The maximum number of children for each node. Default is 3.</param>
/// <returns>A <see cref="FileSystemTreeNodeResponse"/> with a nested structure.</returns>
public FileSystemTreeNodeResponse Create(int currentDepth = 0, int maxDepth = 2, int maxChildren = 3)
{
FileSystemTreeNodeResponse response = new()
{
Path = _faker.System.FilePath(),
Name = _faker.System.FileName(),
ItemType = FileSystemItemType.Directory,
IsExpanded = _faker.Random.Bool(),
ChildrenLoaded = true,
Children = []
};
if (currentDepth < maxDepth)
{
int childCount = _faker.Random.Int(1, maxChildren);
for (int i = 0; i < childCount; i++)
response.Children.Add(Create(currentDepth + 1, maxDepth, maxChildren));
}
return response;
}
/// <summary>
/// Creates a list of <see cref="FileSystemTreeNodeResponse"/> objects, each with a nested structure.
/// </summary>
/// <param name="count">The number of root-level nodes to create. Default is 2.</param>
/// <param name="maxDepth">The maximum depth of the tree structure for each root node. Default is 2.</param>
/// <param name="maxChildren">The maximum number of children for each node. Default is 3.</param>
/// <returns>A list of <see cref="FileSystemTreeNodeResponse"/> objects with nested structures.</returns>
public List<FileSystemTreeNodeResponse> CreateMany(int count = 2, int maxDepth = 2, int maxChildren = 3)
{
return Enumerable.Range(0, count).Select(_ => Create(0, maxDepth, maxChildren)).ToList();
}
}
@@ -1,30 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories.Fixtures;
/// <summary>
/// Fixture class for the <see cref="GetDirectoriesQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetDirectoriesQueryFixture
{
/// <summary>
/// Creates a random valid query to get directories.
/// </summary>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <returns>The created query to get directories.</returns>
public static GetDirectoriesQuery CreateGetDirectoriesQuery(bool includeHiddenElements = false)
{
return new Faker<GetDirectoriesQuery>()
.CustomInstantiator(f => new GetDirectoriesQuery(
default!,
default
))
.RuleFor(x => x.Path, f => f.System.DirectoryPath())
.RuleFor(x => x.IncludeHiddenElements, f => includeHiddenElements);
}
}
@@ -3,12 +3,12 @@ using AutoFixture;
using AutoFixture.AutoNSubstitute;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories.Fixtures;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Directories.Queries.GetDirectories;
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -30,6 +30,7 @@ public class GetDirectoriesQueryHandlerTests
private readonly IDirectoryService _mockDirectoryService;
private readonly GetDirectoriesQueryHandler _sut;
private readonly DirectoryFixture _directoryFixture;
private readonly GetDirectoriesQueryFixture _getDirectoriesQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetDirectoriesQueryHandlerTests"/> class.
@@ -43,13 +44,14 @@ public class GetDirectoriesQueryHandlerTests
.Returns([]);
_sut = new GetDirectoriesQueryHandler(_mockDirectoryService, mockValidator);
_directoryFixture = new DirectoryFixture();
_getDirectoriesQueryFixture = new GetDirectoriesQueryFixture();
}
[Fact]
public async Task HandleAsync_WhenCalledWithValidQueryWithoutFilesIncluded_ShouldReturnSuccessResult()
{
// Arrange
GetDirectoriesQuery getDirectoriesQuery = GetDirectoriesQueryFixture.CreateGetDirectoriesQuery(false);
GetDirectoriesQuery getDirectoriesQuery = _getDirectoriesQueryFixture.Create(includeHiddenElements: false);
IEnumerable<Directory> directories = _directoryFixture.CreateMany();
@@ -83,7 +85,7 @@ public class GetDirectoriesQueryHandlerTests
public async Task HandleAsync_WhenCalledWithValidQueryWithFilesIncluded_ShouldReturnSuccessResult()
{
// Arrange
GetDirectoriesQuery getDirectoriesQuery = GetDirectoriesQueryFixture.CreateGetDirectoriesQuery(true);
GetDirectoriesQuery getDirectoriesQuery = _getDirectoriesQueryFixture.Create(includeHiddenElements: true);
IEnumerable<Directory> directories = _directoryFixture.CreateMany();
@@ -117,7 +119,7 @@ public class GetDirectoriesQueryHandlerTests
public async Task HandleAsync_WhenDirectoryServiceReturnsError_ShouldReturnFailureResult()
{
// Arrange
GetDirectoriesQuery query = _fixture.Create<GetDirectoriesQuery>();
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
Error error = Error.Failure("DirectoryService.Error", "An error occurred");
_mockDirectoryService.GetSubdirectories(query.Path!, query.IncludeHiddenElements)
.Returns(error);
@@ -135,7 +137,7 @@ public class GetDirectoriesQueryHandlerTests
public async Task HandleAsync_WhenDirectoryServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
{
// Arrange
GetDirectoriesQuery query = _fixture.Create<GetDirectoriesQuery>();
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
Result<IEnumerable<Directory>> emptyList = Result.From(Enumerable.Empty<Directory>());
_mockDirectoryService.GetSubdirectories(query.Path!, query.IncludeHiddenElements)
.Returns(emptyList);
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Directories.Queries.GetDirectories;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories.Fixtures;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
@@ -17,6 +17,7 @@ namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Que
public class GetDirectoriesQueryValidatorTests
{
private readonly GetDirectoriesQueryValidator _validator;
private readonly GetDirectoriesQueryFixture _getDirectoriesQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetDirectoriesQueryValidatorTests"/> class.
@@ -24,13 +25,14 @@ public class GetDirectoriesQueryValidatorTests
public GetDirectoriesQueryValidatorTests()
{
_validator = new GetDirectoriesQueryValidator();
_getDirectoriesQueryFixture = new GetDirectoriesQueryFixture();
}
[Fact]
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
{
// Arrange
GetDirectoriesQuery query = GetDirectoriesQueryFixture.CreateGetDirectoriesQuery();
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
query = query with { Path = null! };
// Act
@@ -44,7 +46,7 @@ public class GetDirectoriesQueryValidatorTests
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
{
// Arrange
GetDirectoriesQuery query = GetDirectoriesQueryFixture.CreateGetDirectoriesQuery();
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
query = query with { Path = string.Empty };
// Act
@@ -58,7 +60,7 @@ public class GetDirectoriesQueryValidatorTests
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
{
// Arrange
GetDirectoriesQuery query = GetDirectoriesQueryFixture.CreateGetDirectoriesQuery();
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
query = query with { Path = " " };
// Act
@@ -72,7 +74,7 @@ public class GetDirectoriesQueryValidatorTests
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
{
// Arrange
GetDirectoriesQuery query = GetDirectoriesQueryFixture.CreateGetDirectoriesQuery();
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
query = query with { Path = "/valid/path" };
// Act
@@ -86,7 +88,7 @@ public class GetDirectoriesQueryValidatorTests
public void Validate_WhenIncludeHiddenElementsIsTrue_ShouldNotHaveValidationError()
{
// Arrange
GetDirectoriesQuery query = GetDirectoriesQueryFixture.CreateGetDirectoriesQuery();
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
query = query with { IncludeHiddenElements = true };
// Act
@@ -100,7 +102,7 @@ public class GetDirectoriesQueryValidatorTests
public void Validate_WhenIncludeHiddenElementsIsFalse_ShouldNotHaveValidationError()
{
// Arrange
GetDirectoriesQuery query = GetDirectoriesQueryFixture.CreateGetDirectoriesQuery();
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
query = query with { IncludeHiddenElements = false };
// Act
@@ -1,58 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Drives.Queries.GetDrives.Fixtures;
/// <summary>
/// Fixture class for the <see cref="GetDrivesQueryFixture"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetDrivesQueryFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a single <see cref="FileSystemTreeNodeResponse"/> with a nested structure.
/// </summary>
/// <param name="currentDepth">The current depth in the tree structure. Default is 0 (root level).</param>
/// <param name="maxDepth">The maximum depth of the tree structure. Default is 2.</param>
/// <param name="maxChildren">The maximum number of children for each node. Default is 3.</param>
/// <returns>A <see cref="FileSystemTreeNodeResponse"/> with a nested structure.</returns>
public FileSystemTreeNodeResponse Create(int currentDepth = 0, int maxDepth = 2, int maxChildren = 3)
{
FileSystemTreeNodeResponse response = new()
{
Path = _faker.System.FilePath(),
Name = _faker.System.FileName(),
ItemType = FileSystemItemType.Directory,
IsExpanded = _faker.Random.Bool(),
ChildrenLoaded = true,
Children = []
};
if (currentDepth < maxDepth)
{
int childCount = _faker.Random.Int(1, maxChildren);
for (int i = 0; i < childCount; i++)
response.Children.Add(Create(currentDepth + 1, maxDepth, maxChildren));
}
return response;
}
/// <summary>
/// Creates a list of <see cref="FileSystemTreeNodeResponse"/> objects, each with a nested structure.
/// </summary>
/// <param name="count">The number of root-level nodes to create. Default is 2.</param>
/// <param name="maxDepth">The maximum depth of the tree structure for each root node. Default is 2.</param>
/// <param name="maxChildren">The maximum number of children for each node. Default is 3.</param>
/// <returns>A list of <see cref="FileSystemTreeNodeResponse"/> objects with nested structures.</returns>
public List<FileSystemTreeNodeResponse> CreateMany(int count = 2, int maxDepth = 2, int maxChildren = 3)
{
return Enumerable.Range(0, count).Select(_ => Create(0, maxDepth, maxChildren)).ToList();
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Drives.Queries.GetDrives;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
@@ -24,17 +23,17 @@ namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Drives.Queries.
[ExcludeFromCodeCoverage]
public class GetDrivesQueryHandlerTests
{
private readonly IFixture _fixture;
private readonly IDriveService _mockDriveService;
private readonly GetDrivesQueryHandler _sut;
private readonly GetDrivesQueryFixture _getDrivesQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetDrivesQueryHandlerTests"/> class.
/// </summary>
public GetDrivesQueryHandlerTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockDriveService = Substitute.For<IDriveService>();
_getDrivesQueryFixture = new GetDrivesQueryFixture();
_sut = new GetDrivesQueryHandler(_mockDriveService);
}
@@ -42,7 +41,7 @@ public class GetDrivesQueryHandlerTests
public async Task HandleAsync_WhenCalled_ShouldReturnSuccessResult()
{
// Arrange
GetDrivesQuery getDrivesQuery = _fixture.Create<GetDrivesQuery>();
GetDrivesQuery getDrivesQuery = _getDrivesQueryFixture.Create();
IEnumerable<FileSystemItem> drives =
[
@@ -84,7 +83,7 @@ public class GetDrivesQueryHandlerTests
public async Task HandleAsync_WhenDriveServiceReturnsError_ShouldReturnFailureResult()
{
// Arrange
GetDrivesQuery query = _fixture.Create<GetDrivesQuery>();
GetDrivesQuery query = _getDrivesQueryFixture.Create();
Error error = Error.Failure("DriveService.Error", "An error occurred");
_mockDriveService.GetDrives()
.Returns(error);
@@ -102,7 +101,7 @@ public class GetDrivesQueryHandlerTests
public async Task HandleAsync_WhenDriveServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
{
// Arrange
GetDrivesQuery query = _fixture.Create<GetDrivesQuery>();
GetDrivesQuery query = _getDrivesQueryFixture.Create();
Result<IEnumerable<FileSystemItem>> emptyList = Result.From(Enumerable.Empty<FileSystemItem>());
_mockDriveService.GetDrives()
.Returns(emptyList);
@@ -1,33 +0,0 @@
#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.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Fixtures;
/// <summary>
/// Fixture class for the <see cref="UnixRootItem"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UnixRootItemFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="UnixRootItem"/>.
/// </summary>
/// <returns>The created <see cref="UnixRootItem"/>.</returns>
public UnixRootItem Create()
{
Result<UnixRootItem> unixRootItemResult = UnixRootItem.Create(
_faker.PickRandom<FileSystemItemStatus>()
);
if (unixRootItemResult.IsFailure)
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", unixRootItemResult.Errors));
return unixRootItemResult.Value;
}
}
@@ -1,35 +0,0 @@
#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.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Fixtures;
/// <summary>
/// Fixture class for the <see cref="WindowsRootItem"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class WindowsRootItemFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="WindowsRootItem"/>.
/// </summary>
/// <returns>The created <see cref="WindowsRootItem"/>.</returns>
public WindowsRootItem Create()
{
Result<WindowsRootItem> windowsRootItemResult = WindowsRootItem.Create(
_faker.System.FilePath(),
_faker.System.FileName(),
_faker.PickRandom<FileSystemItemStatus>()
);
if (windowsRootItemResult.IsFailure)
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", windowsRootItemResult.Errors));
return windowsRootItemResult.Value;
}
}
@@ -2,9 +2,10 @@
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Application.Fixtures.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Platform;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -24,6 +25,7 @@ public class GetFileSystemQueryHandlerTests
private readonly IPlatformContextManager _mockPlatformContextManager;
private readonly IPlatformContext _mockPlatformContext;
private readonly GetFileSystemQueryHandler _sut;
private readonly GetFileSystemQueryFixture _getFileSystemQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetFileSystemQueryHandlerTests"/> class.
@@ -34,6 +36,7 @@ public class GetFileSystemQueryHandlerTests
_mockPlatformContextManager = Substitute.For<IPlatformContextManager>();
_mockPlatformContext = Substitute.For<IPlatformContext>();
_mockPlatformContextManager.GetCurrentContext().Returns(_mockPlatformContext);
_getFileSystemQueryFixture = new GetFileSystemQueryFixture();
_sut = new GetFileSystemQueryHandler(_mockPlatformContextManager);
}
@@ -43,7 +46,7 @@ public class GetFileSystemQueryHandlerTests
public async Task HandleAsync_WhenCalled_ShouldReturnCorrectFileSystemTypeResponse(PlatformType platformType)
{
// Arrange
GetFileSystemQuery query = _fixture.Create<GetFileSystemQuery>();
GetFileSystemQuery query = _getFileSystemQueryFixture.Create();
_mockPlatformContext.Platform.Returns(platformType);
// Act
@@ -59,7 +62,7 @@ public class GetFileSystemQueryHandlerTests
public async Task HandleAsync_WhenCalled_ShouldReturnValueTaskResult()
{
// Arrange
GetFileSystemQuery query = _fixture.Create<GetFileSystemQuery>();
GetFileSystemQuery query = _getFileSystemQueryFixture.Create();
_mockPlatformContext.Platform.Returns(PlatformType.Unix);
// Act
@@ -76,8 +79,8 @@ public class GetFileSystemQueryHandlerTests
public async Task HandleAsync_WhenCalled_ShouldNotDependOnQueryContent()
{
// Arrange
GetFileSystemQuery query1 = _fixture.Create<GetFileSystemQuery>();
GetFileSystemQuery query2 = _fixture.Create<GetFileSystemQuery>();
GetFileSystemQuery query1 = _getFileSystemQueryFixture.Create();
GetFileSystemQuery query2 = _getFileSystemQueryFixture.Create();
_mockPlatformContext.Platform.Returns(PlatformType.Windows);
// Act
@@ -93,7 +96,7 @@ public class GetFileSystemQueryHandlerTests
public async Task HandleAsync_WhenCalled_ShouldIgnoreCancellationToken()
{
// Arrange
GetFileSystemQuery query = _fixture.Create<GetFileSystemQuery>();
GetFileSystemQuery query = _getFileSystemQueryFixture.Create();
_mockPlatformContext.Platform.Returns(PlatformType.Unix);
CancellationToken cancellationToken = new(true);
@@ -1,81 +0,0 @@
#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.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
/// <summary>
/// Fixture class for the <see cref="File"/> class.
/// </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>
/// <returns>The created <see cref="File"/>.</returns>
public File CreateFile(
string? path = null,
string? name = null,
Optional<DateTime>? dateCreated = null,
Optional<DateTime>? dateModified = null,
long? size = null,
FileSystemItemStatus? status = null)
{
path ??= _faker.System.FilePath();
name ??= _faker.System.FileName();
dateCreated ??= Optional<DateTime>.Some(_faker.Date.Past());
dateModified ??= Optional<DateTime>.Some(_faker.Date.Recent());
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(_ => CreateFile())];
}
/// <summary>
/// Creates a random valid <see cref="File"/>, without creationg and modification dates.
/// </summary>
/// <returns></returns>
public static File CreateFileWithoutDates()
{
return File.Create(
"/path/to/file_without_dates.txt",
"file_without_dates.txt",
Optional<DateTime>.None(),
Optional<DateTime>.None(),
2048,
FileSystemItemStatus.Accessible
).Value;
}
}
@@ -1,43 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.FileSystemManagement.Files;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
/// <summary>
/// Fixture class for the <see cref="FileResponse"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class FileResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="FileResponse"/>.
/// </summary>
/// <returns>The created <see cref="FileResponse"/>.</returns>
public FileResponse Create()
{
return new FileResponse(
_faker.System.FilePath(),
_faker.System.FileName(),
_faker.Date.Past(),
_faker.Date.Recent(),
_faker.Random.Long()
);
}
/// <summary>
/// Creates a list of <see cref="FileResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<FileResponse> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
}
}
@@ -1,30 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles.Fixtures;
/// <summary>
/// Fixture class for the <see cref="GetFilesQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetFilesQueryFixture
{
/// <summary>
/// Creates a random valid query to get files.
/// </summary>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <returns>The created query to get files.</returns>
public static GetFilesQuery CreateGetFilesQuery(bool includeHiddenElements = false)
{
return new Faker<GetFilesQuery>()
.CustomInstantiator(f => new GetFilesQuery(
default!,
default
))
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.IncludeHiddenElements, f => includeHiddenElements);
}
}
@@ -3,12 +3,12 @@ using AutoFixture;
using AutoFixture.AutoNSubstitute;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles.Fixtures;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Files.Queries.GetFiles;
using Lumina.Contracts.Responses.FileSystemManagement.Files;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -30,6 +30,7 @@ public class GetFilesQueryHandlerTests
private readonly IFileService _mockFileService;
private readonly GetFilesQueryHandler _sut;
private readonly FileFixture _fileFixture;
private readonly GetFilesQueryFixture _getFilesQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetFilesQueryHandlerTests"/> class.
@@ -43,13 +44,14 @@ public class GetFilesQueryHandlerTests
.Returns([]);
_sut = new GetFilesQueryHandler(_mockFileService, mockValidator);
_fileFixture = new FileFixture();
_getFilesQueryFixture = new GetFilesQueryFixture();
}
[Fact]
public async Task HandleAsync_WhenCalledWithValidQueryWithoutHiddenFiles_ShouldReturnSuccessResult()
{
// Arrange
GetFilesQuery getFilesQuery = GetFilesQueryFixture.CreateGetFilesQuery(false);
GetFilesQuery getFilesQuery = _getFilesQueryFixture.Create(includeHiddenElements: false);
IEnumerable<File> files = _fileFixture.CreateMany();
@@ -83,7 +85,7 @@ public class GetFilesQueryHandlerTests
public async Task HandleAsync_WhenCalledWithValidQueryWithHiddenFiles_ShouldReturnSuccessResult()
{
// Arrange
GetFilesQuery getFilesQuery = GetFilesQueryFixture.CreateGetFilesQuery(true);
GetFilesQuery getFilesQuery = _getFilesQueryFixture.Create(includeHiddenElements: true);
IEnumerable<File> files = _fileFixture.CreateMany();
@@ -117,7 +119,7 @@ public class GetFilesQueryHandlerTests
public async Task HandleAsync_WhenFileServiceReturnsError_ShouldReturnFailureResult()
{
// Arrange
GetFilesQuery query = _fixture.Create<GetFilesQuery>();
GetFilesQuery query = _getFilesQueryFixture.Create();
Error error = Error.Failure("FileService.Error", "An error occurred");
_mockFileService.GetFiles(query.Path!, query.IncludeHiddenElements)
.Returns(error);
@@ -135,7 +137,7 @@ public class GetFilesQueryHandlerTests
public async Task HandleAsync_WhenFileServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
{
// Arrange
GetFilesQuery query = _fixture.Create<GetFilesQuery>();
GetFilesQuery query = _getFilesQueryFixture.Create();
Result<IEnumerable<File>> emptyList = Result.From(Enumerable.Empty<File>());
_mockFileService.GetFiles(query.Path!, query.IncludeHiddenElements)
.Returns(emptyList);
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Files.Queries.GetFiles;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles.Fixtures;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
@@ -17,6 +17,7 @@ namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.G
public class GetFilesQueryValidatorTests
{
private readonly GetFilesQueryValidator _validator;
private readonly GetFilesQueryFixture _getFilesQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetFilesQueryValidatorTests"/> class.
@@ -24,13 +25,14 @@ public class GetFilesQueryValidatorTests
public GetFilesQueryValidatorTests()
{
_validator = new GetFilesQueryValidator();
_getFilesQueryFixture = new GetFilesQueryFixture();
}
[Fact]
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
{
// Arrange
GetFilesQuery query = GetFilesQueryFixture.CreateGetFilesQuery();
GetFilesQuery query = _getFilesQueryFixture.Create();
query = query with { Path = null! };
// Act
@@ -44,7 +46,7 @@ public class GetFilesQueryValidatorTests
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
{
// Arrange
GetFilesQuery query = GetFilesQueryFixture.CreateGetFilesQuery();
GetFilesQuery query = _getFilesQueryFixture.Create();
query = query with { Path = string.Empty };
// Act
@@ -58,7 +60,7 @@ public class GetFilesQueryValidatorTests
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
{
// Arrange
GetFilesQuery query = GetFilesQueryFixture.CreateGetFilesQuery();
GetFilesQuery query = _getFilesQueryFixture.Create();
query = query with { Path = " " };
// Act
@@ -72,7 +74,7 @@ public class GetFilesQueryValidatorTests
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
{
// Arrange
GetFilesQuery query = GetFilesQueryFixture.CreateGetFilesQuery();
GetFilesQuery query = _getFilesQueryFixture.Create();
query = query with { Path = "/valid/path" };
// Act
@@ -86,7 +88,7 @@ public class GetFilesQueryValidatorTests
public void Validate_WhenIncludeHiddenElementsIsTrue_ShouldNotHaveValidationError()
{
// Arrange
GetFilesQuery query = GetFilesQueryFixture.CreateGetFilesQuery();
GetFilesQuery query = _getFilesQueryFixture.Create();
query = query with { IncludeHiddenElements = true };
// Act
@@ -100,7 +102,7 @@ public class GetFilesQueryValidatorTests
public void Validate_WhenIncludeHiddenElementsIsFalse_ShouldNotHaveValidationError()
{
// Arrange
GetFilesQuery query = GetFilesQueryFixture.CreateGetFilesQuery();
GetFilesQuery query = _getFilesQueryFixture.Create();
query = query with { IncludeHiddenElements = false };
// Act
@@ -1,30 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles.Fixtures;
/// <summary>
/// Fixture class for the <see cref="GetTreeFilesQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetTreeFilesQueryFixture
{
/// <summary>
/// Creates a random valid query to get files.
/// </summary>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <returns>The created query to get files.</returns>
public static GetTreeFilesQuery CreateGetFilesQuery(bool includeHiddenElements = false)
{
return new Faker<GetTreeFilesQuery>()
.CustomInstantiator(f => new GetTreeFilesQuery(
default!,
default
))
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.IncludeHiddenElements, f => includeHiddenElements);
}
}
@@ -3,12 +3,12 @@ using AutoFixture;
using AutoFixture.AutoNSubstitute;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles.Fixtures;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using NSubstitute;
using System.Collections.Generic;
@@ -30,6 +30,7 @@ public class GetTreeFilesQueryHandlerTests
private readonly IFileService _mockFileService;
private readonly GetTreeFilesQueryHandler _sut;
private readonly FileFixture _fileFixture;
private readonly GetTreeFilesQueryFixture _getTreeFilesQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetTreeFilesQueryHandler"/> class.
@@ -43,13 +44,14 @@ public class GetTreeFilesQueryHandlerTests
.Returns([]);
_sut = new GetTreeFilesQueryHandler(_mockFileService, mockValidator);
_fileFixture = new FileFixture();
_getTreeFilesQueryFixture = new GetTreeFilesQueryFixture();
}
[Fact]
public async Task HandleAsync_WhenCalledWithValidQueryWithoutHiddenFiles_ShouldReturnSuccessResult()
{
// Arrange
GetTreeFilesQuery getFilesQuery = GetTreeFilesQueryFixture.CreateGetFilesQuery(false);
GetTreeFilesQuery getFilesQuery = _getTreeFilesQueryFixture.Create(includeHiddenElements: false);
IEnumerable<File> files = _fileFixture.CreateMany();
@@ -84,7 +86,7 @@ public class GetTreeFilesQueryHandlerTests
public async Task HandleAsync_WhenCalledWithValidQueryWithHiddenFiles_ShouldReturnSuccessResult()
{
// Arrange
GetTreeFilesQuery getFilesQuery = GetTreeFilesQueryFixture.CreateGetFilesQuery(true);
GetTreeFilesQuery getFilesQuery = _getTreeFilesQueryFixture.Create(includeHiddenElements: true);
IEnumerable<File> files = _fileFixture.CreateMany();
@@ -119,7 +121,7 @@ public class GetTreeFilesQueryHandlerTests
public async Task HandleAsync_WhenFileServiceReturnsError_ShouldReturnFailureResult()
{
// Arrange
GetTreeFilesQuery query = _fixture.Create<GetTreeFilesQuery>();
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
Error error = Error.Failure("FileService.Error", "An error occurred");
_mockFileService.GetFiles(query.Path!, query.IncludeHiddenElements)
.Returns(error);
@@ -137,7 +139,7 @@ public class GetTreeFilesQueryHandlerTests
public async Task HandleAsync_WhenFileServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
{
// Arrange
GetTreeFilesQuery query = _fixture.Create<GetTreeFilesQuery>();
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
Result<IEnumerable<File>> emptyList = Result.From(Enumerable.Empty<File>());
_mockFileService.GetFiles(query.Path!, query.IncludeHiddenElements)
.Returns(emptyList);
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles.Fixtures;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
@@ -17,6 +17,7 @@ namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.G
public class GetTreeFilesQueryValidatorTests
{
private readonly GetTreeFilesQueryValidator _validator;
private readonly GetTreeFilesQueryFixture _getTreeFilesQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetTreeFilesQueryValidatorTests"/> class.
@@ -24,13 +25,14 @@ public class GetTreeFilesQueryValidatorTests
public GetTreeFilesQueryValidatorTests()
{
_validator = new GetTreeFilesQueryValidator();
_getTreeFilesQueryFixture = new GetTreeFilesQueryFixture();
}
[Fact]
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
{
// Arrange
GetTreeFilesQuery query = GetTreeFilesQueryFixture.CreateGetFilesQuery();
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
query = query with { Path = null! };
// Act
@@ -44,7 +46,7 @@ public class GetTreeFilesQueryValidatorTests
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
{
// Arrange
GetTreeFilesQuery query = GetTreeFilesQueryFixture.CreateGetFilesQuery();
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
query = query with { Path = string.Empty };
// Act
@@ -58,7 +60,7 @@ public class GetTreeFilesQueryValidatorTests
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
{
// Arrange
GetTreeFilesQuery query = GetTreeFilesQueryFixture.CreateGetFilesQuery();
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
query = query with { Path = " " };
// Act
@@ -72,7 +74,7 @@ public class GetTreeFilesQueryValidatorTests
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
{
// Arrange
GetTreeFilesQuery query = GetTreeFilesQueryFixture.CreateGetFilesQuery();
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
query = query with { Path = "/valid/path" };
// Act
@@ -86,7 +88,7 @@ public class GetTreeFilesQueryValidatorTests
public void Validate_WhenIncludeHiddenElementsIsTrue_ShouldNotHaveValidationError()
{
// Arrange
GetTreeFilesQuery query = GetTreeFilesQueryFixture.CreateGetFilesQuery();
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
query = query with { IncludeHiddenElements = true };
// Act
@@ -100,7 +102,7 @@ public class GetTreeFilesQueryValidatorTests
public void Validate_WhenIncludeHiddenElementsIsFalse_ShouldNotHaveValidationError()
{
// Arrange
GetTreeFilesQuery query = GetTreeFilesQueryFixture.CreateGetFilesQuery();
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
query = query with { IncludeHiddenElements = false };
// Act
@@ -1,42 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Fixtures;
/// <summary>
/// Fixture class for the <see cref="FileSystemPathId"/> class.
/// </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">The path of the file system path element.</param>
/// <returns>The created <see cref="FileSystemPathId"/>.</returns>
public FileSystemPathId CreateFileSystemPathId(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;
}
}
@@ -1,29 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
/// <summary>
/// Fixture class for the <see cref="CombinePathCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class CombinePathCommandFixture
{
/// <summary>
/// Creates a random valid command to combine paths.
/// </summary>
/// <returns>The created command.</returns>
public static CombinePathCommand CreateCombinePathCommand()
{
return new Faker<CombinePathCommand>()
.CustomInstantiator(f => new CombinePathCommand(
default!,
default!
))
.RuleFor(x => x.OriginalPath, f => f.System.FilePath())
.RuleFor(x => x.NewPath, f => f.System.FilePath());
}
}
@@ -1,27 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath.Fixtures;
/// <summary>
/// Fixture class for the <see cref="SplitPathCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class SplitPathCommandFixture
{
/// <summary>
/// Creates a random valid command for splitting paths.
/// </summary>
/// <returns>The created command.</returns>
public static SplitPathCommand CreateSplitPathCommand()
{
return new Faker<SplitPathCommand>()
.CustomInstantiator(f => new SplitPathCommand(
default!
))
.RuleFor(x => x.Path, f => f.System.FilePath());
}
}
@@ -1,58 +0,0 @@
#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.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
/// <summary>
/// Fixture class for the <see cref="PathSegment"/> class.
/// </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>
/// <returns>The created <see cref="PathSegment"/>.</returns>
public PathSegment CreatePathSegment(
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(_ => CreatePathSegment()).ToList();
}
}
@@ -1,37 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
/// <summary>
/// Fixture class for the <see cref="PathSegmentResponse"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class PathSegmentResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="PathSegmentResponse"/>.
/// </summary>
/// <returns>The created <see cref="PathSegmentResponse"/>.</returns>
public PathSegmentResponse Create()
{
return new PathSegmentResponse(_faker.System.DirectoryPath());
}
/// <summary>
/// Creates a list of <see cref="PathSegmentResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<PathSegmentResponse> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
}
}
@@ -1,37 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
/// <summary>
/// Fixture class for the <see cref="PathSeparatorResponse"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class PathSeparatorResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="PathSeparatorResponse"/>.
/// </summary>
/// <returns>The created <see cref="PathSeparatorResponse"/>.</returns>
public PathSeparatorResponse Create()
{
return new PathSeparatorResponse(_faker.System.DirectoryPath());
}
/// <summary>
/// Creates a list of <see cref="PathSeparatorResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<PathSeparatorResponse> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
}
}
@@ -1,30 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
/// <summary>
/// Fixture class for the <see cref="CheckPathExistsQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class CheckPathExistsQueryFixture
{
/// <summary>
/// Creates a random valid query to check if paths exist.
/// </summary>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <returns>The created query.</returns>
public static CheckPathExistsQuery CreateCheckPathExistsQuery(bool includeHiddenElements = true)
{
return new Faker<CheckPathExistsQuery>()
.CustomInstantiator(f => new CheckPathExistsQuery(
default!,
default
))
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.IncludeHiddenElements, includeHiddenElements);
}
}
@@ -1,27 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent.Fixtures;
/// <summary>
/// Fixture class for the <see cref="GetPathParentQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetPathParentQueryFixture
{
/// <summary>
/// Creates a random valid query to check if paths exist.
/// </summary>
/// <returns>The created query.</returns>
public static GetPathParentQuery CreateGetPathParentQuery()
{
return new Faker<GetPathParentQuery>()
.CustomInstantiator(f => new GetPathParentQuery(
default!
))
.RuleFor(x => x.Path, f => f.System.FilePath());
}
}
@@ -1,27 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot.Fixtures;
/// <summary>
/// Fixture class for the <see cref="GetPathRootQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetPathRootQueryFixture
{
/// <summary>
/// Creates a random valid query to check if paths exist.
/// </summary>
/// <returns>The created query.</returns>
public static GetPathRootQuery CreateGetPathRootQuery()
{
return new Faker<GetPathRootQuery>()
.CustomInstantiator(f => new GetPathRootQuery(
default!
))
.RuleFor(x => x.Path, f => f.System.FilePath());
}
}
@@ -1,27 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath.Fixtures;
/// <summary>
/// Fixture class for the <see cref="ValidatePathQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ValidatePathQueryFixure
{
/// <summary>
/// Creates a random valid query to check if paths exist.
/// </summary>
/// <returns>The created query.</returns>
public static ValidatePathQuery CreateValidatePathQuery()
{
return new Faker<ValidatePathQuery>()
.CustomInstantiator(f => new ValidatePathQuery(
default!
))
.RuleFor(x => x.Path, f => f.System.FilePath());
}
}
@@ -3,7 +3,7 @@ using AutoFixture;
using AutoFixture.AutoNSubstitute;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
@@ -13,7 +13,7 @@ using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Commands.CombinePath;
/// <summary>
/// Contains unit tests for the <see cref="CombinePathCommandHandler"/> class.
@@ -24,6 +24,7 @@ public class CombinePathCommandHandlerTests
private readonly IFixture _fixture;
private readonly IPathService _mockPathService;
private readonly CombinePathCommandHandler _sut;
private readonly CombinePathCommandFixture _combinePathCommandFixture;
/// <summary>
/// Initializes a new instance of the <see cref="CombinePathCommandHandlerTests"/> class.
@@ -36,13 +37,14 @@ public class CombinePathCommandHandlerTests
mockValidator.Validate(Arg.Any<CombinePathCommand>())
.Returns([]);
_sut = new CombinePathCommandHandler(_mockPathService, mockValidator);
_combinePathCommandFixture = new CombinePathCommandFixture();
}
[Fact]
public async Task HandleAsync_WhenCalledWithValidCommand_ShouldReturnSuccessResult()
{
// Arrange
CombinePathCommand combinePathCommand = CombinePathCommandFixture.CreateCombinePathCommand();
CombinePathCommand combinePathCommand = _combinePathCommandFixture.Create();
string combinedPath = System.IO.Path.Combine(combinePathCommand.OriginalPath!, combinePathCommand.NewPath!);
_mockPathService.CombinePath(combinePathCommand.OriginalPath!, combinePathCommand.NewPath!)
@@ -62,7 +64,7 @@ public class CombinePathCommandHandlerTests
public async Task HandleAsync_WhenPathServiceReturnsError_ShouldReturnFailureResult()
{
// Arrange
CombinePathCommand command = _fixture.Create<CombinePathCommand>();
CombinePathCommand command = _combinePathCommandFixture.Create();
Error error = Error.Failure("PathService.Error", "An error occurred");
_mockPathService.CombinePath(command.OriginalPath!, command.NewPath!)
.Returns(error);
@@ -80,7 +82,7 @@ public class CombinePathCommandHandlerTests
public async Task HandleAsync_WhenPathServiceReturnsEmptyString_ShouldReturnSuccessResultWithEmptyPath()
{
// Arrange
CombinePathCommand command = _fixture.Create<CombinePathCommand>();
CombinePathCommand command = _combinePathCommandFixture.Create();
_mockPathService.CombinePath(command.OriginalPath!, command.NewPath!)
.Returns(Result.From(string.Empty));
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Commands.CombinePath;
/// <summary>
/// Contains unit tests for the <see cref="CombinePathCommandValidator"/> class.
@@ -17,6 +17,7 @@ namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.C
public class CombinePathCommandValidatorTests
{
private readonly CombinePathCommandValidator _validator;
private readonly CombinePathCommandFixture _combinePathCommandFixture;
/// <summary>
/// Initializes a new instance of the <see cref="CombinePathCommandValidatorTests"/> class.
@@ -24,13 +25,14 @@ public class CombinePathCommandValidatorTests
public CombinePathCommandValidatorTests()
{
_validator = new CombinePathCommandValidator();
_combinePathCommandFixture = new CombinePathCommandFixture();
}
[Fact]
public void Validate_WhenOriginalPathIsNull_ShouldHaveValidationError()
{
// Arrange
CombinePathCommand command = CombinePathCommandFixture.CreateCombinePathCommand();
CombinePathCommand command = _combinePathCommandFixture.Create();
command = command with { OriginalPath = null! };
// Act
@@ -44,7 +46,7 @@ public class CombinePathCommandValidatorTests
public void Validate_WhenOriginalPathIsEmpty_ShouldHaveValidationError()
{
// Arrange
CombinePathCommand command = CombinePathCommandFixture.CreateCombinePathCommand();
CombinePathCommand command = _combinePathCommandFixture.Create();
command = command with { OriginalPath = string.Empty };
// Act
@@ -58,7 +60,7 @@ public class CombinePathCommandValidatorTests
public void Validate_WhenOriginalPathIsWhitespace_ShouldHaveValidationError()
{
// Arrange
CombinePathCommand command = CombinePathCommandFixture.CreateCombinePathCommand();
CombinePathCommand command = _combinePathCommandFixture.Create();
command = command with { OriginalPath = " " };
// Act
@@ -72,7 +74,7 @@ public class CombinePathCommandValidatorTests
public void Validate_WhenNewPathIsNull_ShouldHaveValidationError()
{
// Arrange
CombinePathCommand command = CombinePathCommandFixture.CreateCombinePathCommand();
CombinePathCommand command = _combinePathCommandFixture.Create();
command = command with { NewPath = null! };
// Act
@@ -86,7 +88,7 @@ public class CombinePathCommandValidatorTests
public void Validate_WhenNewPathIsEmpty_ShouldHaveValidationError()
{
// Arrange
CombinePathCommand command = CombinePathCommandFixture.CreateCombinePathCommand();
CombinePathCommand command = _combinePathCommandFixture.Create();
command = command with { NewPath = string.Empty };
// Act
@@ -100,7 +102,7 @@ public class CombinePathCommandValidatorTests
public void Validate_WhenNewPathIsWhitespace_ShouldHaveValidationError()
{
// Arrange
CombinePathCommand command = CombinePathCommandFixture.CreateCombinePathCommand();
CombinePathCommand command = _combinePathCommandFixture.Create();
command = command with { NewPath = " " };
// Act
@@ -114,7 +116,7 @@ public class CombinePathCommandValidatorTests
public void Validate_WhenBothPathsAreValid_ShouldNotHaveValidationError()
{
// Arrange
CombinePathCommand command = CombinePathCommandFixture.CreateCombinePathCommand();
CombinePathCommand command = _combinePathCommandFixture.Create();
command = command with { OriginalPath = "/valid/path", NewPath = "new/segment" };
// Act
@@ -3,12 +3,12 @@ using AutoFixture;
using AutoFixture.AutoNSubstitute;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Commands.SplitPath;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -18,7 +18,7 @@ using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Commands.SplitPath;
/// <summary>
/// Contains unit tests for the <see cref="SplitPathCommandHandler"/> class.
@@ -30,6 +30,7 @@ public class SplitPathCommandHandlerTests
private readonly IPathService _mockPathService;
private readonly SplitPathCommandHandler _sut;
private readonly PathSegmentFixture _pathSegmentFixture;
private readonly SplitPathCommandFixture _splitPathCommandFixture;
/// <summary>
/// Initializes a new instance of the <see cref="SplitPathCommandHandlerTests"/> class.
@@ -43,13 +44,14 @@ public class SplitPathCommandHandlerTests
.Returns([]);
_sut = new SplitPathCommandHandler(_mockPathService, mockValidator);
_pathSegmentFixture = new PathSegmentFixture();
_splitPathCommandFixture = new SplitPathCommandFixture();
}
[Fact]
public async Task HandleAsync_WhenCalledWithValidCommand_ShouldReturnSuccessResult()
{
// Arrange
SplitPathCommand splitPathCommand = SplitPathCommandFixture.CreateSplitPathCommand();
SplitPathCommand splitPathCommand = _splitPathCommandFixture.Create();
IEnumerable<PathSegment> pathSegments = _pathSegmentFixture.CreateMany();
@@ -76,7 +78,7 @@ public class SplitPathCommandHandlerTests
public async Task HandleAsync_WhenPathServiceReturnsError_ShouldReturnFailureResult()
{
// Arrange
SplitPathCommand command = _fixture.Create<SplitPathCommand>();
SplitPathCommand command = _splitPathCommandFixture.Create();
Error error = Error.Failure("PathService.Error", "An error occurred");
_mockPathService.ParsePath(command.Path!)
.Returns(error);
@@ -94,7 +96,7 @@ public class SplitPathCommandHandlerTests
public async Task HandleAsync_WhenPathServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
{
// Arrange
SplitPathCommand command = _fixture.Create<SplitPathCommand>();
SplitPathCommand command = _splitPathCommandFixture.Create();
Result<IEnumerable<PathSegment>> emptyList = Result.From(Enumerable.Empty<PathSegment>());
_mockPathService.ParsePath(command.Path!)
.Returns(emptyList);
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Commands.SplitPath;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath.Fixtures;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Commands.SplitPath;
/// <summary>
/// Contains unit tests for the <see cref="SplitPathCommandValidator"/> class.
@@ -17,6 +17,7 @@ namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.S
public class SplitPathCommandValidatorTests
{
private readonly SplitPathCommandValidator _validator;
private readonly SplitPathCommandFixture _splitPathCommandFixture;
/// <summary>
/// Initializes a new instance of the <see cref="SplitPathCommandValidatorTests"/> class.
@@ -24,13 +25,14 @@ public class SplitPathCommandValidatorTests
public SplitPathCommandValidatorTests()
{
_validator = new SplitPathCommandValidator();
_splitPathCommandFixture = new SplitPathCommandFixture();
}
[Fact]
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
{
// Arrange
SplitPathCommand command = SplitPathCommandFixture.CreateSplitPathCommand();
SplitPathCommand command = _splitPathCommandFixture.Create();
command = command with { Path = null! };
// Act
@@ -44,7 +46,7 @@ public class SplitPathCommandValidatorTests
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
{
// Arrange
SplitPathCommand command = SplitPathCommandFixture.CreateSplitPathCommand();
SplitPathCommand command = _splitPathCommandFixture.Create();
command = command with { Path = string.Empty };
// Act
@@ -58,7 +60,7 @@ public class SplitPathCommandValidatorTests
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
{
// Arrange
SplitPathCommand command = SplitPathCommandFixture.CreateSplitPathCommand();
SplitPathCommand command = _splitPathCommandFixture.Create();
command = command with { Path = " " };
// Act
@@ -72,7 +74,7 @@ public class SplitPathCommandValidatorTests
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
{
// Arrange
SplitPathCommand command = SplitPathCommandFixture.CreateSplitPathCommand();
SplitPathCommand command = _splitPathCommandFixture.Create();
command = command with { Path = "/valid/path" };
// Act
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
@@ -11,7 +11,7 @@ using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
/// <summary>
/// Contains unit tests for the <see cref="CheckPathExistsQueryHandler"/> class.
@@ -21,6 +21,7 @@ public class CheckPathExistsQueryHandlerTests
{
private readonly IPathService _mockPathService;
private readonly CheckPathExistsQueryHandler _sut;
private readonly CheckPathExistsQueryFixture _checkPathExistsQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="CheckPathExistsQueryHandlerTests"/> class.
@@ -28,6 +29,7 @@ public class CheckPathExistsQueryHandlerTests
public CheckPathExistsQueryHandlerTests()
{
_mockPathService = Substitute.For<IPathService>();
_checkPathExistsQueryFixture = new CheckPathExistsQueryFixture();
IValidator<CheckPathExistsQuery> mockValidator = Substitute.For<IValidator<CheckPathExistsQuery>>();
mockValidator.Validate(Arg.Any<CheckPathExistsQuery>())
.Returns([]);
@@ -38,7 +40,7 @@ public class CheckPathExistsQueryHandlerTests
public async Task HandleAsync_WhenPathExistsAndIsNotHidden_ShouldReturnTrueResponse()
{
// Arrange
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery();
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
_mockPathService.Exists(query.Path!).Returns(true);
// Act
@@ -54,7 +56,7 @@ public class CheckPathExistsQueryHandlerTests
public async Task HandleAsync_WhenPathExistsAndIsHiddenAndIncludeHiddenElementsIsTrue_ShouldReturnTrueResponse()
{
// Arrange
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery(true);
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create(includeHiddenElements: true);
_mockPathService.Exists(query.Path!).Returns(true);
// Act
@@ -70,7 +72,7 @@ public class CheckPathExistsQueryHandlerTests
public async Task HandleAsync_WhenPathExistsAndIsHiddenAndIncludeHiddenElementsIsFalse_ShouldReturnFalseResponse()
{
// Arrange
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery(false);
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create(includeHiddenElements: false);
_mockPathService.Exists(query.Path!, false).Returns(false);
// Act
@@ -86,7 +88,7 @@ public class CheckPathExistsQueryHandlerTests
public async Task HandleAsync_WhenPathDoesNotExist_ShouldReturnFalseResponse()
{
// Arrange
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery();
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
_mockPathService.Exists(query.Path!).Returns(false);
// Act
@@ -118,7 +120,7 @@ public class CheckPathExistsQueryHandlerTests
public async Task HandleAsync_WhenCancellationRequested_ShouldStillCompleteOperation()
{
// Arrange
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery();
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
_mockPathService.Exists(query.Path!).Returns(true);
CancellationToken cancellationToken = new(true);
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
/// <summary>
/// Contains unit tests for the <see cref="CheckPathExistsQueryValidator"/> class.
@@ -17,6 +17,7 @@ namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.Ch
public class CheckPathExistsQueryValidatorTests
{
private readonly CheckPathExistsQueryValidator _validator;
private readonly CheckPathExistsQueryFixture _checkPathExistsQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="CheckPathExistsQueryValidatorTests"/> class.
@@ -24,13 +25,14 @@ public class CheckPathExistsQueryValidatorTests
public CheckPathExistsQueryValidatorTests()
{
_validator = new CheckPathExistsQueryValidator();
_checkPathExistsQueryFixture = new CheckPathExistsQueryFixture();
}
[Fact]
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
{
// Arrange
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery();
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
query = query with { Path = null! };
// Act
@@ -44,7 +46,7 @@ public class CheckPathExistsQueryValidatorTests
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
{
// Arrange
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery();
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
query = query with { Path = string.Empty };
// Act
@@ -58,7 +60,7 @@ public class CheckPathExistsQueryValidatorTests
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
{
// Arrange
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery();
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
query = query with { Path = " " };
// Act
@@ -72,7 +74,7 @@ public class CheckPathExistsQueryValidatorTests
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
{
// Arrange
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery();
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
query = query with { Path = "/valid/path" };
// Act
@@ -3,12 +3,12 @@ using AutoFixture;
using AutoFixture.AutoNSubstitute;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent.Fixtures;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using NSubstitute;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -17,7 +17,7 @@ using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.GetPathParent;
/// <summary>
/// Contains unit tests for the <see cref="GetPathParentQueryHandler"/> class.
@@ -29,6 +29,7 @@ public class GetPathParentQueryHandlerTests
private readonly IPathService _mockPathService;
private readonly GetPathParentQueryHandler _sut;
private readonly PathSegmentFixture _pathSegmentFixture;
private readonly GetPathParentQueryFixture _getPathParentQueryFixture;
public GetPathParentQueryHandlerTests()
{
@@ -39,13 +40,14 @@ public class GetPathParentQueryHandlerTests
.Returns([]);
_sut = new GetPathParentQueryHandler(_mockPathService, mockValidator);
_pathSegmentFixture = new PathSegmentFixture();
_getPathParentQueryFixture = new GetPathParentQueryFixture();
}
[Fact]
public async Task HandleAsync_WhenCalledWithValidQuery_ShouldReturnSuccessResult()
{
// Arrange
GetPathParentQuery query = GetPathParentQueryFixture.CreateGetPathParentQuery();
GetPathParentQuery query = _getPathParentQueryFixture.Create();
IEnumerable<PathSegment> pathSegments = _pathSegmentFixture.CreateMany();
@@ -69,7 +71,7 @@ public class GetPathParentQueryHandlerTests
public async Task HandleAsync_WhenPathServiceReturnsError_ShouldReturnFailureResult()
{
// Arrange
GetPathParentQuery query = _fixture.Create<GetPathParentQuery>();
GetPathParentQuery query = _getPathParentQueryFixture.Create();
Error error = Error.Failure("PathService.Error", "An error occurred");
_mockPathService.GoUpOneLevel(query.Path!)
.Returns(error);
@@ -87,7 +89,7 @@ public class GetPathParentQueryHandlerTests
public async Task HandleAsync_WhenPathServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
{
// Arrange
GetPathParentQuery query = _fixture.Create<GetPathParentQuery>();
GetPathParentQuery query = _getPathParentQueryFixture.Create();
Result<IEnumerable<PathSegment>> emptyList = Result.From(Enumerable.Empty<PathSegment>());
_mockPathService.GoUpOneLevel(query.Path!)
.Returns(emptyList);
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent.Fixtures;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.GetPathParent;
/// <summary>
/// Contains unit tests for the <see cref="GetPathParentQueryValidator"/> class.
@@ -17,6 +17,7 @@ namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.Ge
public class GetPathParentQueryValidatorTests
{
private readonly GetPathParentQueryValidator _validator;
private readonly GetPathParentQueryFixture _getPathParentQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetPathParentQueryValidatorTests"/> class.
@@ -24,13 +25,14 @@ public class GetPathParentQueryValidatorTests
public GetPathParentQueryValidatorTests()
{
_validator = new GetPathParentQueryValidator();
_getPathParentQueryFixture = new GetPathParentQueryFixture();
}
[Fact]
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
{
// Arrange
GetPathParentQuery query = GetPathParentQueryFixture.CreateGetPathParentQuery();
GetPathParentQuery query = _getPathParentQueryFixture.Create();
query = query with { Path = null! };
// Act
@@ -44,7 +46,7 @@ public class GetPathParentQueryValidatorTests
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
{
// Arrange
GetPathParentQuery query = GetPathParentQueryFixture.CreateGetPathParentQuery();
GetPathParentQuery query = _getPathParentQueryFixture.Create();
query = query with { Path = string.Empty };
// Act
@@ -58,7 +60,7 @@ public class GetPathParentQueryValidatorTests
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
{
// Arrange
GetPathParentQuery query = GetPathParentQueryFixture.CreateGetPathParentQuery();
GetPathParentQuery query = _getPathParentQueryFixture.Create();
query = query with { Path = " " };
// Act
@@ -72,7 +74,7 @@ public class GetPathParentQueryValidatorTests
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
{
// Arrange
GetPathParentQuery query = GetPathParentQueryFixture.CreateGetPathParentQuery();
GetPathParentQuery query = _getPathParentQueryFixture.Create();
query = query with { Path = "/valid/path" };
// Act
@@ -1,19 +1,19 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot.Fixtures;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using NSubstitute;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
/// <summary>
/// Contains unit tests for the <see cref="GetPathRootQueryHandler"/> class.
@@ -24,6 +24,7 @@ public class GetPathRootQueryHandlerTests
private readonly IPathService _mockPathService;
private readonly GetPathRootQueryHandler _sut;
private readonly PathSegmentFixture _pathSegmentFixture;
private readonly GetPathRootQueryFixture _getPathRootQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetPathRootQueryHandlerTests"/> class.
@@ -31,6 +32,7 @@ public class GetPathRootQueryHandlerTests
public GetPathRootQueryHandlerTests()
{
_mockPathService = Substitute.For<IPathService>();
_getPathRootQueryFixture = new GetPathRootQueryFixture();
IValidator<GetPathRootQuery> mockValidator = Substitute.For<IValidator<GetPathRootQuery>>();
mockValidator.Validate(Arg.Any<GetPathRootQuery>())
.Returns([]);
@@ -42,8 +44,8 @@ public class GetPathRootQueryHandlerTests
public async Task HandleAsync_WhenCalledWithValidQuery_ShouldReturnSuccessResult()
{
// Arrange
GetPathRootQuery query = GetPathRootQueryFixture.CreateGetPathRootQuery();
PathSegment pathSegment = _pathSegmentFixture.CreatePathSegment(isDrive: true);
GetPathRootQuery query = _getPathRootQueryFixture.Create();
PathSegment pathSegment = _pathSegmentFixture.Create(isDrive: true);
_mockPathService.GetPathRoot(query.Path!)
.Returns(Result.From(pathSegment));
@@ -62,7 +64,7 @@ public class GetPathRootQueryHandlerTests
public async Task HandleAsync_WhenPathServiceReturnsError_ShouldReturnFailureResult()
{
// Arrange
GetPathRootQuery query = GetPathRootQueryFixture.CreateGetPathRootQuery();
GetPathRootQuery query = _getPathRootQueryFixture.Create();
Error error = Error.Failure("PathService.Error", "An error occurred");
_mockPathService.GetPathRoot(query.Path!)
.Returns(error);
@@ -80,8 +82,8 @@ public class GetPathRootQueryHandlerTests
public async Task HandleAsync_WhenPathServiceReturnsRootPathSegment_ShouldReturnRootSuccessResult()
{
// Arrange
GetPathRootQuery query = GetPathRootQueryFixture.CreateGetPathRootQuery();
PathSegment rootPathSegment = _pathSegmentFixture.CreatePathSegment(name: "/", isDirectory: true, isDrive: true);
GetPathRootQuery query = _getPathRootQueryFixture.Create();
PathSegment rootPathSegment = _pathSegmentFixture.Create(name: "/", isDirectory: true, isDrive: true);
_mockPathService.GetPathRoot(query.Path!)
.Returns(Result.From(rootPathSegment));
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot.Fixtures;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
/// <summary>
/// Contains unit tests for the <see cref="GetPathRootQueryValidator"/> class.
@@ -17,6 +17,7 @@ namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.Ge
public class GetPathRootQueryValidatorTests
{
private readonly GetPathRootQueryValidator _validator;
private readonly GetPathRootQueryFixture _getPathRootQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetPathRootQueryValidatorTests"/> class.
@@ -24,13 +25,14 @@ public class GetPathRootQueryValidatorTests
public GetPathRootQueryValidatorTests()
{
_validator = new GetPathRootQueryValidator();
_getPathRootQueryFixture = new GetPathRootQueryFixture();
}
[Fact]
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
{
// Arrange
GetPathRootQuery query = GetPathRootQueryFixture.CreateGetPathRootQuery();
GetPathRootQuery query = _getPathRootQueryFixture.Create();
query = query with { Path = null! };
// Act
@@ -44,7 +46,7 @@ public class GetPathRootQueryValidatorTests
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
{
// Arrange
GetPathRootQuery query = GetPathRootQueryFixture.CreateGetPathRootQuery();
GetPathRootQuery query = _getPathRootQueryFixture.Create();
query = query with { Path = string.Empty };
// Act
@@ -58,7 +60,7 @@ public class GetPathRootQueryValidatorTests
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
{
// Arrange
GetPathRootQuery query = GetPathRootQueryFixture.CreateGetPathRootQuery();
GetPathRootQuery query = _getPathRootQueryFixture.Create();
query = query with { Path = " " };
// Act
@@ -72,7 +74,7 @@ public class GetPathRootQueryValidatorTests
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
{
// Arrange
GetPathRootQuery query = GetPathRootQueryFixture.CreateGetPathRootQuery();
GetPathRootQuery query = _getPathRootQueryFixture.Create();
query = query with { Path = "/valid/path" };
// Act
@@ -9,7 +9,7 @@ using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathSeparator;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.GetPathSeparator;
/// <summary>
/// Contains unit tests for the <see cref="GetPathSeparatorQueryHandler"/> class.
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath.Fixtures;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
@@ -12,7 +12,7 @@ using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.ValidatePath;
/// <summary>
/// Contains unit tests for the <see cref="ValidatePathQueryHandler"/> class.
@@ -23,6 +23,7 @@ public class ValidatePathQueryHandlerTests
private readonly IPathService _mockPathService;
private readonly IValidator<ValidatePathQuery> _mockValidator;
private readonly ValidatePathQueryHandler _sut;
private readonly ValidatePathQueryFixture _validatePathQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="ValidatePathQueryHandlerTests"/> class.
@@ -31,6 +32,7 @@ public class ValidatePathQueryHandlerTests
{
_mockPathService = Substitute.For<IPathService>();
_mockValidator = Substitute.For<IValidator<ValidatePathQuery>>();
_validatePathQueryFixture = new ValidatePathQueryFixture();
_mockValidator.Validate(Arg.Any<ValidatePathQuery>())
.Returns([]);
_sut = new ValidatePathQueryHandler(_mockPathService, _mockValidator);
@@ -40,7 +42,7 @@ public class ValidatePathQueryHandlerTests
public async Task HandleAsync_WhenCalledWithValidPath_ShouldReturnTrueResponse()
{
// Arrange
ValidatePathQuery query = ValidatePathQueryFixure.CreateValidatePathQuery();
ValidatePathQuery query = _validatePathQueryFixture.Create();
_mockPathService.IsValidPath(query.Path!).Returns(true);
// Act
@@ -56,7 +58,7 @@ public class ValidatePathQueryHandlerTests
public async Task HandleAsync_WhenCalledWithInvalidPath_ShouldReturnFalseResponse()
{
// Arrange
ValidatePathQuery query = ValidatePathQueryFixure.CreateValidatePathQuery();
ValidatePathQuery query = _validatePathQueryFixture.Create();
_mockPathService.IsValidPath(query.Path!).Returns(false);
// Act
@@ -104,7 +106,7 @@ public class ValidatePathQueryHandlerTests
public async Task HandleAsync_WhenValidatorReturnsErrors_ShouldReturnValidationErrorsWithoutCallingPathService()
{
// Arrange
ValidatePathQuery query = ValidatePathQueryFixure.CreateValidatePathQuery();
ValidatePathQuery query = _validatePathQueryFixture.Create();
_mockValidator.Validate(query)
.Returns([Errors.FileSystemManagement.PathCannotBeEmpty]);
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath.Fixtures;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath;
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.ValidatePath;
/// <summary>
/// Contains unit tests for the <see cref="ValidatePathQueryValidator"/> class.
@@ -17,6 +17,7 @@ namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.Va
public class ValidatePathQueryValidatorTests
{
private readonly ValidatePathQueryValidator _validator;
private readonly ValidatePathQueryFixture _validatePathQueryFixture;
/// <summary>
/// Initializes a new instance of the <see cref="ValidatePathQueryValidatorTests"/> class.
@@ -24,13 +25,14 @@ public class ValidatePathQueryValidatorTests
public ValidatePathQueryValidatorTests()
{
_validator = new ValidatePathQueryValidator();
_validatePathQueryFixture = new ValidatePathQueryFixture();
}
[Fact]
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
{
// Arrange
ValidatePathQuery query = ValidatePathQueryFixure.CreateValidatePathQuery();
ValidatePathQuery query = _validatePathQueryFixture.Create();
query = query with { Path = null! };
// Act
@@ -44,7 +46,7 @@ public class ValidatePathQueryValidatorTests
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
{
// Arrange
ValidatePathQuery query = ValidatePathQueryFixure.CreateValidatePathQuery();
ValidatePathQuery query = _validatePathQueryFixture.Create();
query = query with { Path = string.Empty };
// Act
@@ -58,7 +60,7 @@ public class ValidatePathQueryValidatorTests
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
{
// Arrange
ValidatePathQuery query = ValidatePathQueryFixure.CreateValidatePathQuery();
ValidatePathQuery query = _validatePathQueryFixture.Create();
query = query with { Path = " " };
// Act
@@ -72,7 +74,7 @@ public class ValidatePathQueryValidatorTests
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
{
// Arrange
ValidatePathQuery query = ValidatePathQueryFixure.CreateValidatePathQuery();
ValidatePathQuery query = _validatePathQueryFixture.Create();
query = query with { Path = "/valid/path" };
// Act
@@ -1,30 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Thumbnails.Fixtures;
/// <summary>
/// Fixture class for the <see cref="ThumbnailResponse"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ThumbnailResponseFixture
{
/// <summary>
/// Creates a random valid query to get a thumbnail.
/// </summary>
/// <returns>The created query.</returns>
public static ThumbnailResponse CreateThumbnailResponse()
{
return new Faker<ThumbnailResponse>()
.CustomInstantiator(f => new ThumbnailResponse(
default,
default!
))
.RuleFor(x => x.Type, f => f.PickRandom<ImageType>())
.RuleFor(x => x.Bytes, f => f.Random.Bytes(20));
}
}
@@ -1,29 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail.Fixtures;
/// <summary>
/// Fixture class for the <see cref="GetThumbnailQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetThumbnailQueryFixture
{
/// <summary>
/// Creates a random valid query to get a thumbnail.
/// </summary>
/// <returns>The created query.</returns>
public static GetThumbnailQuery CreateGetThumbnailQuery()
{
return new Faker<GetThumbnailQuery>()
.CustomInstantiator(f => new GetThumbnailQuery(
default!,
default
))
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.Quality, f => f.Random.Int());
}
}
@@ -3,10 +3,12 @@ using AutoFixture;
using AutoFixture.AutoNSubstitute;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using NSubstitute;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
@@ -24,11 +26,15 @@ public class GetThumbnailQueryHandlerTests
private readonly IFixture _fixture;
private readonly IThumbnailService _mockThumbnailService;
private readonly GetThumbnailQueryHandler _sut;
private readonly GetThumbnailQueryFixture _getThumbnailQueryFixture;
private readonly ThumbnailFixture _thumbnailFixture;
public GetThumbnailQueryHandlerTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockThumbnailService = Substitute.For<IThumbnailService>();
_getThumbnailQueryFixture = new GetThumbnailQueryFixture();
_thumbnailFixture = new ThumbnailFixture();
IValidator<GetThumbnailQuery> mockValidator = Substitute.For<IValidator<GetThumbnailQuery>>();
mockValidator.Validate(Arg.Any<GetThumbnailQuery>())
.Returns([]);
@@ -39,8 +45,8 @@ public class GetThumbnailQueryHandlerTests
public async Task HandleAsync_WhenCalledWithValidQuery_ShouldReturnSuccessResult()
{
// Arrange
GetThumbnailQuery query = _fixture.Create<GetThumbnailQuery>();
Thumbnail thumbnail = _fixture.Create<Thumbnail>();
GetThumbnailQuery query = _getThumbnailQueryFixture.Create();
Thumbnail thumbnail = _thumbnailFixture.Create();
_mockThumbnailService.GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>())
.Returns(Result.From(thumbnail));
@@ -60,7 +66,7 @@ public class GetThumbnailQueryHandlerTests
public async Task HandleAsync_WhenThumbnailServiceReturnsError_ShouldReturnFailureResult()
{
// Arrange
GetThumbnailQuery query = _fixture.Create<GetThumbnailQuery>();
GetThumbnailQuery query = _getThumbnailQueryFixture.Create();
Error error = Error.Failure("ThumbnailService.Error", "An error occurred");
_mockThumbnailService.GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>())
.Returns(error);
@@ -78,7 +84,7 @@ public class GetThumbnailQueryHandlerTests
public async Task HandleAsync_WhenCancellationRequested_ShouldCancelOperation()
{
// Arrange
GetThumbnailQuery query = _fixture.Create<GetThumbnailQuery>();
GetThumbnailQuery query = _getThumbnailQueryFixture.Create();
CancellationTokenSource cts = new();
cts.Cancel();