mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 00:11:10 +00:00
Renames project paths from Lumina to Nemera
This commit is contained in:
1 parent
ce6fddb4c9
commit
0f659a4877
6450 files changed
No files matched your search
+161
@@ -0,0 +1,161 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
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;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDirectoriesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDirectoriesQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IDirectoryService _mockDirectoryService;
|
||||
private readonly GetDirectoriesQueryHandler _sut;
|
||||
private readonly DirectoryFixture _directoryFixture = new();
|
||||
private readonly GetDirectoriesQueryFixture _getDirectoriesQueryFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoriesQueryHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public GetDirectoriesQueryHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockDirectoryService = Substitute.For<IDirectoryService>();
|
||||
IValidator<GetDirectoriesQuery> mockValidator = Substitute.For<IValidator<GetDirectoriesQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetDirectoriesQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetDirectoriesQueryHandler(_mockDirectoryService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithValidQueryWithoutFilesIncluded_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesQuery getDirectoriesQuery = _getDirectoriesQueryFixture.Create(shouldIncludeHiddenElements: false);
|
||||
|
||||
IEnumerable<Directory> directories =
|
||||
[
|
||||
_directoryFixture.Create(isHidden: true),
|
||||
_directoryFixture.Create(isHidden: false)
|
||||
];
|
||||
|
||||
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.ShouldIncludeHiddenElements)
|
||||
.Returns(Result.From(directories));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(getDirectoriesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.IsAssignableFrom<IEnumerable<DirectoryResponse>>(result.Value);
|
||||
Assert.Equal(directories.Count(), result.Value.Count());
|
||||
|
||||
List<DirectoryResponse> resultList = [.. result.Value];
|
||||
List<Directory> directoriesList = [.. directories];
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
Assert.Equal(directoriesList[i].Id.Path, resultList[i].Path);
|
||||
Assert.Equal(directoriesList[i].Name, resultList[i].Name);
|
||||
Assert.Equal(directoriesList[i].DateCreated.Value, resultList[i].DateCreated);
|
||||
Assert.Equal(directoriesList[i].DateModified.Value, resultList[i].DateModified);
|
||||
Assert.Equal(directoriesList[i].IsHidden, resultList[i].IsHidden);
|
||||
Assert.Empty(resultList[i].Items); // Since files are not included.
|
||||
}
|
||||
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.ShouldIncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithValidQueryWithFilesIncluded_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesQuery getDirectoriesQuery = _getDirectoriesQueryFixture.Create(shouldIncludeHiddenElements: true);
|
||||
|
||||
IEnumerable<Directory> directories =
|
||||
[
|
||||
_directoryFixture.Create(isHidden: true),
|
||||
_directoryFixture.Create(isHidden: false)
|
||||
];
|
||||
|
||||
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.ShouldIncludeHiddenElements)
|
||||
.Returns(Result.From(directories));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(getDirectoriesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.IsAssignableFrom<IEnumerable<DirectoryResponse>>(result.Value);
|
||||
Assert.Equal(directories.Count(), result.Value.Count());
|
||||
|
||||
List<DirectoryResponse> resultList = [.. result.Value];
|
||||
List<Directory> directoriesList = [.. directories];
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
Assert.Equal(directoriesList[i].Id.Path, resultList[i].Path);
|
||||
Assert.Equal(directoriesList[i].Name, resultList[i].Name);
|
||||
Assert.Equal(directoriesList[i].DateCreated.Value, resultList[i].DateCreated);
|
||||
Assert.Equal(directoriesList[i].DateModified.Value, resultList[i].DateModified);
|
||||
Assert.Equal(directoriesList[i].IsHidden, resultList[i].IsHidden);
|
||||
Assert.Equal(directoriesList[i].Items.Count, resultList[i].Items.Count);
|
||||
}
|
||||
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.ShouldIncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenDirectoryServiceReturnsError_ShouldReturnFailureResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
|
||||
Error error = Error.Failure("DirectoryService.Error", "An error occurred");
|
||||
_mockDirectoryService.GetSubdirectories(query.Path!, query.ShouldIncludeHiddenElements)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(query.Path!, query.ShouldIncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenDirectoryServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
|
||||
Result<IEnumerable<Directory>> emptyList = Result.From(Enumerable.Empty<Directory>());
|
||||
_mockDirectoryService.GetSubdirectories(query.Path!, query.ShouldIncludeHiddenElements)
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Empty(result.Value);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(query.Path!, query.ShouldIncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
#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.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDirectoriesQueryValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDirectoriesQueryValidatorTests
|
||||
{
|
||||
private readonly GetDirectoriesQueryValidator _validator = new();
|
||||
private readonly GetDirectoriesQueryFixture _getDirectoriesQueryFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenShouldIncludeHiddenElementsIsTrue_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
|
||||
query = query with { ShouldIncludeHiddenElements = true };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenShouldIncludeHiddenElementsIsFalse_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesQuery query = _getDirectoriesQueryFixture.Create();
|
||||
query = query with { ShouldIncludeHiddenElements = false };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
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;
|
||||
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;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Drives.Queries.GetDrives;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDrivesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDrivesQueryHandlerTests
|
||||
{
|
||||
private readonly IDriveService _mockDriveService;
|
||||
private readonly GetDrivesQueryHandler _sut;
|
||||
private readonly GetDrivesQueryFixture _getDrivesQueryFixture = new();
|
||||
private readonly WindowsRootItemFixture _windowsRootItemFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDrivesQueryHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public GetDrivesQueryHandlerTests()
|
||||
{
|
||||
_mockDriveService = Substitute.For<IDriveService>();
|
||||
_sut = new GetDrivesQueryHandler(_mockDriveService);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalled_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDrivesQuery getDrivesQuery = _getDrivesQueryFixture.Create();
|
||||
|
||||
IEnumerable<FileSystemItem> drives =
|
||||
[
|
||||
_windowsRootItemFixture.Create(path: "C:\\", name: "C:"),
|
||||
_windowsRootItemFixture.Create(path: "D:\\", name: "D:")
|
||||
];
|
||||
|
||||
_mockDriveService.GetDrives()
|
||||
.Returns(Result.From(drives));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getDrivesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.IsAssignableFrom<IEnumerable<FileSystemTreeNodeResponse>>(result.Value);
|
||||
Assert.Equal(drives.Count(), result.Value.Count());
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = [.. result.Value];
|
||||
List<FileSystemItem> drivesList = [.. drives];
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
FileSystemTreeNodeResponse response = resultList[i];
|
||||
WindowsRootItem drive = (WindowsRootItem)drivesList[i];
|
||||
|
||||
Assert.Equal(drive.Id.Path, response.Path);
|
||||
Assert.Equal(drive.Name, response.Name);
|
||||
Assert.Equal(FileSystemItemType.Root, response.ItemType);
|
||||
Assert.False(response.IsExpanded);
|
||||
Assert.False(response.ChildrenLoaded);
|
||||
Assert.Empty(response.Children);
|
||||
}
|
||||
|
||||
_mockDriveService.Received(1).GetDrives();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenDriveServiceReturnsError_ShouldReturnFailureResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDrivesQuery query = _getDrivesQueryFixture.Create();
|
||||
Error error = Error.Failure("DriveService.Error", "An error occurred");
|
||||
_mockDriveService.GetDrives()
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
_mockDriveService.Received(1).GetDrives();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenDriveServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDrivesQuery query = _getDrivesQueryFixture.Create();
|
||||
Result<IEnumerable<FileSystemItem>> emptyList = Result.From(Enumerable.Empty<FileSystemItem>());
|
||||
_mockDriveService.GetDrives()
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Empty(result.Value);
|
||||
_mockDriveService.Received(1).GetDrives();
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
|
||||
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;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetFileSystemQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetFileSystemQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IPlatformContextManager _mockPlatformContextManager;
|
||||
private readonly IPlatformContext _mockPlatformContext;
|
||||
private readonly GetFileSystemQueryHandler _sut;
|
||||
private readonly GetFileSystemQueryFixture _getFileSystemQueryFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetFileSystemQueryHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public GetFileSystemQueryHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockPlatformContextManager = Substitute.For<IPlatformContextManager>();
|
||||
_mockPlatformContext = Substitute.For<IPlatformContext>();
|
||||
_mockPlatformContextManager.GetCurrentContext().Returns(_mockPlatformContext);
|
||||
_sut = new GetFileSystemQueryHandler(_mockPlatformContextManager);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(PlatformType.Unix)]
|
||||
[InlineData(PlatformType.Windows)]
|
||||
public async Task HandleAsync_WhenCalled_ShouldReturnCorrectFileSystemTypeResponse(PlatformType platformType)
|
||||
{
|
||||
// Arrange
|
||||
GetFileSystemQuery query = _getFileSystemQueryFixture.Create();
|
||||
_mockPlatformContext.Platform.Returns(platformType);
|
||||
|
||||
// Act
|
||||
FileSystemTypeResponse result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(platformType, result.PlatformType);
|
||||
_mockPlatformContextManager.Received(1).GetCurrentContext();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalled_ShouldReturnValueTaskResult()
|
||||
{
|
||||
// Arrange
|
||||
GetFileSystemQuery query = _getFileSystemQueryFixture.Create();
|
||||
_mockPlatformContext.Platform.Returns(PlatformType.Unix);
|
||||
|
||||
// Act
|
||||
Task<FileSystemTypeResponse> resultTask = _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(resultTask.IsCompleted);
|
||||
FileSystemTypeResponse result = await resultTask;
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(PlatformType.Unix, result.PlatformType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalled_ShouldNotDependOnQueryContent()
|
||||
{
|
||||
// Arrange
|
||||
GetFileSystemQuery query1 = _getFileSystemQueryFixture.Create();
|
||||
GetFileSystemQuery query2 = _getFileSystemQueryFixture.Create();
|
||||
_mockPlatformContext.Platform.Returns(PlatformType.Windows);
|
||||
|
||||
// Act
|
||||
FileSystemTypeResponse result1 = await _sut.HandleAsync(query1, CancellationToken.None);
|
||||
FileSystemTypeResponse result2 = await _sut.HandleAsync(query2, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(result1.PlatformType, result2.PlatformType);
|
||||
_mockPlatformContextManager.Received(1).GetCurrentContext();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalled_ShouldIgnoreCancellationToken()
|
||||
{
|
||||
// Arrange
|
||||
GetFileSystemQuery query = _getFileSystemQueryFixture.Create();
|
||||
_mockPlatformContext.Platform.Returns(PlatformType.Unix);
|
||||
CancellationToken cancellationToken = new(true);
|
||||
|
||||
// Act & Assert
|
||||
Exception? exception = await Record.ExceptionAsync(async () =>
|
||||
await _sut.HandleAsync(query, cancellationToken));
|
||||
Assert.Null(exception);
|
||||
_mockPlatformContextManager.Received(1).GetCurrentContext();
|
||||
}
|
||||
}
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
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;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetFilesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetFilesQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IFileService _mockFileService;
|
||||
private readonly GetFilesQueryHandler _sut;
|
||||
private readonly FileFixture _fileFixture = new();
|
||||
private readonly GetFilesQueryFixture _getFilesQueryFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetFilesQueryHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public GetFilesQueryHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockFileService = Substitute.For<IFileService>();
|
||||
IValidator<GetFilesQuery> mockValidator = Substitute.For<IValidator<GetFilesQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetFilesQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetFilesQueryHandler(_mockFileService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithValidQueryWithoutHiddenFiles_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesQuery getFilesQuery = _getFilesQueryFixture.Create(shouldIncludeHiddenElements: false);
|
||||
|
||||
IEnumerable<File> files =
|
||||
[
|
||||
_fileFixture.Create(isHidden: true),
|
||||
_fileFixture.Create(isHidden: false)
|
||||
];
|
||||
|
||||
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements)
|
||||
.Returns(Result.From(files));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<FileResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.IsAssignableFrom<IEnumerable<FileResponse>>(result.Value);
|
||||
Assert.Equal(files.Count(), result.Value.Count());
|
||||
|
||||
List<FileResponse> resultList = [.. result.Value];
|
||||
List<File> filesList = [.. files];
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
Assert.Equal(filesList[i].Id.Path, resultList[i].Path);
|
||||
Assert.Equal(filesList[i].Name, resultList[i].Name);
|
||||
Assert.Equal(filesList[i].DateCreated.Value, resultList[i].DateCreated);
|
||||
Assert.Equal(filesList[i].DateModified.Value, resultList[i].DateModified);
|
||||
Assert.Equal(filesList[i].Size, resultList[i].Size);
|
||||
Assert.Equal(filesList[i].IsHidden, resultList[i].IsHidden);
|
||||
}
|
||||
|
||||
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithValidQueryWithHiddenFiles_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesQuery getFilesQuery = _getFilesQueryFixture.Create(shouldIncludeHiddenElements: true);
|
||||
|
||||
IEnumerable<File> files =
|
||||
[
|
||||
_fileFixture.Create(isHidden: true),
|
||||
_fileFixture.Create(isHidden: false)
|
||||
];
|
||||
|
||||
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements)
|
||||
.Returns(Result.From(files));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<FileResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.IsAssignableFrom<IEnumerable<FileResponse>>(result.Value);
|
||||
Assert.Equal(files.Count(), result.Value.Count());
|
||||
|
||||
List<FileResponse> resultList = [.. result.Value];
|
||||
List<File> filesList = [.. files];
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
Assert.Equal(filesList[i].Id.Path, resultList[i].Path);
|
||||
Assert.Equal(filesList[i].Name, resultList[i].Name);
|
||||
Assert.Equal(filesList[i].DateCreated.Value, resultList[i].DateCreated);
|
||||
Assert.Equal(filesList[i].DateModified.Value, resultList[i].DateModified);
|
||||
Assert.Equal(filesList[i].Size, resultList[i].Size);
|
||||
Assert.Equal(filesList[i].IsHidden, resultList[i].IsHidden);
|
||||
}
|
||||
|
||||
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenFileServiceReturnsError_ShouldReturnFailureResult()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesQuery query = _getFilesQueryFixture.Create();
|
||||
Error error = Error.Failure("FileService.Error", "An error occurred");
|
||||
_mockFileService.GetFiles(query.Path!, query.ShouldIncludeHiddenElements)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<FileResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
_mockFileService.Received(1).GetFiles(query.Path!, query.ShouldIncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenFileServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesQuery query = _getFilesQueryFixture.Create();
|
||||
Result<IEnumerable<File>> emptyList = Result.From(Enumerable.Empty<File>());
|
||||
_mockFileService.GetFiles(query.Path!, query.ShouldIncludeHiddenElements)
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<FileResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Empty(result.Value);
|
||||
_mockFileService.Received(1).GetFiles(query.Path!, query.ShouldIncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
#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.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetFilesQueryValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetFilesQueryValidatorTests
|
||||
{
|
||||
private readonly GetFilesQueryValidator _validator = new();
|
||||
private readonly GetFilesQueryFixture _getFilesQueryFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesQuery query = _getFilesQueryFixture.Create();
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesQuery query = _getFilesQueryFixture.Create();
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesQuery query = _getFilesQueryFixture.Create();
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesQuery query = _getFilesQueryFixture.Create();
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenShouldIncludeHiddenElementsIsTrue_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesQuery query = _getFilesQueryFixture.Create();
|
||||
query = query with { ShouldIncludeHiddenElements = true };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenShouldIncludeHiddenElementsIsFalse_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesQuery query = _getFilesQueryFixture.Create();
|
||||
query = query with { ShouldIncludeHiddenElements = false };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
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;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetTreeFilesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTreeFilesQueryHandlerTests
|
||||
{
|
||||
private readonly IFileService _mockFileService;
|
||||
private readonly GetTreeFilesQueryHandler _sut;
|
||||
private readonly FileFixture _fileFixture = new();
|
||||
private readonly GetTreeFilesQueryFixture _getTreeFilesQueryFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeFilesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
public GetTreeFilesQueryHandlerTests()
|
||||
{
|
||||
_mockFileService = Substitute.For<IFileService>();
|
||||
IValidator<GetTreeFilesQuery> mockValidator = Substitute.For<IValidator<GetTreeFilesQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetTreeFilesQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetTreeFilesQueryHandler(_mockFileService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithValidQueryWithoutHiddenFiles_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesQuery getFilesQuery = _getTreeFilesQueryFixture.Create(shouldIncludeHiddenElements: false);
|
||||
|
||||
IEnumerable<File> files =
|
||||
[
|
||||
_fileFixture.Create(isHidden: true),
|
||||
_fileFixture.Create(isHidden: false)
|
||||
];
|
||||
|
||||
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements)
|
||||
.Returns(Result.From(files));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.IsAssignableFrom<IEnumerable<FileSystemTreeNodeResponse>>(result.Value);
|
||||
Assert.Equal(files.Count(), result.Value.Count());
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = [.. result.Value];
|
||||
List<File> filesList = [.. files];
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
Assert.Equal(filesList[i].Id.Path, resultList[i].Path);
|
||||
Assert.Equal(filesList[i].Name, resultList[i].Name);
|
||||
Assert.Equal(FileSystemItemType.File, resultList[i].ItemType);
|
||||
Assert.Equal(filesList[i].IsHidden, resultList[i].IsHidden);
|
||||
Assert.False(resultList[i].IsExpanded);
|
||||
Assert.False(resultList[i].ChildrenLoaded);
|
||||
Assert.Empty(resultList[i].Children);
|
||||
}
|
||||
|
||||
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithValidQueryWithHiddenFiles_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesQuery getFilesQuery = _getTreeFilesQueryFixture.Create(shouldIncludeHiddenElements: true);
|
||||
|
||||
IEnumerable<File> files =
|
||||
[
|
||||
_fileFixture.Create(isHidden: true),
|
||||
_fileFixture.Create(isHidden: false)
|
||||
];
|
||||
|
||||
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements)
|
||||
.Returns(Result.From(files));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.IsAssignableFrom<IEnumerable<FileSystemTreeNodeResponse>>(result.Value);
|
||||
Assert.Equal(files.Count(), result.Value.Count());
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = [.. result.Value];
|
||||
List<File> filesList = [.. files];
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
Assert.Equal(filesList[i].Id.Path, resultList[i].Path);
|
||||
Assert.Equal(filesList[i].Name, resultList[i].Name);
|
||||
Assert.Equal(FileSystemItemType.File, resultList[i].ItemType);
|
||||
Assert.Equal(filesList[i].IsHidden, resultList[i].IsHidden);
|
||||
Assert.False(resultList[i].IsExpanded);
|
||||
Assert.False(resultList[i].ChildrenLoaded);
|
||||
Assert.Empty(resultList[i].Children);
|
||||
}
|
||||
|
||||
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenFileServiceReturnsError_ShouldReturnFailureResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
|
||||
Error error = Error.Failure("FileService.Error", "An error occurred");
|
||||
_mockFileService.GetFiles(query.Path!, query.ShouldIncludeHiddenElements)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
_mockFileService.Received(1).GetFiles(query.Path!, query.ShouldIncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenFileServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
|
||||
Result<IEnumerable<File>> emptyList = Result.From(Enumerable.Empty<File>());
|
||||
_mockFileService.GetFiles(query.Path!, query.ShouldIncludeHiddenElements)
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Empty(result.Value);
|
||||
_mockFileService.Received(1).GetFiles(query.Path!, query.ShouldIncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
#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.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetTreeFilesQueryValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTreeFilesQueryValidatorTests
|
||||
{
|
||||
private readonly GetTreeFilesQueryValidator _validator = new();
|
||||
private readonly GetTreeFilesQueryFixture _getTreeFilesQueryFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenShouldIncludeHiddenElementsIsTrue_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
|
||||
query = query with { ShouldIncludeHiddenElements = true };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenShouldIncludeHiddenElementsIsFalse_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesQuery query = _getTreeFilesQueryFixture.Create();
|
||||
query = query with { ShouldIncludeHiddenElements = false };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
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;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CombinePathCommandHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CombinePathCommandHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly CombinePathCommandHandler _sut;
|
||||
private readonly CombinePathCommandFixture _combinePathCommandFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CombinePathCommandHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public CombinePathCommandHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
IValidator<CombinePathCommand> mockValidator = Substitute.For<IValidator<CombinePathCommand>>();
|
||||
mockValidator.Validate(Arg.Any<CombinePathCommand>())
|
||||
.Returns([]);
|
||||
_sut = new CombinePathCommandHandler(_mockPathService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithValidCommand_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathCommand combinePathCommand = _combinePathCommandFixture.Create();
|
||||
string combinedPath = System.IO.Path.Combine(combinePathCommand.OriginalPath!, combinePathCommand.NewPath!);
|
||||
|
||||
_mockPathService.CombinePath(combinePathCommand.OriginalPath!, combinePathCommand.NewPath!)
|
||||
.Returns(Result.From(combinedPath));
|
||||
|
||||
// Act
|
||||
Result<PathSegmentResponse> result = await _sut.HandleAsync(combinePathCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.IsType<PathSegmentResponse>(result.Value);
|
||||
Assert.Equal(combinedPath, result.Value.Path);
|
||||
_mockPathService.Received(1).CombinePath(combinePathCommand.OriginalPath!, combinePathCommand.NewPath!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathServiceReturnsError_ShouldReturnFailureResult()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathCommand command = _combinePathCommandFixture.Create();
|
||||
Error error = Error.Failure("PathService.Error", "An error occurred");
|
||||
_mockPathService.CombinePath(command.OriginalPath!, command.NewPath!)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
Result<PathSegmentResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
_mockPathService.Received(1).CombinePath(command.OriginalPath!, command.NewPath!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathServiceReturnsEmptyString_ShouldReturnSuccessResultWithEmptyPath()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathCommand command = _combinePathCommandFixture.Create();
|
||||
_mockPathService.CombinePath(command.OriginalPath!, command.NewPath!)
|
||||
.Returns(Result.From(string.Empty));
|
||||
|
||||
// Act
|
||||
Result<PathSegmentResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.IsType<PathSegmentResponse>(result.Value);
|
||||
Assert.Empty(result.Value.Path);
|
||||
_mockPathService.Received(1).CombinePath(command.OriginalPath!, command.NewPath!);
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
#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.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CombinePathCommandValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CombinePathCommandValidatorTests
|
||||
{
|
||||
private readonly CombinePathCommandValidator _validator = new();
|
||||
private readonly CombinePathCommandFixture _combinePathCommandFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenOriginalPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathCommand command = _combinePathCommandFixture.Create();
|
||||
command = command with { OriginalPath = null! };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenOriginalPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathCommand command = _combinePathCommandFixture.Create();
|
||||
command = command with { OriginalPath = string.Empty };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenOriginalPathIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathCommand command = _combinePathCommandFixture.Create();
|
||||
command = command with { OriginalPath = " " };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNewPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathCommand command = _combinePathCommandFixture.Create();
|
||||
command = command with { NewPath = null! };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNewPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathCommand command = _combinePathCommandFixture.Create();
|
||||
command = command with { NewPath = string.Empty };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNewPathIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathCommand command = _combinePathCommandFixture.Create();
|
||||
command = command with { NewPath = " " };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenBothPathsAreValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathCommand command = _combinePathCommandFixture.Create();
|
||||
command = command with { OriginalPath = "/valid/path", NewPath = "new/segment" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
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;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="SplitPathCommandHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SplitPathCommandHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly SplitPathCommandHandler _sut;
|
||||
private readonly PathSegmentFixture _pathSegmentFixture = new();
|
||||
private readonly SplitPathCommandFixture _splitPathCommandFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SplitPathCommandHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public SplitPathCommandHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
IValidator<SplitPathCommand> mockValidator = Substitute.For<IValidator<SplitPathCommand>>();
|
||||
mockValidator.Validate(Arg.Any<SplitPathCommand>())
|
||||
.Returns([]);
|
||||
_sut = new SplitPathCommandHandler(_mockPathService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithValidCommand_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
SplitPathCommand splitPathCommand = _splitPathCommandFixture.Create();
|
||||
|
||||
IEnumerable<PathSegment> pathSegments = _pathSegmentFixture.CreateMany();
|
||||
|
||||
_mockPathService.ParsePath(splitPathCommand.Path!)
|
||||
.Returns(Result.From(pathSegments));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(splitPathCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.IsAssignableFrom<IEnumerable<PathSegmentResponse>>(result.Value);
|
||||
Assert.Equal(pathSegments.Count(), result.Value.Count());
|
||||
|
||||
List<PathSegmentResponse> resultList = [.. result.Value];
|
||||
List<PathSegment> segmentsList = [.. pathSegments];
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
Assert.Equal(segmentsList[i].Name, resultList[i].Path);
|
||||
_mockPathService.Received(1).ParsePath(splitPathCommand.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathServiceReturnsError_ShouldReturnFailureResult()
|
||||
{
|
||||
// Arrange
|
||||
SplitPathCommand command = _splitPathCommandFixture.Create();
|
||||
Error error = Error.Failure("PathService.Error", "An error occurred");
|
||||
_mockPathService.ParsePath(command.Path!)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
_mockPathService.Received(1).ParsePath(command.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
SplitPathCommand command = _splitPathCommandFixture.Create();
|
||||
Result<IEnumerable<PathSegment>> emptyList = Result.From(Enumerable.Empty<PathSegment>());
|
||||
_mockPathService.ParsePath(command.Path!)
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Empty(result.Value);
|
||||
_mockPathService.Received(1).ParsePath(command.Path!);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#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.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="SplitPathCommandValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SplitPathCommandValidatorTests
|
||||
{
|
||||
private readonly SplitPathCommandValidator _validator = new();
|
||||
private readonly SplitPathCommandFixture _splitPathCommandFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
SplitPathCommand command = _splitPathCommandFixture.Create();
|
||||
command = command with { Path = null! };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
SplitPathCommand command = _splitPathCommandFixture.Create();
|
||||
command = command with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
SplitPathCommand command = _splitPathCommandFixture.Create();
|
||||
command = command with { Path = " " };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
SplitPathCommand command = _splitPathCommandFixture.Create();
|
||||
command = command with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
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;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CheckPathExistsQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CheckPathExistsQueryHandlerTests
|
||||
{
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly CheckPathExistsQueryHandler _sut;
|
||||
private readonly CheckPathExistsQueryFixture _checkPathExistsQueryFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CheckPathExistsQueryHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public CheckPathExistsQueryHandlerTests()
|
||||
{
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
IValidator<CheckPathExistsQuery> mockValidator = Substitute.For<IValidator<CheckPathExistsQuery>>();
|
||||
mockValidator.Validate(Arg.Any<CheckPathExistsQuery>())
|
||||
.Returns([]);
|
||||
_sut = new CheckPathExistsQueryHandler(_mockPathService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathExistsAndIsNotHidden_ShouldReturnTrueResponse()
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
|
||||
_mockPathService.Exists(query.Path!).Returns(true);
|
||||
|
||||
// Act
|
||||
Result<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.True(result.Value.Exists);
|
||||
_mockPathService.Received(1).Exists(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathExistsAndIsHiddenAndShouldIncludeHiddenElementsIsTrue_ShouldReturnTrueResponse()
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create(shouldIncludeHiddenElements: true);
|
||||
_mockPathService.Exists(query.Path!).Returns(true);
|
||||
|
||||
// Act
|
||||
Result<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.True(result.Value.Exists);
|
||||
_mockPathService.Received(1).Exists(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathExistsAndIsHiddenAndShouldIncludeHiddenElementsIsFalse_ShouldReturnFalseResponse()
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create(shouldIncludeHiddenElements: false);
|
||||
_mockPathService.Exists(query.Path!, false).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.Exists);
|
||||
_mockPathService.Received(1).Exists(query.Path!, false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathDoesNotExist_ShouldReturnFalseResponse()
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
|
||||
_mockPathService.Exists(query.Path!).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.Exists);
|
||||
_mockPathService.Received(1).Exists(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithNullPath_ShouldStillCallPathService()
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create(includePath: false, shouldIncludeHiddenElements: false);
|
||||
_mockPathService.Exists(Arg.Any<string>(), Arg.Any<bool>()).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.Exists);
|
||||
_mockPathService.Received(1).Exists(Arg.Any<string>(), Arg.Any<bool>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCancellationRequested_ShouldStillCompleteOperation()
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
|
||||
_mockPathService.Exists(query.Path!).Returns(true);
|
||||
CancellationToken cancellationToken = new(true);
|
||||
|
||||
// Act
|
||||
Result<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.True(result.Value.Exists);
|
||||
_mockPathService.Received(1).Exists(query.Path!);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#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.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CheckPathExistsQueryValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CheckPathExistsQueryValidatorTests
|
||||
{
|
||||
private readonly CheckPathExistsQueryValidator _validator = new();
|
||||
private readonly CheckPathExistsQueryFixture _checkPathExistsQueryFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = _checkPathExistsQueryFixture.Create();
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Path;
|
||||
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;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPathParentQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathParentQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly GetPathParentQueryHandler _sut;
|
||||
private readonly PathSegmentFixture _pathSegmentFixture = new();
|
||||
private readonly GetPathParentQueryFixture _getPathParentQueryFixture = new();
|
||||
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture = new();
|
||||
|
||||
public GetPathParentQueryHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
IValidator<GetPathParentQuery> mockValidator = Substitute.For<IValidator<GetPathParentQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetPathParentQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetPathParentQueryHandler(_mockPathService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithValidQuery_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentQuery query = _getPathParentQueryFixture.Create();
|
||||
|
||||
IEnumerable<PathSegment> pathSegments = _pathSegmentFixture.CreateMany();
|
||||
|
||||
// Create PathSegmentResponses based on the PathSegments.
|
||||
IEnumerable<PathSegmentResponse> pathSegmentResponses = pathSegments.Select(segment => _pathSegmentResponseFixture.Create(path: segment.Name));
|
||||
|
||||
_mockPathService.GoUpOneLevel(query.Path!)
|
||||
.Returns(Result.From(pathSegments));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.IsType<IEnumerable<PathSegmentResponse>>(result.Value, exactMatch: false);
|
||||
Assert.Equal(pathSegmentResponses, result.Value);
|
||||
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathServiceReturnsError_ShouldReturnFailureResult()
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentQuery query = _getPathParentQueryFixture.Create();
|
||||
Error error = Error.Failure("PathService.Error", "An error occurred");
|
||||
_mockPathService.GoUpOneLevel(query.Path!)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentQuery query = _getPathParentQueryFixture.Create();
|
||||
Result<IEnumerable<PathSegment>> emptyList = Result.From(Enumerable.Empty<PathSegment>());
|
||||
_mockPathService.GoUpOneLevel(query.Path!)
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Empty(result.Value);
|
||||
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#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.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPathParentQueryValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathParentQueryValidatorTests
|
||||
{
|
||||
private readonly GetPathParentQueryValidator _validator = new();
|
||||
private readonly GetPathParentQueryFixture _getPathParentQueryFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentQuery query = _getPathParentQueryFixture.Create();
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentQuery query = _getPathParentQueryFixture.Create();
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentQuery query = _getPathParentQueryFixture.Create();
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentQuery query = _getPathParentQueryFixture.Create();
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
|
||||
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.Paths.Queries.GetPathRoot;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPathRootQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathRootQueryHandlerTests
|
||||
{
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly GetPathRootQueryHandler _sut;
|
||||
private readonly PathSegmentFixture _pathSegmentFixture = new();
|
||||
private readonly GetPathRootQueryFixture _getPathRootQueryFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPathRootQueryHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public GetPathRootQueryHandlerTests()
|
||||
{
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
IValidator<GetPathRootQuery> mockValidator = Substitute.For<IValidator<GetPathRootQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetPathRootQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetPathRootQueryHandler(_mockPathService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithValidQuery_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootQuery query = _getPathRootQueryFixture.Create();
|
||||
PathSegment pathSegment = _pathSegmentFixture.Create(isDrive: true);
|
||||
|
||||
_mockPathService.GetPathRoot(query.Path!)
|
||||
.Returns(Result.From(pathSegment));
|
||||
|
||||
// Act
|
||||
Result<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(pathSegment.Name, result.Value.Path);
|
||||
_mockPathService.Received(1).GetPathRoot(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathServiceReturnsError_ShouldReturnFailureResult()
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootQuery query = _getPathRootQueryFixture.Create();
|
||||
Error error = Error.Failure("PathService.Error", "An error occurred");
|
||||
_mockPathService.GetPathRoot(query.Path!)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
Result<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
_mockPathService.Received(1).GetPathRoot(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenPathServiceReturnsRootPathSegment_ShouldReturnRootSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootQuery query = _getPathRootQueryFixture.Create();
|
||||
PathSegment rootPathSegment = _pathSegmentFixture.Create(name: "/", isDirectory: true, isDrive: true);
|
||||
|
||||
_mockPathService.GetPathRoot(query.Path!)
|
||||
.Returns(Result.From(rootPathSegment));
|
||||
|
||||
// Act
|
||||
Result<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal("/", result.Value.Path);
|
||||
_mockPathService.Received(1).GetPathRoot(query.Path!);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#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.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPathRootQueryValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathRootQueryValidatorTests
|
||||
{
|
||||
private readonly GetPathRootQueryValidator _validator = new();
|
||||
private readonly GetPathRootQueryFixture _getPathRootQueryFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootQuery query = _getPathRootQueryFixture.Create();
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootQuery query = _getPathRootQueryFixture.Create();
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootQuery query = _getPathRootQueryFixture.Create();
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootQuery query = _getPathRootQueryFixture.Create();
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathSeparator;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.GetPathSeparator;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPathSeparatorQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathSeparatorQueryHandlerTests
|
||||
{
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly GetPathSeparatorQueryHandler _sut;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPathSeparatorQueryHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public GetPathSeparatorQueryHandlerTests()
|
||||
{
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
_sut = new GetPathSeparatorQueryHandler(_mockPathService);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalled_ShouldReturnPathSeparatorResponse()
|
||||
{
|
||||
// Arrange
|
||||
GetPathSeparatorQuery query = new();
|
||||
char expectedSeparator = System.IO.Path.DirectorySeparatorChar;
|
||||
_mockPathService.PathSeparator.Returns(expectedSeparator);
|
||||
|
||||
// Act
|
||||
PathSeparatorResponse result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(expectedSeparator.ToString(), result.Separator);
|
||||
|
||||
_mockPathService.Received(1);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData('/')]
|
||||
[InlineData('\\')]
|
||||
public async Task Handle_WithDifferentSeparators_ShouldReturnCorrectSeparator(char separator)
|
||||
{
|
||||
// Arrange
|
||||
GetPathSeparatorQuery query = new();
|
||||
_mockPathService.PathSeparator.Returns(separator);
|
||||
|
||||
// Act
|
||||
PathSeparatorResponse result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(separator.ToString(), result.Separator);
|
||||
_mockPathService.Received(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledMultipleTimes_ShouldReturnSameResult()
|
||||
{
|
||||
// Arrange
|
||||
GetPathSeparatorQuery query = new();
|
||||
char expectedSeparator = System.IO.Path.DirectorySeparatorChar;
|
||||
_mockPathService.PathSeparator.Returns(expectedSeparator);
|
||||
|
||||
// Act
|
||||
PathSeparatorResponse result1 = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
PathSeparatorResponse result2 = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(result1, result2);
|
||||
_mockPathService.Received(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WithCancellationToken_ShouldCompleteSuccessfully()
|
||||
{
|
||||
// Arrange
|
||||
GetPathSeparatorQuery query = new();
|
||||
using CancellationTokenSource cts = new();
|
||||
|
||||
// Act
|
||||
Exception? exception = await Record.ExceptionAsync(
|
||||
async () => await _sut.HandleAsync(query, cts.Token)
|
||||
);
|
||||
|
||||
// Assert
|
||||
Assert.Null(exception);
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
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;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ValidatePathQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ValidatePathQueryHandlerTests
|
||||
{
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly IValidator<ValidatePathQuery> _mockValidator;
|
||||
private readonly ValidatePathQueryHandler _sut;
|
||||
private readonly ValidatePathQueryFixture _validatePathQueryFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ValidatePathQueryHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public ValidatePathQueryHandlerTests()
|
||||
{
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
_mockValidator = Substitute.For<IValidator<ValidatePathQuery>>();
|
||||
_mockValidator.Validate(Arg.Any<ValidatePathQuery>())
|
||||
.Returns([]);
|
||||
_sut = new ValidatePathQueryHandler(_mockPathService, _mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithValidPath_ShouldReturnTrueResponse()
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathQuery query = _validatePathQueryFixture.Create();
|
||||
_mockPathService.IsValidPath(query.Path!).Returns(true);
|
||||
|
||||
// Act
|
||||
Result<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.True(result.Value.IsValid);
|
||||
_mockPathService.Received(1).IsValidPath(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithInvalidPath_ShouldReturnFalseResponse()
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathQuery query = _validatePathQueryFixture.Create();
|
||||
_mockPathService.IsValidPath(query.Path!).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.IsValid);
|
||||
_mockPathService.Received(1).IsValidPath(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithNullPath_ShouldReturnFalseResponse()
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathQuery query = _validatePathQueryFixture.Create(includePath: false);
|
||||
_mockPathService.IsValidPath(Arg.Any<string>()).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.IsValid);
|
||||
_mockPathService.Received(1).IsValidPath(Arg.Any<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithEmptyPath_ShouldReturnFalseResponse()
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathQuery query = _validatePathQueryFixture.Create(string.Empty);
|
||||
_mockPathService.IsValidPath(Arg.Any<string>()).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.IsValid);
|
||||
_mockPathService.Received(1).IsValidPath(Arg.Any<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenValidatorReturnsErrors_ShouldReturnValidationErrorsWithoutCallingPathService()
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathQuery query = _validatePathQueryFixture.Create();
|
||||
_mockValidator.Validate(query)
|
||||
.Returns([Errors.FileSystemManagement.PathCannotBeEmpty]);
|
||||
|
||||
// Act
|
||||
Result<PathValidResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.FileSystemManagement.PathCannotBeEmpty, result.FirstError);
|
||||
_mockPathService.DidNotReceive().IsValidPath(Arg.Any<string>());
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#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.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ValidatePathQueryValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ValidatePathQueryValidatorTests
|
||||
{
|
||||
private readonly ValidatePathQueryValidator _validator = new();
|
||||
private readonly ValidatePathQueryFixture _validatePathQueryFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathQuery query = _validatePathQueryFixture.Create();
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathQuery query = _validatePathQueryFixture.Create();
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsWhitespace_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathQuery query = _validatePathQueryFixture.Create();
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathQuery query = _validatePathQueryFixture.Create();
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
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;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetThumbnailQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThumbnailQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IThumbnailService _mockThumbnailService;
|
||||
private readonly GetThumbnailQueryHandler _sut;
|
||||
private readonly GetThumbnailQueryFixture _getThumbnailQueryFixture = new();
|
||||
private readonly ThumbnailFixture _thumbnailFixture = new();
|
||||
|
||||
public GetThumbnailQueryHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockThumbnailService = Substitute.For<IThumbnailService>();
|
||||
IValidator<GetThumbnailQuery> mockValidator = Substitute.For<IValidator<GetThumbnailQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetThumbnailQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetThumbnailQueryHandler(_mockThumbnailService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCalledWithValidQuery_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = _getThumbnailQueryFixture.Create();
|
||||
Thumbnail thumbnail = _thumbnailFixture.Create();
|
||||
|
||||
_mockThumbnailService.GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(thumbnail));
|
||||
|
||||
// Act
|
||||
Result<ThumbnailResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(thumbnail.Type, result.Value.Type);
|
||||
Assert.Equal(thumbnail.Bytes, result.Value.Bytes);
|
||||
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenThumbnailServiceReturnsError_ShouldReturnFailureResult()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = _getThumbnailQueryFixture.Create();
|
||||
Error error = Error.Failure("ThumbnailService.Error", "An error occurred");
|
||||
_mockThumbnailService.GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
Result<ThumbnailResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenCancellationRequested_ShouldCancelOperation()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = _getThumbnailQueryFixture.Create();
|
||||
CancellationTokenSource cts = new();
|
||||
cts.Cancel();
|
||||
|
||||
_mockThumbnailService.GetThumbnailAsync(query.Path!, query.Quality, cts.Token)
|
||||
.Returns(Task.FromCanceled<Result<Thumbnail>>(cts.Token));
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<TaskCanceledException>(() => _sut.HandleAsync(query, cts.Token));
|
||||
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path!, query.Quality, cts.Token);
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Application.Fixtures.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetThumbnailQueryValidator"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThumbnailQueryValidatorTests
|
||||
{
|
||||
private readonly GetThumbnailQueryValidator _validator = new();
|
||||
private readonly GetThumbnailQueryFixture _getThumbnailQueryFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsNull_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = _getThumbnailQueryFixture.Create(includePath: false, quality: 1);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(DomainErrors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = _getThumbnailQueryFixture.Create(string.Empty, 1);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(DomainErrors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPathIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = _getThumbnailQueryFixture.Create("test", 1);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(DomainErrors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenQualityIsNegative_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = _getThumbnailQueryFixture.Create("test", -1);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(ApplicationErrors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenQualityIsOver100_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = _getThumbnailQueryFixture.Create("test", 101);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(ApplicationErrors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenQualityIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailQuery query = _getThumbnailQueryFixture.Create("test", 1);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(ApplicationErrors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user