Replaces FluentValidation and Mediator command/queries handling with custom implementations.

This commit is contained in:
BinaryAlley committed 2026-08-13 08:53:06 -07:00
1 parent 9a5c7473f9
commit 2d1c6b1ab8
297 files changed
+3619 -3045

No files matched your search

@@ -8,6 +8,7 @@ using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -37,7 +38,10 @@ public class GetDirectoriesQueryHandlerTests
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockDirectoryService = Substitute.For<IDirectoryService>();
_sut = new GetDirectoriesQueryHandler(_mockDirectoryService);
IValidator<GetDirectoriesQuery> mockValidator = Substitute.For<IValidator<GetDirectoriesQuery>>();
mockValidator.Validate(Arg.Any<GetDirectoriesQuery>())
.Returns([]);
_sut = new GetDirectoriesQueryHandler(_mockDirectoryService, mockValidator);
_directoryFixture = new DirectoryFixture();
}
@@ -53,7 +57,7 @@ public class GetDirectoriesQueryHandlerTests
.Returns(ErrorOrFactory.From(directories));
// Act
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(getDirectoriesQuery, CancellationToken.None);
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(getDirectoriesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -87,7 +91,7 @@ public class GetDirectoriesQueryHandlerTests
.Returns(ErrorOrFactory.From(directories));
// Act
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(getDirectoriesQuery, CancellationToken.None);
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(getDirectoriesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -119,7 +123,7 @@ public class GetDirectoriesQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
@@ -137,7 +141,7 @@ public class GetDirectoriesQueryHandlerTests
.Returns(emptyList);
// Act
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -1,7 +1,9 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation.TestHelper;
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories.Fixtures;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
@@ -32,11 +34,10 @@ public class GetDirectoriesQueryValidatorTests
query = query with { Path = null! };
// Act
TestValidationResult<GetDirectoriesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -47,11 +48,10 @@ public class GetDirectoriesQueryValidatorTests
query = query with { Path = string.Empty };
// Act
TestValidationResult<GetDirectoriesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -62,11 +62,10 @@ public class GetDirectoriesQueryValidatorTests
query = query with { Path = " " };
// Act
TestValidationResult<GetDirectoriesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -77,10 +76,10 @@ public class GetDirectoriesQueryValidatorTests
query = query with { Path = "/valid/path" };
// Act
TestValidationResult<GetDirectoriesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.Path);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -91,10 +90,10 @@ public class GetDirectoriesQueryValidatorTests
query = query with { IncludeHiddenElements = true };
// Act
TestValidationResult<GetDirectoriesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.IncludeHiddenElements);
result.ShouldNotHaveAnyValidationErrors();
}
[Fact]
@@ -105,9 +104,9 @@ public class GetDirectoriesQueryValidatorTests
query = query with { IncludeHiddenElements = false };
// Act
TestValidationResult<GetDirectoriesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.IncludeHiddenElements);
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -54,7 +54,7 @@ public class GetDrivesQueryHandlerTests
.Returns(ErrorOrFactory.From(drives));
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getDrivesQuery, CancellationToken.None);
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getDrivesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -90,7 +90,7 @@ public class GetDrivesQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
@@ -108,7 +108,7 @@ public class GetDrivesQueryHandlerTests
.Returns(emptyList);
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -47,7 +47,7 @@ public class GetFileSystemQueryHandlerTests
_mockPlatformContext.Platform.Returns(platformType);
// Act
FileSystemTypeResponse result = await _sut.Handle(query, CancellationToken.None);
FileSystemTypeResponse result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.NotNull(result);
@@ -63,7 +63,7 @@ public class GetFileSystemQueryHandlerTests
_mockPlatformContext.Platform.Returns(PlatformType.Unix);
// Act
ValueTask<FileSystemTypeResponse> resultTask = _sut.Handle(query, CancellationToken.None);
Task<FileSystemTypeResponse> resultTask = _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(resultTask.IsCompleted);
@@ -81,8 +81,8 @@ public class GetFileSystemQueryHandlerTests
_mockPlatformContext.Platform.Returns(PlatformType.Windows);
// Act
FileSystemTypeResponse result1 = await _sut.Handle(query1, CancellationToken.None);
FileSystemTypeResponse result2 = await _sut.Handle(query2, CancellationToken.None);
FileSystemTypeResponse result1 = await _sut.HandleAsync(query1, CancellationToken.None);
FileSystemTypeResponse result2 = await _sut.HandleAsync(query2, CancellationToken.None);
// Assert
Assert.Equal(result1.PlatformType, result2.PlatformType);
@@ -99,7 +99,7 @@ public class GetFileSystemQueryHandlerTests
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _sut.Handle(query, cancellationToken));
await _sut.HandleAsync(query, cancellationToken));
Assert.Null(exception);
_mockPlatformContextManager.Received(1).GetCurrentContext();
}
@@ -8,6 +8,7 @@ using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFi
using Lumina.Contracts.Responses.FileSystemManagement.Files;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -37,7 +38,10 @@ public class GetFilesQueryHandlerTests
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockFileService = Substitute.For<IFileService>();
_sut = new GetFilesQueryHandler(_mockFileService);
IValidator<GetFilesQuery> mockValidator = Substitute.For<IValidator<GetFilesQuery>>();
mockValidator.Validate(Arg.Any<GetFilesQuery>())
.Returns([]);
_sut = new GetFilesQueryHandler(_mockFileService, mockValidator);
_fileFixture = new FileFixture();
}
@@ -53,7 +57,7 @@ public class GetFilesQueryHandlerTests
.Returns(ErrorOrFactory.From(files));
// Act
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
ErrorOr<IEnumerable<FileResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -87,7 +91,7 @@ public class GetFilesQueryHandlerTests
.Returns(ErrorOrFactory.From(files));
// Act
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
ErrorOr<IEnumerable<FileResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -119,7 +123,7 @@ public class GetFilesQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<IEnumerable<FileResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
@@ -137,7 +141,7 @@ public class GetFilesQueryHandlerTests
.Returns(emptyList);
// Act
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<IEnumerable<FileResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -1,8 +1,10 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation.TestHelper;
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -32,11 +34,10 @@ public class GetFilesQueryValidatorTests
query = query with { Path = null! };
// Act
TestValidationResult<GetFilesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -47,11 +48,10 @@ public class GetFilesQueryValidatorTests
query = query with { Path = string.Empty };
// Act
TestValidationResult<GetFilesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -62,11 +62,10 @@ public class GetFilesQueryValidatorTests
query = query with { Path = " " };
// Act
TestValidationResult<GetFilesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -77,10 +76,10 @@ public class GetFilesQueryValidatorTests
query = query with { Path = "/valid/path" };
// Act
TestValidationResult<GetFilesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.Path);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -91,10 +90,10 @@ public class GetFilesQueryValidatorTests
query = query with { IncludeHiddenElements = true };
// Act
TestValidationResult<GetFilesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.IncludeHiddenElements);
result.ShouldNotHaveAnyValidationErrors();
}
[Fact]
@@ -105,9 +104,9 @@ public class GetFilesQueryValidatorTests
query = query with { IncludeHiddenElements = false };
// Act
TestValidationResult<GetFilesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.IncludeHiddenElements);
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -9,6 +9,7 @@ using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -37,7 +38,10 @@ public class GetTreeFilesQueryHandlerTests
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockFileService = Substitute.For<IFileService>();
_sut = new GetTreeFilesQueryHandler(_mockFileService);
IValidator<GetTreeFilesQuery> mockValidator = Substitute.For<IValidator<GetTreeFilesQuery>>();
mockValidator.Validate(Arg.Any<GetTreeFilesQuery>())
.Returns([]);
_sut = new GetTreeFilesQueryHandler(_mockFileService, mockValidator);
_fileFixture = new FileFixture();
}
@@ -53,7 +57,7 @@ public class GetTreeFilesQueryHandlerTests
.Returns(ErrorOrFactory.From(files));
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -88,7 +92,7 @@ public class GetTreeFilesQueryHandlerTests
.Returns(ErrorOrFactory.From(files));
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -121,7 +125,7 @@ public class GetTreeFilesQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
@@ -139,7 +143,7 @@ public class GetTreeFilesQueryHandlerTests
.Returns(emptyList);
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -1,8 +1,10 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation.TestHelper;
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -32,11 +34,10 @@ public class GetTreeFilesQueryValidatorTests
query = query with { Path = null! };
// Act
TestValidationResult<GetTreeFilesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -47,11 +48,10 @@ public class GetTreeFilesQueryValidatorTests
query = query with { Path = string.Empty };
// Act
TestValidationResult<GetTreeFilesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -62,11 +62,10 @@ public class GetTreeFilesQueryValidatorTests
query = query with { Path = " " };
// Act
TestValidationResult<GetTreeFilesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -77,10 +76,10 @@ public class GetTreeFilesQueryValidatorTests
query = query with { Path = "/valid/path" };
// Act
TestValidationResult<GetTreeFilesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.Path);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -91,10 +90,10 @@ public class GetTreeFilesQueryValidatorTests
query = query with { IncludeHiddenElements = true };
// Act
TestValidationResult<GetTreeFilesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.IncludeHiddenElements);
result.ShouldNotHaveAnyValidationErrors();
}
[Fact]
@@ -105,9 +104,9 @@ public class GetTreeFilesQueryValidatorTests
query = query with { IncludeHiddenElements = false };
// Act
TestValidationResult<GetTreeFilesQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.IncludeHiddenElements);
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -6,6 +6,7 @@ using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
@@ -31,7 +32,10 @@ public class CombinePathCommandHandlerTests
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockPathService = Substitute.For<IPathService>();
_sut = new CombinePathCommandHandler(_mockPathService);
IValidator<CombinePathCommand> mockValidator = Substitute.For<IValidator<CombinePathCommand>>();
mockValidator.Validate(Arg.Any<CombinePathCommand>())
.Returns([]);
_sut = new CombinePathCommandHandler(_mockPathService, mockValidator);
}
[Fact]
@@ -45,7 +49,7 @@ public class CombinePathCommandHandlerTests
.Returns(ErrorOrFactory.From(combinedPath));
// Act
ErrorOr<PathSegmentResponse> result = await _sut.Handle(combinePathCommand, CancellationToken.None);
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(combinePathCommand, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -64,7 +68,7 @@ public class CombinePathCommandHandlerTests
.Returns(error);
// Act
ErrorOr<PathSegmentResponse> result = await _sut.Handle(command, CancellationToken.None);
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
@@ -81,7 +85,7 @@ public class CombinePathCommandHandlerTests
.Returns(ErrorOrFactory.From(string.Empty));
// Act
ErrorOr<PathSegmentResponse> result = await _sut.Handle(command, CancellationToken.None);
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -1,8 +1,10 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation.TestHelper;
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -32,11 +34,10 @@ public class CombinePathCommandValidatorTests
command = command with { OriginalPath = null! };
// Act
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationErrorFor(x => x.OriginalPath)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -47,11 +48,10 @@ public class CombinePathCommandValidatorTests
command = command with { OriginalPath = string.Empty };
// Act
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationErrorFor(x => x.OriginalPath)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -62,11 +62,10 @@ public class CombinePathCommandValidatorTests
command = command with { OriginalPath = " " };
// Act
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationErrorFor(x => x.OriginalPath)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -77,11 +76,10 @@ public class CombinePathCommandValidatorTests
command = command with { NewPath = null! };
// Act
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationErrorFor(x => x.NewPath)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -92,11 +90,10 @@ public class CombinePathCommandValidatorTests
command = command with { NewPath = string.Empty };
// Act
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationErrorFor(x => x.NewPath)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -107,11 +104,10 @@ public class CombinePathCommandValidatorTests
command = command with { NewPath = " " };
// Act
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationErrorFor(x => x.NewPath)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -122,10 +118,10 @@ public class CombinePathCommandValidatorTests
command = command with { OriginalPath = "/valid/path", NewPath = "new/segment" };
// Act
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.OriginalPath);
result.ShouldNotHaveValidationErrorFor(x => x.NewPath);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
}
@@ -8,6 +8,7 @@ using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System;
using System.Collections.Generic;
@@ -37,7 +38,10 @@ public class SplitPathCommandHandlerTests
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockPathService = Substitute.For<IPathService>();
_sut = new SplitPathCommandHandler(_mockPathService);
IValidator<SplitPathCommand> mockValidator = Substitute.For<IValidator<SplitPathCommand>>();
mockValidator.Validate(Arg.Any<SplitPathCommand>())
.Returns([]);
_sut = new SplitPathCommandHandler(_mockPathService, mockValidator);
_pathSegmentFixture = new PathSegmentFixture();
}
@@ -53,7 +57,7 @@ public class SplitPathCommandHandlerTests
.Returns(ErrorOrFactory.From(pathSegments));
// Act
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(splitPathCommand, CancellationToken.None);
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(splitPathCommand, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -78,7 +82,7 @@ public class SplitPathCommandHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(command, CancellationToken.None);
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.True(result.IsError);
@@ -96,7 +100,7 @@ public class SplitPathCommandHandlerTests
.Returns(emptyList);
// Act
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(command, CancellationToken.None);
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(command, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -1,8 +1,10 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation.TestHelper;
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -32,11 +34,10 @@ public class SplitPathCommandValidatorTests
command = command with { Path = null! };
// Act
TestValidationResult<SplitPathCommand> result = _validator.TestValidate(command);
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -47,11 +48,10 @@ public class SplitPathCommandValidatorTests
command = command with { Path = string.Empty };
// Act
TestValidationResult<SplitPathCommand> result = _validator.TestValidate(command);
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -62,11 +62,10 @@ public class SplitPathCommandValidatorTests
command = command with { Path = " " };
// Act
TestValidationResult<SplitPathCommand> result = _validator.TestValidate(command);
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -77,9 +76,9 @@ public class SplitPathCommandValidatorTests
command = command with { Path = "/valid/path" };
// Act
TestValidationResult<SplitPathCommand> result = _validator.TestValidate(command);
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.Path);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
}
@@ -4,6 +4,7 @@ using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
@@ -27,7 +28,10 @@ public class CheckPathExistsQueryHandlerTests
public CheckPathExistsQueryHandlerTests()
{
_mockPathService = Substitute.For<IPathService>();
_sut = new CheckPathExistsQueryHandler(_mockPathService);
IValidator<CheckPathExistsQuery> mockValidator = Substitute.For<IValidator<CheckPathExistsQuery>>();
mockValidator.Validate(Arg.Any<CheckPathExistsQuery>())
.Returns([]);
_sut = new CheckPathExistsQueryHandler(_mockPathService, mockValidator);
}
[Fact]
@@ -38,7 +42,7 @@ public class CheckPathExistsQueryHandlerTests
_mockPathService.Exists(query.Path!).Returns(true);
// Act
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -54,7 +58,7 @@ public class CheckPathExistsQueryHandlerTests
_mockPathService.Exists(query.Path!).Returns(true);
// Act
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -70,7 +74,7 @@ public class CheckPathExistsQueryHandlerTests
_mockPathService.Exists(query.Path!, false).Returns(false);
// Act
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -86,7 +90,7 @@ public class CheckPathExistsQueryHandlerTests
_mockPathService.Exists(query.Path!).Returns(false);
// Act
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -102,7 +106,7 @@ public class CheckPathExistsQueryHandlerTests
_mockPathService.Exists(Arg.Any<string>(), Arg.Any<bool>()).Returns(false);
// Act
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -119,7 +123,7 @@ public class CheckPathExistsQueryHandlerTests
CancellationToken cancellationToken = new(true);
// Act
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -1,8 +1,10 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation.TestHelper;
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -32,11 +34,10 @@ public class CheckPathExistsQueryValidatorTests
query = query with { Path = null! };
// Act
TestValidationResult<CheckPathExistsQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -47,11 +48,10 @@ public class CheckPathExistsQueryValidatorTests
query = query with { Path = string.Empty };
// Act
TestValidationResult<CheckPathExistsQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -62,11 +62,10 @@ public class CheckPathExistsQueryValidatorTests
query = query with { Path = " " };
// Act
TestValidationResult<CheckPathExistsQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -77,9 +76,9 @@ public class CheckPathExistsQueryValidatorTests
query = query with { Path = "/valid/path" };
// Act
TestValidationResult<CheckPathExistsQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.Path);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
}
@@ -8,6 +8,7 @@ using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPat
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -33,7 +34,10 @@ public class GetPathParentQueryHandlerTests
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockPathService = Substitute.For<IPathService>();
_sut = new GetPathParentQueryHandler(_mockPathService);
IValidator<GetPathParentQuery> mockValidator = Substitute.For<IValidator<GetPathParentQuery>>();
mockValidator.Validate(Arg.Any<GetPathParentQuery>())
.Returns([]);
_sut = new GetPathParentQueryHandler(_mockPathService, mockValidator);
_pathSegmentFixture = new PathSegmentFixture();
}
@@ -52,7 +56,7 @@ public class GetPathParentQueryHandlerTests
.Returns(ErrorOrFactory.From(pathSegments));
// Act
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -71,7 +75,7 @@ public class GetPathParentQueryHandlerTests
.Returns(error);
// Act
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
@@ -89,7 +93,7 @@ public class GetPathParentQueryHandlerTests
.Returns(emptyList);
// Act
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -1,8 +1,10 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation.TestHelper;
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -32,11 +34,10 @@ public class GetPathParentQueryValidatorTests
query = query with { Path = null! };
// Act
TestValidationResult<GetPathParentQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -47,11 +48,10 @@ public class GetPathParentQueryValidatorTests
query = query with { Path = string.Empty };
// Act
TestValidationResult<GetPathParentQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -62,11 +62,10 @@ public class GetPathParentQueryValidatorTests
query = query with { Path = " " };
// Act
TestValidationResult<GetPathParentQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -77,9 +76,9 @@ public class GetPathParentQueryValidatorTests
query = query with { Path = "/valid/path" };
// Act
TestValidationResult<GetPathParentQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.Path);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
}
@@ -6,6 +6,7 @@ using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPat
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
@@ -30,7 +31,10 @@ public class GetPathRootQueryHandlerTests
public GetPathRootQueryHandlerTests()
{
_mockPathService = Substitute.For<IPathService>();
_sut = new GetPathRootQueryHandler(_mockPathService);
IValidator<GetPathRootQuery> mockValidator = Substitute.For<IValidator<GetPathRootQuery>>();
mockValidator.Validate(Arg.Any<GetPathRootQuery>())
.Returns([]);
_sut = new GetPathRootQueryHandler(_mockPathService, mockValidator);
_pathSegmentFixture = new PathSegmentFixture();
}
@@ -45,7 +49,7 @@ public class GetPathRootQueryHandlerTests
.Returns(ErrorOrFactory.From(pathSegment));
// Act
ErrorOr<PathSegmentResponse> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -64,7 +68,7 @@ public class GetPathRootQueryHandlerTests
.Returns(error);
// Act
ErrorOr<PathSegmentResponse> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
@@ -83,7 +87,7 @@ public class GetPathRootQueryHandlerTests
.Returns(ErrorOrFactory.From(rootPathSegment));
// Act
ErrorOr<PathSegmentResponse> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -1,8 +1,10 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation.TestHelper;
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -32,11 +34,10 @@ public class GetPathRootQueryValidatorTests
query = query with { Path = null! };
// Act
TestValidationResult<GetPathRootQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -47,11 +48,10 @@ public class GetPathRootQueryValidatorTests
query = query with { Path = string.Empty };
// Act
TestValidationResult<GetPathRootQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -62,11 +62,10 @@ public class GetPathRootQueryValidatorTests
query = query with { Path = " " };
// Act
TestValidationResult<GetPathRootQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -77,9 +76,9 @@ public class GetPathRootQueryValidatorTests
query = query with { Path = "/valid/path" };
// Act
TestValidationResult<GetPathRootQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.Path);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
}
@@ -38,7 +38,7 @@ public class GetPathSeparatorQueryHandlerTests
_mockPathService.PathSeparator.Returns(expectedSeparator);
// Act
PathSeparatorResponse result = await _sut.Handle(query, CancellationToken.None);
PathSeparatorResponse result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.NotNull(result);
@@ -57,7 +57,7 @@ public class GetPathSeparatorQueryHandlerTests
_mockPathService.PathSeparator.Returns(separator);
// Act
PathSeparatorResponse result = await _sut.Handle(query, CancellationToken.None);
PathSeparatorResponse result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.NotNull(result);
@@ -74,8 +74,8 @@ public class GetPathSeparatorQueryHandlerTests
_mockPathService.PathSeparator.Returns(expectedSeparator);
// Act
PathSeparatorResponse result1 = await _sut.Handle(query, CancellationToken.None);
PathSeparatorResponse result2 = await _sut.Handle(query, CancellationToken.None);
PathSeparatorResponse result1 = await _sut.HandleAsync(query, CancellationToken.None);
PathSeparatorResponse result2 = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.Equal(result1, result2);
@@ -91,7 +91,7 @@ public class GetPathSeparatorQueryHandlerTests
// Act
Exception? exception = await Record.ExceptionAsync(
async () => await _sut.Handle(query, cts.Token)
async () => await _sut.HandleAsync(query, cts.Token)
);
// Assert
@@ -37,7 +37,7 @@ public class ValidatePathQueryHandlerTests
_mockPathService.IsValidPath(query.Path!).Returns(true);
// Act
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
PathValidResponse result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsValid);
@@ -52,7 +52,7 @@ public class ValidatePathQueryHandlerTests
_mockPathService.IsValidPath(query.Path!).Returns(false);
// Act
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
PathValidResponse result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsValid);
@@ -67,7 +67,7 @@ public class ValidatePathQueryHandlerTests
_mockPathService.IsValidPath(Arg.Any<string>()).Returns(false);
// Act
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
PathValidResponse result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsValid);
@@ -82,7 +82,7 @@ public class ValidatePathQueryHandlerTests
_mockPathService.IsValidPath(Arg.Any<string>()).Returns(false);
// Act
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
PathValidResponse result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsValid);
@@ -1,8 +1,10 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation.TestHelper;
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath.Fixtures;
using Lumina.Domain.SharedKernel.Common.Errors;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -32,11 +34,10 @@ public class ValidatePathQueryValidatorTests
query = query with { Path = null! };
// Act
TestValidationResult<ValidatePathQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -47,11 +48,10 @@ public class ValidatePathQueryValidatorTests
query = query with { Path = string.Empty };
// Act
TestValidationResult<ValidatePathQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -62,11 +62,10 @@ public class ValidatePathQueryValidatorTests
query = query with { Path = " " };
// Act
TestValidationResult<ValidatePathQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path)
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -77,9 +76,9 @@ public class ValidatePathQueryValidatorTests
query = query with { Path = "/valid/path" };
// Act
TestValidationResult<ValidatePathQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.Path);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
}
@@ -6,6 +6,7 @@ using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbna
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Application.Common.Infrastructure.Validation;
using NSubstitute;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
@@ -28,7 +29,10 @@ public class GetThumbnailQueryHandlerTests
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockThumbnailService = Substitute.For<IThumbnailService>();
_sut = new GetThumbnailQueryHandler(_mockThumbnailService);
IValidator<GetThumbnailQuery> mockValidator = Substitute.For<IValidator<GetThumbnailQuery>>();
mockValidator.Validate(Arg.Any<GetThumbnailQuery>())
.Returns([]);
_sut = new GetThumbnailQueryHandler(_mockThumbnailService, mockValidator);
}
[Fact]
@@ -42,7 +46,7 @@ public class GetThumbnailQueryHandlerTests
.Returns(ErrorOrFactory.From(thumbnail));
// Act
ErrorOr<ThumbnailResponse> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<ThumbnailResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.False(result.IsError);
@@ -62,7 +66,7 @@ public class GetThumbnailQueryHandlerTests
.Returns(error);
// Act
ErrorOr<ThumbnailResponse> result = await _sut.Handle(query, CancellationToken.None);
ErrorOr<ThumbnailResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
// Assert
Assert.True(result.IsError);
@@ -82,7 +86,7 @@ public class GetThumbnailQueryHandlerTests
.Returns(Task.FromCanceled<ErrorOr<Thumbnail>>(cts.Token));
// Act & Assert
await Assert.ThrowsAsync<TaskCanceledException>(() => _sut.Handle(query, cts.Token).AsTask());
await Assert.ThrowsAsync<TaskCanceledException>(() => _sut.HandleAsync(query, cts.Token));
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path!, query.Quality, cts.Token);
}
}
@@ -1,7 +1,9 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation.TestHelper;
using ErrorOr;
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.SharedKernel.Common.Errors;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -30,10 +32,10 @@ public class GetThumbnailQueryValidatorTests
GetThumbnailQuery query = new(null!, 1);
// Act
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path).WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -43,10 +45,10 @@ public class GetThumbnailQueryValidatorTests
GetThumbnailQuery query = new(string.Empty, 1);
// Act
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Path).WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -56,10 +58,10 @@ public class GetThumbnailQueryValidatorTests
GetThumbnailQuery query = new("test", 1);
// Act
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.Path);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
@@ -69,10 +71,10 @@ public class GetThumbnailQueryValidatorTests
GetThumbnailQuery query = new("test", -1);
// Act
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Quality).WithErrorMessage(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred.Description);
result.ShouldHaveValidationError(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred);
}
[Fact]
@@ -82,10 +84,10 @@ public class GetThumbnailQueryValidatorTests
GetThumbnailQuery query = new("test", 101);
// Act
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationErrorFor(x => x.Quality).WithErrorMessage(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred.Description);
result.ShouldHaveValidationError(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred);
}
[Fact]
@@ -95,10 +97,10 @@ public class GetThumbnailQueryValidatorTests
GetThumbnailQuery query = new("test", 1);
// Act
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationErrorFor(x => x.Quality);
result.ShouldNotHaveValidationError(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred);
}
}