mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11:10 +00:00
Replaces FluentValidation and Mediator command/queries handling with custom implementations.
This commit is contained in:
1 parent
9a5c7473f9
commit
2d1c6b1ab8
297 files changed
+3619
-3045
No files matched your search
+9
-5
@@ -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);
|
||||
|
||||
+15
-16
@@ -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
-5
@@ -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);
|
||||
|
||||
+15
-16
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user