mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 02:01:10 +00:00
Replaces Mediator domain event publishing with a custom implementation and removes the Mediator dependency
This commit is contained in:
1 parent
8c8c96c6db
commit
810fa5c2e7
61 files changed
+618
-176
No files matched your search
+103
-23
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.CQRS;
|
||||
@@ -17,6 +18,7 @@ namespace Lumina.Application.UnitTests.Common.CQRS;
|
||||
public class HandlersCallTheirValidatorsTests
|
||||
{
|
||||
private static readonly Assembly s_applicationAssembly = typeof(ICommand).Assembly;
|
||||
private static readonly Dictionary<short, OpCode> s_opCodes = BuildOpCodeLookup();
|
||||
|
||||
/// <summary>
|
||||
/// Ensures every command or query that has a validator has a handler that calls that validator.
|
||||
@@ -101,6 +103,12 @@ public class HandlersCallTheirValidatorsTests
|
||||
yield return nestedDescendant;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the IL of the specified <paramref name="method"/> contains a call to <see cref="IValidator{TRequest}.Validate"/>.
|
||||
/// </summary>
|
||||
/// <param name="method">The method whose IL is inspected.</param>
|
||||
/// <param name="validatorInterface">The closed validator interface whose <c>Validate</c> method is being looked for.</param>
|
||||
/// <returns><see langword="true"/> if the method calls the validator, <see langword="false"/> otherwise.</returns>
|
||||
private static bool CallsValidatorMethod(MethodInfo method, Type validatorInterface)
|
||||
{
|
||||
MethodBody? body = method.GetMethodBody();
|
||||
@@ -112,38 +120,110 @@ public class HandlersCallTheirValidatorsTests
|
||||
return false;
|
||||
|
||||
Module module = method.Module;
|
||||
for (int i = 0; i < il.Length; i++)
|
||||
int offset = 0;
|
||||
while (offset < il.Length)
|
||||
{
|
||||
// 0x28 is the call opcode and 0x6F is the callvirt opcode, both followed by a 4-byte metadata token
|
||||
if (il[i] != 0x28 && il[i] != 0x6F)
|
||||
continue;
|
||||
// read the opcode, handling the 0xFE prefix used by two-byte opcodes
|
||||
short opCodeValue = il[offset];
|
||||
int opCodeSize = 1;
|
||||
if (opCodeValue == 0xFE && offset + 1 < il.Length)
|
||||
{
|
||||
opCodeValue = (short)((0xFE << 8) | il[offset + 1]);
|
||||
opCodeSize = 2;
|
||||
}
|
||||
|
||||
if (i + 4 >= il.Length)
|
||||
if (!s_opCodes.TryGetValue(opCodeValue, out OpCode opCode))
|
||||
return false;
|
||||
|
||||
offset += opCodeSize;
|
||||
if (offset >= il.Length)
|
||||
break;
|
||||
|
||||
int token = il[i + 1] | (il[i + 2] << 8) | (il[i + 3] << 16) | (il[i + 4] << 24);
|
||||
try
|
||||
if (opCode == OpCodes.Call || opCode == OpCodes.Callvirt)
|
||||
{
|
||||
if (module.ResolveMethod(token) is MethodInfo resolvedMethod &&
|
||||
resolvedMethod.Name == nameof(IValidator<object>.Validate) &&
|
||||
resolvedMethod.DeclaringType != null &&
|
||||
resolvedMethod.DeclaringType.Equals(validatorInterface))
|
||||
return true;
|
||||
int token = ReadInt32(il, offset);
|
||||
try
|
||||
{
|
||||
if (module.ResolveMethod(token) is MethodInfo resolvedMethod &&
|
||||
resolvedMethod.Name == nameof(IValidator<object>.Validate) &&
|
||||
resolvedMethod.DeclaringType != null &&
|
||||
resolvedMethod.DeclaringType.Equals(validatorInterface))
|
||||
return true;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// the token is not a valid method token, skip it
|
||||
}
|
||||
catch (BadImageFormatException)
|
||||
{
|
||||
// the token references corrupt metadata, skip it
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// the token cannot be resolved as a method, skip it
|
||||
}
|
||||
}
|
||||
catch (ArgumentException)
|
||||
|
||||
if (opCode.OperandType == OperandType.InlineSwitch)
|
||||
{
|
||||
// the token is not a valid method token, skip it
|
||||
int switchCases = ReadInt32(il, offset);
|
||||
offset += 4 + (switchCases * 4);
|
||||
}
|
||||
catch (BadImageFormatException)
|
||||
{
|
||||
// the token references corrupt metadata, skip it
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// the token cannot be resolved as a method, skip it
|
||||
}
|
||||
i += 4;
|
||||
else
|
||||
offset += GetOperandSize(opCode);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a lookup table of all opcodes, keyed by their numeric value.
|
||||
/// </summary>
|
||||
/// <returns>The built lookup table.</returns>
|
||||
private static Dictionary<short, OpCode> BuildOpCodeLookup()
|
||||
{
|
||||
Dictionary<short, OpCode> opCodes = [];
|
||||
foreach (FieldInfo field in typeof(OpCodes).GetFields(BindingFlags.Public | BindingFlags.Static))
|
||||
if (field.GetValue(null) is OpCode opCode)
|
||||
opCodes[opCode.Value] = opCode;
|
||||
return opCodes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size in bytes of the operand of the specified <paramref name="opCode"/>.
|
||||
/// </summary>
|
||||
/// <param name="opCode">The opcode whose operand size is returned.</param>
|
||||
/// <returns>The size of the operand in bytes.</returns>
|
||||
private static int GetOperandSize(OpCode opCode)
|
||||
{
|
||||
return opCode.OperandType switch
|
||||
{
|
||||
OperandType.InlineNone => 0,
|
||||
OperandType.ShortInlineI => 1,
|
||||
OperandType.ShortInlineVar => 1,
|
||||
OperandType.ShortInlineBrTarget => 1,
|
||||
OperandType.InlineVar => 2,
|
||||
OperandType.InlineBrTarget => 4,
|
||||
OperandType.InlineField => 4,
|
||||
OperandType.InlineMethod => 4,
|
||||
OperandType.InlineType => 4,
|
||||
OperandType.InlineString => 4,
|
||||
OperandType.InlineSig => 4,
|
||||
OperandType.ShortInlineR => 4,
|
||||
OperandType.InlineI => 4,
|
||||
OperandType.InlineR => 8,
|
||||
OperandType.InlineI8 => 8,
|
||||
_ => 0,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 4-byte little-endian integer from the specified offset in the IL stream.
|
||||
/// </summary>
|
||||
/// <param name="il">The IL byte stream.</param>
|
||||
/// <param name="offset">The offset at which to read the integer.</param>
|
||||
/// <returns>The read integer.</returns>
|
||||
private static int ReadInt32(byte[] il, int offset)
|
||||
{
|
||||
return il[offset] | (il[offset + 1] << 8) | (il[offset + 2] << 16) | (il[offset + 3] << 24);
|
||||
}
|
||||
}
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Infrastructure.Common.DomainEvents;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Common.DomainEvents;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="DomainEventPublisher"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DomainEventPublisherTests
|
||||
{
|
||||
public sealed record TestDomainEvent(Guid Id, DateTime OccurredOnUtc) : IDomainEvent;
|
||||
|
||||
public sealed record NestedTestDomainEvent(Guid Id, DateTime OccurredOnUtc) : IDomainEvent;
|
||||
|
||||
private sealed class RecordingDomainEventHandler : IDomainEventHandler<TestDomainEvent>
|
||||
{
|
||||
private readonly List<string> _callLog;
|
||||
private readonly string _handlerName;
|
||||
|
||||
public RecordingDomainEventHandler(List<string> callLog, string handlerName)
|
||||
{
|
||||
_callLog = callLog;
|
||||
_handlerName = handlerName;
|
||||
}
|
||||
|
||||
public ValueTask HandleAsync(TestDomainEvent domainEvent, CancellationToken cancellationToken)
|
||||
{
|
||||
_callLog.Add(_handlerName);
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a publisher wired to a fresh service provider, optionally registering additional services.
|
||||
/// </summary>
|
||||
/// <param name="configureServices">Optional action used to register additional services into the provider.</param>
|
||||
/// <returns>A domain event publisher resolved from the created provider.</returns>
|
||||
private static IDomainEventPublisher CreatePublisher(Action<IServiceCollection>? configureServices = null)
|
||||
{
|
||||
IServiceCollection services = new ServiceCollection();
|
||||
services.AddScoped<IDomainEventPublisher, DomainEventPublisher>();
|
||||
configureServices?.Invoke(services);
|
||||
ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
return serviceProvider.GetRequiredService<IDomainEventPublisher>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid instance of <see cref="TestDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created domain event.</returns>
|
||||
private static TestDomainEvent CreateTestDomainEvent()
|
||||
{
|
||||
return new TestDomainEvent(Guid.NewGuid(), DateTime.UtcNow);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid instance of <see cref="NestedTestDomainEvent"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created domain event.</returns>
|
||||
private static NestedTestDomainEvent CreateNestedTestDomainEvent()
|
||||
{
|
||||
return new NestedTestDomainEvent(Guid.NewGuid(), DateTime.UtcNow);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_WhenHandlersAreRegistered_ShouldInvokeAllHandlersInOrder()
|
||||
{
|
||||
// Arrange
|
||||
TestDomainEvent domainEvent = CreateTestDomainEvent();
|
||||
List<string> callLog = [];
|
||||
IDomainEventPublisher publisher = CreatePublisher(services =>
|
||||
{
|
||||
services.AddScoped<IDomainEventHandler<TestDomainEvent>>(_ => new RecordingDomainEventHandler(callLog, "first"));
|
||||
services.AddScoped<IDomainEventHandler<TestDomainEvent>>(_ => new RecordingDomainEventHandler(callLog, "second"));
|
||||
});
|
||||
|
||||
// Act
|
||||
await publisher.PublishAsync(domainEvent, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(["first", "second"], callLog);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_WhenNoHandlersAreRegisteredForTheEventType_ShouldNotThrow()
|
||||
{
|
||||
// Arrange
|
||||
TestDomainEvent domainEvent = CreateTestDomainEvent();
|
||||
IDomainEventPublisher publisher = CreatePublisher();
|
||||
|
||||
// Act
|
||||
await publisher.PublishAsync(domainEvent, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
// reaching this point without an exception means the publish was a no-op, as expected
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_WhenOnlyAnotherEventTypeHasHandlers_ShouldNotInvokeThem()
|
||||
{
|
||||
// Arrange
|
||||
TestDomainEvent domainEvent = CreateTestDomainEvent();
|
||||
IDomainEventHandler<NestedTestDomainEvent> nestedHandler = Substitute.For<IDomainEventHandler<NestedTestDomainEvent>>();
|
||||
IDomainEventPublisher publisher = CreatePublisher(services => services.AddScoped(_ => nestedHandler));
|
||||
|
||||
// Act
|
||||
await publisher.PublishAsync(domainEvent, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await nestedHandler.DidNotReceive().HandleAsync(Arg.Any<NestedTestDomainEvent>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_WhenHandlerThrows_ShouldPropagateTheException()
|
||||
{
|
||||
// Arrange
|
||||
TestDomainEvent domainEvent = CreateTestDomainEvent();
|
||||
InvalidOperationException expectedException = new("Test exception");
|
||||
IDomainEventHandler<TestDomainEvent> handler = Substitute.For<IDomainEventHandler<TestDomainEvent>>();
|
||||
handler.HandleAsync(Arg.Any<TestDomainEvent>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => throw expectedException);
|
||||
IDomainEventPublisher publisher = CreatePublisher(services => services.AddScoped<IDomainEventHandler<TestDomainEvent>>(_ => handler));
|
||||
|
||||
// Act
|
||||
InvalidOperationException result = await Assert.ThrowsAsync<InvalidOperationException>(
|
||||
() => publisher.PublishAsync(domainEvent, CancellationToken.None).AsTask());
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedException, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_WhenHandlerPublishesAnotherEvent_ShouldInvokeNestedHandlers()
|
||||
{
|
||||
// Arrange
|
||||
TestDomainEvent domainEvent = CreateTestDomainEvent();
|
||||
NestedTestDomainEvent nestedDomainEvent = CreateNestedTestDomainEvent();
|
||||
IDomainEventHandler<TestDomainEvent> handler = Substitute.For<IDomainEventHandler<TestDomainEvent>>();
|
||||
IDomainEventHandler<NestedTestDomainEvent> nestedHandler = Substitute.For<IDomainEventHandler<NestedTestDomainEvent>>();
|
||||
IDomainEventPublisher publisher = CreatePublisher(services =>
|
||||
{
|
||||
services.AddScoped(_ => handler);
|
||||
services.AddScoped(_ => nestedHandler);
|
||||
});
|
||||
handler.HandleAsync(domainEvent, Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => publisher.PublishAsync(nestedDomainEvent, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
await publisher.PublishAsync(domainEvent, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await nestedHandler.Received(1).HandleAsync(nestedDomainEvent, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_WhenCancellationRequested_ShouldPassTokenToHandlers()
|
||||
{
|
||||
// Arrange
|
||||
TestDomainEvent domainEvent = CreateTestDomainEvent();
|
||||
using CancellationTokenSource cancellationTokenSource = new();
|
||||
CancellationToken cancellationToken = cancellationTokenSource.Token;
|
||||
IDomainEventHandler<TestDomainEvent> handler = Substitute.For<IDomainEventHandler<TestDomainEvent>>();
|
||||
IDomainEventPublisher publisher = CreatePublisher(services => services.AddScoped(_ => handler));
|
||||
|
||||
// Act
|
||||
await publisher.PublishAsync(domainEvent, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await handler.Received(1).HandleAsync(domainEvent, Arg.Is(cancellationToken));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_WhenDomainEventIsNull_ShouldThrowArgumentNullException()
|
||||
{
|
||||
// Arrange
|
||||
IDomainEventPublisher publisher = CreatePublisher();
|
||||
|
||||
// Act
|
||||
ArgumentNullException result = await Assert.ThrowsAsync<ArgumentNullException>(() => publisher.PublishAsync(null!, CancellationToken.None).AsTask());
|
||||
|
||||
// Assert
|
||||
Assert.Equal("domainEvent", result.ParamName);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class GetPermissionsEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class AddRoleEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = new("Admin", [Guid.NewGuid()]);
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class DeleteRoleEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
DeleteRoleRequest request = new(Guid.NewGuid());
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ public class GetRolePermissionsEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetRolePermissionsRequest request = new(Guid.NewGuid());
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class GetRolesEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class UpdateRoleEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
UpdateRoleRequest request = new(Guid.NewGuid(), "UpdatedAdmin", [Guid.NewGuid()]);
|
||||
|
||||
+3
-3
@@ -60,7 +60,7 @@ public class GetDirectoriesEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
@@ -86,7 +86,7 @@ public class GetDirectoriesEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
@@ -112,7 +112,7 @@ public class GetDirectoriesEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetDirectoriesQueryToMediator()
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetDirectoriesQueryToHandler()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
|
||||
+2
-2
@@ -57,7 +57,7 @@ public class GetDrivesEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
@@ -82,7 +82,7 @@ public class GetDrivesEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetDrivesQueryToMediator()
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetDrivesQueryToHandler()
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ public class GetFileSystemTypeEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetFileSystemQueryToMediator()
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetFileSystemQueryToHandler()
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
+2
-2
@@ -62,7 +62,7 @@ public class GetFilesEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
@@ -88,7 +88,7 @@ public class GetFilesEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
|
||||
+2
-2
@@ -63,7 +63,7 @@ public class GetTreeFilesEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
@@ -89,7 +89,7 @@ public class GetTreeFilesEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class CheckPathExistsEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendCheckPathExistsQueryToMediator()
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendCheckPathExistsQueryToHandler()
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsRequest request = _checkPathExistsRequestFixture.Create(path: @"C:\Users\TestUser\Documents", includeHiddenElements: true);
|
||||
|
||||
+3
-3
@@ -58,7 +58,7 @@ public class CombinePathEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathRequest request = _combinePathRequestFixture.Create("InvalidPath", "TestUser");
|
||||
@@ -84,7 +84,7 @@ public class CombinePathEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathRequest request = _combinePathRequestFixture.Create("InvalidPath", "TestUser");
|
||||
@@ -110,7 +110,7 @@ public class CombinePathEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendCombinePathCommandToMediator()
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendCombinePathCommandToHandler()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathRequest request = _combinePathRequestFixture.Create("C:\\Users", "TestUser");
|
||||
|
||||
+3
-3
@@ -61,7 +61,7 @@ public class GetPathParentEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentRequest request = _getPathParentRequestFixture.Create(@"C:\Users\TestUser");
|
||||
@@ -87,7 +87,7 @@ public class GetPathParentEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentRequest request = _getPathParentRequestFixture.Create(@"InvalidPath");
|
||||
@@ -113,7 +113,7 @@ public class GetPathParentEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetPathParentQueryToMediator()
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetPathParentQueryToHandler()
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentRequest request = _getPathParentRequestFixture.Create(@"C:\Users\TestUser");
|
||||
|
||||
+3
-3
@@ -59,7 +59,7 @@ public class GetPathRootEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootRequest request = _getPathRootRequestFixture.Create(@"C:\Users\TestUser");
|
||||
@@ -85,7 +85,7 @@ public class GetPathRootEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootRequest request = _getPathRootRequestFixture.Create(@"InvalidPath");
|
||||
@@ -111,7 +111,7 @@ public class GetPathRootEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetPathRootQueryToMediator()
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetPathRootQueryToHandler()
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootRequest request = _getPathRootRequestFixture.Create(@"C:\Users\TestUser");
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public class GetPathSeparatorEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetPathSeparatorQueryToMediator()
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetPathSeparatorQueryToHandler()
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
+2
-2
@@ -60,7 +60,7 @@ public class SplitPathEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
SplitPathRequest request = _splitPathRequestFixture.Create(@"InvalidPath");
|
||||
@@ -87,7 +87,7 @@ public class SplitPathEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendSplitPathCommandToMediator()
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendSplitPathCommandToHandler()
|
||||
{
|
||||
// Arrange
|
||||
SplitPathRequest request = _splitPathRequestFixture.Create(@"C:\Users\TestUser\Documents");
|
||||
|
||||
+2
-2
@@ -58,7 +58,7 @@ public class ValidatePathEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendValidatePathQueryToMediator()
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendValidatePathQueryToHandler()
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(@"C:\Users\TestUser\Documents");
|
||||
@@ -76,7 +76,7 @@ public class ValidatePathEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(@"C:\Users\TestUser\Documents");
|
||||
|
||||
+2
-2
@@ -59,7 +59,7 @@ public class GetThumbnailEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailRequest request = _getThumbnailRequestFixture.Create("/path/to/nonexistent/file.jpg", 80);
|
||||
@@ -85,7 +85,7 @@ public class GetThumbnailEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailRequest request = _getThumbnailRequestFixture.Create("/path/to/nonexistent/file.jpg", 80);
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ public class CheckInitializationEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendCheckInitializationQueryToMediator()
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendCheckInitializationQueryToHandler()
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public class SetupApplicationEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class ChangePasswordEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class GetUsersEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class LoginEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
LoginRequest request = _loginRequestFixture.Create();
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class RecoverPasswordEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class RegisterEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ public class GetAuthorizationEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetAuthorizationRequest request = GetAuthorizationRequestFixture.Create();
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class GetUserPermissionsEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetUserPermissionsRequest request = new(Guid.NewGuid());
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public class GetUserRoleEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetUserRoleRequest request = new(Guid.NewGuid());
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
|
||||
Reference in new issue
Block a user