From 810fa5c2e7cee992a01f53fd39d42594c093584a Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Thu, 13 Aug 2026 14:02:16 -0700 Subject: [PATCH] Replaces Mediator domain event publishing with a custom implementation and removes the Mediator dependency --- .../architecture-decision-record-0011.md | 4 +- .../architecture-decision-record-0013.md | 76 +++++++ .../ApplicationLayerServices.cs | 8 +- .../LibraryDeletedDomainEventHandler.cs | 8 +- .../Events/LibrarySavedDomainEventHandler.cs | 8 +- .../LibraryScanCancelledDomainEventHandler.cs | 8 +- .../LibraryScanFailedDomainEventHandler.cs | 8 +- .../LibraryScanFinishedDomainEventHandler.cs | 8 +- ...canJobProgressChangedDomainEventHandler.cs | 8 +- ...ryScanProgressChangedDomainEventHandler.cs | 8 +- .../LibraryScanQueuedDomainEventHandler.cs | 7 +- .../LibraryScanStartedDomainEventHandler.cs | 8 +- .../Lumina.Application.csproj | 5 - .../Common/Events/IDomainEvent.cs | 3 +- .../Common/Events/IDomainEventHandler.cs | 21 ++ .../Common/Events/IDomainEventPublisher.cs | 20 ++ .../Services/MediaLibraryScanningService.cs | 11 +- src/Lumina.Domain/Lumina.Domain.csproj | 1 - .../InfrastructureLayerServices.cs | 2 + .../DomainEvents/DomainEventPublisher.cs | 65 ++++++ .../Jobs/Common/MediaLibraryScanDiffJob.cs | 16 +- .../Jobs/Common/MediaLibraryScanHashJob.cs | 16 +- .../MediaLibraryScanMetadataEnrichmentJob.cs | 16 +- .../Common/MediaLibraryScanResultsSaveJob.cs | 18 +- .../Jobs/Common/ScanFailurePublisher.cs | 6 +- .../Books/BooksFileSystemDiscoveryJob.cs | 18 +- .../EventualConsistencyMiddleware.cs | 7 +- .../Lumina.Presentation.Api.csproj | 1 - .../Lumina.Presentation.Web.csproj | 1 - .../CQRS/HandlersCallTheirValidatorsTests.cs | 126 +++++++++--- .../DomainEvents/DomainEventPublisherTests.cs | 194 ++++++++++++++++++ .../GetPermissionsEndpointTests.cs | 2 +- .../Roles/AddRole/AddRoleEndpointTests.cs | 2 +- .../DeleteRole/DeleteRoleEndpointTests.cs | 2 +- .../GetRolePermissionsEndpointTests.cs | 2 +- .../Roles/GetRoles/GetRolesEndpointTests.cs | 2 +- .../UpdateRole/UpdateRoleEndpointTests.cs | 2 +- .../GetDirectoriesEndpointTests.cs | 6 +- .../Drives/GetDrivesEndpointTests.cs | 4 +- .../FileSystem/GetTypeEndpointTests.cs | 2 +- .../Files/GetFilesEndpointTests.cs | 4 +- .../Files/GetTreeFilesEndpointTests.cs | 4 +- .../Path/CheckPathExistsEndpointTests.cs | 2 +- .../Path/CombinePathEndpointTests.cs | 6 +- .../Path/GetPathParentEndpointTests.cs | 6 +- .../Path/GetPathRootEndpointTests.cs | 6 +- .../Path/GetPathSeparatorEndpointTests.cs | 2 +- .../Path/SplitPathEndpointTests.cs | 4 +- .../Path/ValidatePathEndpointTests.cs | 4 +- .../Thumbnails/GetThumbnailEndpointTests.cs | 4 +- .../CheckInitializationEndpointTests.cs | 2 +- .../SetupApplicationEndpointTests.cs | 2 +- .../ChangePasswordEndpointTests.cs | 2 +- .../GetUsers/GetUsersEndpointTests.cs | 2 +- .../Login/LoginEndpointTests.cs | 2 +- .../RecoverPasswordEndpointTests.cs | 2 +- .../Register/RegisterEndpointTests.cs | 2 +- .../GetAuthorizationEndpointTests.cs | 2 +- .../GetUserPermissionsEndpointTests.cs | 2 +- .../GetUserRole/GetUserRoleEndpointTests.cs | 2 +- ...dateUserRoleAndPermissionsEndpointTests.cs | 2 +- 61 files changed, 618 insertions(+), 176 deletions(-) create mode 100644 docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0013.md create mode 100644 src/Lumina.Domain/Common/Events/IDomainEventHandler.cs create mode 100644 src/Lumina.Domain/Common/Events/IDomainEventPublisher.cs create mode 100644 src/Lumina.Infrastructure/Common/DomainEvents/DomainEventPublisher.cs create mode 100644 tests/UnitTests/Lumina.Infrastructure.UnitTests/Common/DomainEvents/DomainEventPublisherTests.cs diff --git a/docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0011.md b/docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0011.md index 855119b4..68f31844 100644 --- a/docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0011.md +++ b/docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0011.md @@ -12,9 +12,9 @@ Key constraints that shaped this decision: 1. **Licensing Change**: MediatR became a commercial product for .NET 8+ projects, requiring a paid license for continued use in production systems. -2. **Narrow Usage Scope**: MediatR is used exclusively for command and query dispatching - only one pipeline behavior (automatic application validation) and no notification publishing or stream requests are in use anywhere in the solution. +2. **Narrow Usage Scope**: MediatR is used for command and query dispatching, with a single pipeline behavior (automatic application validation) and no stream requests. Its notification publishing is used for domain event publishing, which is outside the scope of this ADR and is replaced separately (see ADR-0013). -3. **Zero Abstraction Value at Scale**: With only a validation pipeline behavior registered, MediatR provides no runtime value beyond a dispatch indirection that can be replaced by direct handler injection. It actually hurts performance by runtime dispatching of handlers via reflection. +3. **Zero Abstraction Value at Scale**: With only a validation pipeline behavior registered, the command and query dispatching provides no runtime value beyond a dispatch indirection that can be replaced by direct handler injection. It actually hurts performance by runtime dispatching of handlers via reflection. 4. **Ownership and Transparency**: A custom implementation is fully owned, inspectable, and carries no transitive dependency risk or future licensing exposure. diff --git a/docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0013.md b/docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0013.md new file mode 100644 index 00000000..74e21de2 --- /dev/null +++ b/docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0013.md @@ -0,0 +1,76 @@ +# Architecture Decision Record (ADR): 0013 - Replace Mediator Domain Event Publishing with a Custom Implementation + +## Status + +**Accepted** (2026-08-13) + +## Context + +Domain event publishing, the mechanism that fires the `IDomainEvent` objects raised by aggregates to their handlers, depends on the Mediator library (`Mediator.Abstractions` and `Mediator.SourceGenerator`). + +1. **Event contract**: `IDomainEvent` implements Mediator's `INotification` marker interface. + +2. **Handler registration**: Domain event handlers implements Mediator's `INotificationHandler` and are registered by the source-generated `AddMediator` call. + +3. **Publishing sites**: Mediator's `IPublisher` is used from `EventualConsistencyMiddleware` (queued events, published after the transaction commits), from `MediaLibraryScanningService` (scan start events), and from the scan jobs and `ScanFailurePublisher` (progress and failure events). + +The remaining publish half carries the same third-party dependency and source-generated registration that ADR-0011 removed from the dispatch half. + +## Decision + +Replace Mediator's notification publishing with a first-party domain event publisher. + +### New Abstractions (in `Lumina.Domain.Common.Events`) + +- `IDomainEvent` no longer inherits `INotification`. +- `IDomainEventPublisher` exposes `ValueTask PublishAsync(IDomainEvent domainEvent, CancellationToken cancellationToken = default)`. +- `IDomainEventHandler` exposes `ValueTask HandleAsync(TDomainEvent domainEvent, CancellationToken cancellationToken)`. The type parameter is invariant so handlers stay mockable by dynamic proxy libraries. + +### Publisher Implementation (`DomainEventPublisher` in Infrastructure) + +- Scoped, resolving handlers for the event's runtime type from the DI container. +- Dispatches through a compiled delegate cached per event type in a static `ConcurrentDictionary`, built once via `MakeGenericMethod` over a generic dispatch helper. Handlers run sequentially in registration order, exceptions propagate, and events without handlers are no-ops. +- Registered next to the existing `IDomainEventsQueue`. + +### Registration (Application DI) + +The existing assembly scan that registers `ICommandHandler<>`, `IQueryHandler<>`, and `IValidator<>` now also registers `IDomainEventHandler<>` as scoped, replacing the source-generated `AddMediator`. + +### Consistency Guarantees Preserved + +- Commit-before-publish ordering in `EventualConsistencyMiddleware` is unchanged (see ADR-0002). +- Re-entrant publishing (a handler publishing another event) is safe: each publish resolves handlers fresh from the scoped provider. +- Jobs publish from their own scopes, so handlers receive a fresh unit of work and `DbContext`. + +## Consequences + +### Positive Outcomes + +| Aspect | Benefit | +|---|---| +| Dependency reduction | Removes `Mediator.Abstractions` and `Mediator.SourceGenerator` from the entire solution | +| Transparency | Dispatch logic is fully owned and inspectable; no generated code | +| Consistency | Domain event handlers join the same explicit registration scan as the CQRS handlers | +| Single event contract | `IDomainEvent` remains the sole contract until a real cross-bounded-context consumer exists | + +### Risks and Mitigations + +| Risk | Mitigation Strategy | +|---|---| +| Handler resolution failures surface at runtime | Existing integration test suite exercises the DI container on startup | +| Reflection-based dispatch per event type | Compiled delegate cache makes dispatch cheap after the first publish of each type | +| Dynamic proxy cannot proxy generic interfaces | `IDomainEventHandler` is deliberately invariant so handlers remain mockable in unit tests | + +## Alternatives Considered + +### 1. Domain versus Integration Event Split + +Introduce `IIntegrationEvent` now, with a durable outbox, for inter-bounded-context propagation. + +**Rejected**: there are no cross-bounded-context consumers today - every event lives in the `LibraryManagementBoundedContext` and is handled in-process. The outbox machinery (durability, retries, idempotency) is speculative until the first real consumer appears, and forcing every existing event into one of two buckets would produce classification with no basis. The seam is documented on `IDomainEvent` itself so the split stays cheap to introduce later. + +### 2. Keeping Mediator for Publishing + +Keep the Mediator library for the domain event publishing half. + +**Rejected**: for the same reason ADR-0011 rejected it for command and query dispatching - an external dependency, with source-generated registration, for functionality that is fully implementable in-house. diff --git a/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs b/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs index 4b6c6e71..229555a5 100644 --- a/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs +++ b/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs @@ -1,4 +1,5 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Events; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; @@ -22,17 +23,12 @@ public static class ApplicationLayerServices /// The updated . public static IServiceCollection AddApplicationLayerServices(this IServiceCollection services) { - // register the Mediator publisher used for publishing domain events - services.AddMediator(options => - { - options.ServiceLifetime = ServiceLifetime.Scoped; - }); - Type[] handlerContractTypes = [ typeof(CQRS.ICommandHandler<,>), typeof(CQRS.IQueryHandler<,>), typeof(Infrastructure.Validation.IValidator<>), + typeof(IDomainEventHandler<>), ]; IEnumerable concreteTypes = Assembly.GetExecutingAssembly() diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryDeletedDomainEventHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryDeletedDomainEventHandler.cs index 7f7e91eb..5f4ab957 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryDeletedDomainEventHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryDeletedDomainEventHandler.cs @@ -6,7 +6,7 @@ using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.File using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events; -using Mediator; +using Lumina.Domain.Common.Events; using Microsoft.Extensions.Options; using System; using System.Threading; @@ -16,9 +16,9 @@ using System.Threading.Tasks; namespace Lumina.Application.Core.MediaLibrary.Management.Events; /// -/// Handler for the event raised when a media library is deleted. +/// Handler for the domain event raised when a media library is deleted. /// -public class LibraryDeletedDomainEventHandler : INotificationHandler +public class LibraryDeletedDomainEventHandler : IDomainEventHandler { private readonly IEnvironmentContext _environmentContext; private readonly IPathService _pathService; @@ -42,7 +42,7 @@ public class LibraryDeletedDomainEventHandler : INotificationHandler /// The domain event to be handled. /// Cancellation token that can be used to stop the execution. - public ValueTask Handle(LibraryDeletedDomainEvent domainEvent, CancellationToken cancellationToken) + public ValueTask HandleAsync(LibraryDeletedDomainEvent domainEvent, CancellationToken cancellationToken) { // delete the media library directory in the internal location for media library files ErrorOr libraryPathResult = GetLibraryPath(domainEvent.Library.Id.Value); diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibrarySavedDomainEventHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibrarySavedDomainEventHandler.cs index 08f2cb79..e83e3411 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibrarySavedDomainEventHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibrarySavedDomainEventHandler.cs @@ -5,12 +5,12 @@ using Lumina.Application.Common.DataAccess.UoW; using Lumina.Application.Common.Mapping.MediaLibrary.Management; using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary; using Lumina.Domain.SharedKernel.Common.Errors; +using Lumina.Domain.Common.Events; using Lumina.Domain.Common.Exceptions; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events; -using Mediator; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; @@ -23,9 +23,9 @@ using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration; namespace Lumina.Application.Core.MediaLibrary.Management.Events; /// -/// Handler for the event raised when a media library is created or updated. +/// Handler for the domain event raised when a media library is created or updated. /// -public class LibrarySavedDomainEventHandler : INotificationHandler +public class LibrarySavedDomainEventHandler : IDomainEventHandler { private readonly IUnitOfWork _unitOfWork; private readonly IEnvironmentContext _environmentContext; @@ -56,7 +56,7 @@ public class LibrarySavedDomainEventHandler : INotificationHandler /// The domain event to be handled. /// Cancellation token that can be used to stop the execution. - public async ValueTask Handle(LibrarySavedDomainEvent domainEvent, CancellationToken cancellationToken) + public async ValueTask HandleAsync(LibrarySavedDomainEvent domainEvent, CancellationToken cancellationToken) { if (domainEvent.Library.CoverImage is not null) { diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanCancelledDomainEventHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanCancelledDomainEventHandler.cs index 3137958f..0c176b68 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanCancelledDomainEventHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanCancelledDomainEventHandler.cs @@ -5,6 +5,7 @@ using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary; using Lumina.Application.Common.DataAccess.UoW; using Lumina.Application.Common.Mapping.MediaLibrary.Management; using Lumina.Domain.SharedKernel.Common.Errors; +using Lumina.Domain.Common.Events; using Lumina.Domain.Common.Exceptions; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; @@ -13,7 +14,6 @@ using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.Library using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Progress; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects; -using Mediator; using System.Threading; using System.Threading.Tasks; #endregion @@ -21,9 +21,9 @@ using System.Threading.Tasks; namespace Lumina.Application.Core.MediaLibrary.Management.Events; /// -/// Handler for the event raised when a media library scan is cancelled. +/// Handler for the domain event raised when a media library scan is cancelled. /// -public class LibraryScanCancelledDomainEventHandler : INotificationHandler +public class LibraryScanCancelledDomainEventHandler : IDomainEventHandler { private readonly IMediaLibraryScanningService _mediaLibraryScanningService; private readonly IMediaLibrariesScanCancellationTracker _mediaLibrariesScanCancellationTracker; @@ -56,7 +56,7 @@ public class LibraryScanCancelledDomainEventHandler : INotificationHandler /// The domain event to be handled. /// Cancellation token that can be used to stop the execution. - public async ValueTask Handle(LibraryScanCancelledDomainEvent domainEvent, CancellationToken cancellationToken) + public async ValueTask HandleAsync(LibraryScanCancelledDomainEvent domainEvent, CancellationToken cancellationToken) { // get the library scan from the repository ErrorOr getLibraryScansResult = await _libraryScanRepository.GetByIdAsync(domainEvent.ScanId.Value, cancellationToken).ConfigureAwait(false); diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanFailedDomainEventHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanFailedDomainEventHandler.cs index a6b68baa..8da1fdbf 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanFailedDomainEventHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanFailedDomainEventHandler.cs @@ -6,12 +6,12 @@ using Lumina.Application.Common.DataAccess.UoW; using Lumina.Application.Common.Mapping.MediaLibrary.Management; using Lumina.Application.Core.MediaLibrary.Management.Progress; using Lumina.Domain.SharedKernel.Common.Errors; +using Lumina.Domain.Common.Events; using Lumina.Domain.Common.Exceptions; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Cancellation; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Progress; -using Mediator; using System.Threading; using System.Threading.Tasks; #endregion @@ -19,9 +19,9 @@ using System.Threading.Tasks; namespace Lumina.Application.Core.MediaLibrary.Management.Events; /// -/// Handler for the event raised when a media library scan has failed. +/// Handler for the domain event raised when a media library scan has failed. /// -public class LibraryScanFailedDomainEventHandler : INotificationHandler +public class LibraryScanFailedDomainEventHandler : IDomainEventHandler { private readonly IMediaLibraryScanProgressNotifier _debouncedLibraryScanProgressNotifier; private readonly IMediaLibrariesScanCancellationTracker _mediaLibrariesScanCancellationTracker; @@ -52,7 +52,7 @@ public class LibraryScanFailedDomainEventHandler : INotificationHandler /// The domain event to be handled. /// Cancellation token that can be used to stop the execution. - public async ValueTask Handle(LibraryScanFailedDomainEvent domainEvent, CancellationToken cancellationToken) + public async ValueTask HandleAsync(LibraryScanFailedDomainEvent domainEvent, CancellationToken cancellationToken) { ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository(); ILibraryScanStagingResultsRepository stagingResultsRepository = _unitOfWork.GetRepository(); diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanFinishedDomainEventHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanFinishedDomainEventHandler.cs index 79726cea..a0b20187 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanFinishedDomainEventHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanFinishedDomainEventHandler.cs @@ -6,12 +6,12 @@ using Lumina.Application.Common.DataAccess.UoW; using Lumina.Application.Common.Mapping.MediaLibrary.Management; using Lumina.Application.Core.MediaLibrary.Management.Progress; using Lumina.Domain.SharedKernel.Common.Errors; +using Lumina.Domain.Common.Events; using Lumina.Domain.Common.Exceptions; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Cancellation; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Progress; -using Mediator; using System.Threading; using System.Threading.Tasks; #endregion @@ -19,9 +19,9 @@ using System.Threading.Tasks; namespace Lumina.Application.Core.MediaLibrary.Management.Events; /// -/// Handler for the event raised when a media library scan is finished. +/// Handler for the domain event raised when a media library scan is finished. /// -public class LibraryScanFinishedDomainEventHandler : INotificationHandler +public class LibraryScanFinishedDomainEventHandler : IDomainEventHandler { private readonly IMediaLibrariesScanProgressTracker _mediaLibrariesScanProgressTracker; private readonly IMediaLibrariesScanCancellationTracker _mediaLibrariesScanCancellationTracker; @@ -52,7 +52,7 @@ public class LibraryScanFinishedDomainEventHandler : INotificationHandler /// The domain event to be handled. /// Cancellation token that can be used to stop the execution. - public async ValueTask Handle(LibraryScanFinishedDomainEvent domainEvent, CancellationToken cancellationToken) + public async ValueTask HandleAsync(LibraryScanFinishedDomainEvent domainEvent, CancellationToken cancellationToken) { ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository(); diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanJobProgressChangedDomainEventHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanJobProgressChangedDomainEventHandler.cs index 47db2cf5..e0bd68b4 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanJobProgressChangedDomainEventHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanJobProgressChangedDomainEventHandler.cs @@ -1,8 +1,8 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Core.MediaLibrary.Management.Progress; +using Lumina.Domain.Common.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Progress; -using Mediator; using System.Threading; using System.Threading.Tasks; #endregion @@ -10,9 +10,9 @@ using System.Threading.Tasks; namespace Lumina.Application.Core.MediaLibrary.Management.Events; /// -/// Handler for the event raised when a media library's scan progress changes. +/// Handler for the domain event raised when a media library's scan progress changes. /// -public class LibraryScanJobProgressChangedDomainEventHandler : INotificationHandler +public class LibraryScanJobProgressChangedDomainEventHandler : IDomainEventHandler { private readonly IMediaLibrariesScanProgressTracker _mediaLibrariesScanProgressTracker; private readonly IMediaLibraryScanProgressNotifier _debouncedLibraryScanProgressNotifier; @@ -35,7 +35,7 @@ public class LibraryScanJobProgressChangedDomainEventHandler : INotificationHand /// /// The domain event to be handled. /// Cancellation token that can be used to stop the execution. - public async ValueTask Handle(LibraryScanJobProgressChangedDomainEvent domainEvent, CancellationToken cancellationToken) + public async ValueTask HandleAsync(LibraryScanJobProgressChangedDomainEvent domainEvent, CancellationToken cancellationToken) { _mediaLibrariesScanProgressTracker.UpdateScanJobProgress(domainEvent.LibraryId, domainEvent.MediaLibraryScanCompositeId, domainEvent.Progress); // notify SignalR clients that the library scan progress changed diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanProgressChangedDomainEventHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanProgressChangedDomainEventHandler.cs index 42059d36..2934a173 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanProgressChangedDomainEventHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanProgressChangedDomainEventHandler.cs @@ -1,8 +1,8 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Core.MediaLibrary.Management.Progress; +using Lumina.Domain.Common.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Progress; -using Mediator; using System.Threading; using System.Threading.Tasks; #endregion @@ -10,9 +10,9 @@ using System.Threading.Tasks; namespace Lumina.Application.Core.MediaLibrary.Management.Events; /// -/// Handler for the event raised when a media library's scan progress changes. +/// Handler for the domain event raised when a media library's scan progress changes. /// -public class LibraryScanProgressChangedDomainEventHandler : INotificationHandler +public class LibraryScanProgressChangedDomainEventHandler : IDomainEventHandler { private readonly IMediaLibrariesScanProgressTracker _mediaLibrariesScanProgressTracker; private readonly IMediaLibraryScanProgressNotifier _debouncedLibraryScanProgressNotifier; @@ -35,7 +35,7 @@ public class LibraryScanProgressChangedDomainEventHandler : INotificationHandler /// /// The domain event to be handled. /// Cancellation token that can be used to stop the execution. - public async ValueTask Handle(LibraryScanProgressChangedDomainEvent domainEvent, CancellationToken cancellationToken) + public async ValueTask HandleAsync(LibraryScanProgressChangedDomainEvent domainEvent, CancellationToken cancellationToken) { _mediaLibrariesScanProgressTracker.UpdateScanProgress(domainEvent.LibraryId, domainEvent.MediaLibraryScanCompositeId); // notify SignalR clients that the library scan progress changed diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanQueuedDomainEventHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanQueuedDomainEventHandler.cs index 17ee8a78..adbaf656 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanQueuedDomainEventHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanQueuedDomainEventHandler.cs @@ -12,7 +12,6 @@ using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.Library using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services; using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects; -using Mediator; using System.Threading; using System.Threading.Tasks; #endregion @@ -20,9 +19,9 @@ using System.Threading.Tasks; namespace Lumina.Application.Core.MediaLibrary.Management.Events; /// -/// Handler for the event raised when a media library scan is queued. +/// Handler for the domain event raised when a media library scan is queued. /// -public class LibraryScanQueuedDomainEventHandler : INotificationHandler +public class LibraryScanQueuedDomainEventHandler : IDomainEventHandler { private readonly IMediaLibraryScanningService _mediaLibraryScanningService; private readonly IDomainEventsQueue _domainEventsQueue; @@ -47,7 +46,7 @@ public class LibraryScanQueuedDomainEventHandler : INotificationHandler /// The domain event to be handled. /// Cancellation token that can be used to stop the execution. - public async ValueTask Handle(LibraryScanQueuedDomainEvent domainEvent, CancellationToken cancellationToken) + public async ValueTask HandleAsync(LibraryScanQueuedDomainEvent domainEvent, CancellationToken cancellationToken) { ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository(); diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanStartedDomainEventHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanStartedDomainEventHandler.cs index b6fcfa91..a6597e5e 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanStartedDomainEventHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryScanStartedDomainEventHandler.cs @@ -3,9 +3,9 @@ using ErrorOr; using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary; using Lumina.Application.Common.DataAccess.UoW; using Lumina.Application.Common.Mapping.MediaLibrary.Management; +using Lumina.Domain.Common.Events; using Lumina.Domain.Common.Exceptions; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; -using Mediator; using System.Threading; using System.Threading.Tasks; #endregion @@ -13,9 +13,9 @@ using System.Threading.Tasks; namespace Lumina.Application.Core.MediaLibrary.Management.Events; /// -/// Handler for the event raised when a media library scan is started. +/// Handler for the domain event raised when a media library scan is started. /// -public class LibraryScanStartedDomainEventHandler : INotificationHandler +public class LibraryScanStartedDomainEventHandler : IDomainEventHandler { private readonly IUnitOfWork _unitOfWork; @@ -33,7 +33,7 @@ public class LibraryScanStartedDomainEventHandler : INotificationHandler /// The domain event to be handled. /// Cancellation token that can be used to stop the execution. - public async ValueTask Handle(LibraryScanStartedDomainEvent domainEvent, CancellationToken cancellationToken) + public async ValueTask HandleAsync(LibraryScanStartedDomainEvent domainEvent, CancellationToken cancellationToken) { ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository(); diff --git a/src/Lumina.Application/Lumina.Application.csproj b/src/Lumina.Application/Lumina.Application.csproj index 4f750cb6..73963c32 100644 --- a/src/Lumina.Application/Lumina.Application.csproj +++ b/src/Lumina.Application/Lumina.Application.csproj @@ -20,11 +20,6 @@ - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - diff --git a/src/Lumina.Domain/Common/Events/IDomainEvent.cs b/src/Lumina.Domain/Common/Events/IDomainEvent.cs index fbb4ed46..dad42f0a 100644 --- a/src/Lumina.Domain/Common/Events/IDomainEvent.cs +++ b/src/Lumina.Domain/Common/Events/IDomainEvent.cs @@ -1,5 +1,4 @@ #region ========================================================================= USING ===================================================================================== -using Mediator; using System; #endregion @@ -8,7 +7,7 @@ namespace Lumina.Domain.Common.Events; /// /// Interface defining a domain event. /// -public interface IDomainEvent : INotification +public interface IDomainEvent { /// /// Gets the Id of the domain event. diff --git a/src/Lumina.Domain/Common/Events/IDomainEventHandler.cs b/src/Lumina.Domain/Common/Events/IDomainEventHandler.cs new file mode 100644 index 00000000..9209e99d --- /dev/null +++ b/src/Lumina.Domain/Common/Events/IDomainEventHandler.cs @@ -0,0 +1,21 @@ +#region ========================================================================= USING ===================================================================================== +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Domain.Common.Events; + +/// +/// Defines a contract for handling a domain event type in the application layer. +/// +/// The type of domain event to handle. +public interface IDomainEventHandler where TDomainEvent : IDomainEvent +{ + /// + /// Handles the specified . + /// + /// The domain event to handle. + /// Token to monitor for cancellation requests. + /// A task that represents the asynchronous operation. + ValueTask HandleAsync(TDomainEvent domainEvent, CancellationToken cancellationToken); +} diff --git a/src/Lumina.Domain/Common/Events/IDomainEventPublisher.cs b/src/Lumina.Domain/Common/Events/IDomainEventPublisher.cs new file mode 100644 index 00000000..df8b69fa --- /dev/null +++ b/src/Lumina.Domain/Common/Events/IDomainEventPublisher.cs @@ -0,0 +1,20 @@ +#region ========================================================================= USING ===================================================================================== +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Domain.Common.Events; + +/// +/// Publishes domain events to all handlers registered for the event type. +/// +public interface IDomainEventPublisher +{ + /// + /// Publishes the specified to all its registered handlers, in registration order. + /// + /// The domain event to publish. + /// Token to monitor for cancellation requests. + /// A task that represents the asynchronous operation. + ValueTask PublishAsync(IDomainEvent domainEvent, CancellationToken cancellationToken = default); +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/MediaLibraryScanningService.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/MediaLibraryScanningService.cs index 47cfdd17..2c019b7e 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/MediaLibraryScanningService.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/MediaLibraryScanningService.cs @@ -9,7 +9,6 @@ using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.Library using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Scanners; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects; -using Mediator; using System; using System.Collections.Generic; using System.Threading; @@ -27,7 +26,7 @@ internal class MediaLibraryScanningService : IMediaLibraryScanningService private readonly IMediaLibraryScannerFactory _mediaLibraryScannerFactory; private readonly IMediaLibrariesScanCancellationTracker _mediaLibrariesScanCancellationTracker; private readonly IMediaLibrariesScanProgressTracker _mediaLibrariesScanProgressTracker; - private readonly IPublisher _publisher; + private readonly IDomainEventPublisher _domainEventPublisher; /// /// Initializes a new instance of the class. @@ -36,19 +35,19 @@ internal class MediaLibraryScanningService : IMediaLibraryScanningService /// Injected factory for creating media library scanners. /// Injected tracker used for canceling media library scans. /// Injected tracker used for media library scans progress. - /// The domain event publisher used to publish events. + /// The domain event publisher used to publish events. public MediaLibraryScanningService( IMediaLibrariesScanQueue mediaLibrariesScanQueue, IMediaLibraryScannerFactory mediaLibraryScannerFactory, IMediaLibrariesScanCancellationTracker mediaLibrariesScanCancellationTracker, IMediaLibrariesScanProgressTracker mediaLibrariesScanProgressTracker, - IPublisher publisher) + IDomainEventPublisher domainEventPublisher) { _mediaLibrariesScanQueue = mediaLibrariesScanQueue; _mediaLibraryScannerFactory = mediaLibraryScannerFactory; _mediaLibrariesScanCancellationTracker = mediaLibrariesScanCancellationTracker; _mediaLibrariesScanProgressTracker = mediaLibrariesScanProgressTracker; - _publisher = publisher; + _domainEventPublisher = domainEventPublisher; } /// @@ -67,7 +66,7 @@ internal class MediaLibraryScanningService : IMediaLibraryScanningService return startScanResult.Errors; foreach (IDomainEvent domainEvent in scan.GetDomainEvents()) - await _publisher!.Publish(domainEvent, cancellationToken).ConfigureAwait(false); + await _domainEventPublisher.PublishAsync(domainEvent, cancellationToken).ConfigureAwait(false); // register the scan in the tracker for cancellation tokens _mediaLibrariesScanCancellationTracker.RegisterScan(MediaLibraryScanCompositeId.Create(scan.Id, scan.UserId)); diff --git a/src/Lumina.Domain/Lumina.Domain.csproj b/src/Lumina.Domain/Lumina.Domain.csproj index db6970b3..bff52acd 100644 --- a/src/Lumina.Domain/Lumina.Domain.csproj +++ b/src/Lumina.Domain/Lumina.Domain.csproj @@ -18,7 +18,6 @@ - diff --git a/src/Lumina.Infrastructure/Common/DependencyInjection/InfrastructureLayerServices.cs b/src/Lumina.Infrastructure/Common/DependencyInjection/InfrastructureLayerServices.cs index 19232202..24080a22 100644 --- a/src/Lumina.Infrastructure/Common/DependencyInjection/InfrastructureLayerServices.cs +++ b/src/Lumina.Infrastructure/Common/DependencyInjection/InfrastructureLayerServices.cs @@ -9,6 +9,7 @@ using Lumina.Application.Common.Infrastructure.Security; using Lumina.Application.Common.Infrastructure.Time; using Lumina.Application.Common.Infrastructure.Validation; using Lumina.Application.Core.MediaLibrary.Management.Progress; +using Lumina.Domain.Common.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Cancellation; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Queue; @@ -75,6 +76,7 @@ public static class InfrastructureLayerServices services.AddSingleton(); services.AddScoped(); + services.AddScoped(); // authorization services.AddScoped(); diff --git a/src/Lumina.Infrastructure/Common/DomainEvents/DomainEventPublisher.cs b/src/Lumina.Infrastructure/Common/DomainEvents/DomainEventPublisher.cs new file mode 100644 index 00000000..3c472e9b --- /dev/null +++ b/src/Lumina.Infrastructure/Common/DomainEvents/DomainEventPublisher.cs @@ -0,0 +1,65 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Events; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Concurrent; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Infrastructure.Common.DomainEvents; + +/// +/// Publishes domain events to all handlers registered for the event type, by resolving them from the dependency injection container. +/// +public class DomainEventPublisher : IDomainEventPublisher +{ + private static readonly ConcurrentDictionary> s_dispatchers = new(); + + private readonly IServiceProvider _serviceProvider; + + /// + /// Initializes a new instance of the class. + /// + /// Injected provider used to resolve the domain event handlers. + public DomainEventPublisher(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + /// + /// Publishes the specified to all its registered handlers, in registration order. + /// + /// The domain event to publish. + /// Token to monitor for cancellation requests. + /// A task that represents the asynchronous operation. + public ValueTask PublishAsync(IDomainEvent domainEvent, CancellationToken cancellationToken = default) + { + ArgumentNullException.ThrowIfNull(domainEvent); + + Func dispatcher = s_dispatchers.GetOrAdd(domainEvent.GetType(), static eventType => + { + MethodInfo dispatchMethod = typeof(DomainEventPublisher).GetMethod(nameof(DispatchAsync), BindingFlags.NonPublic | BindingFlags.Static)! + .MakeGenericMethod(eventType); + return dispatchMethod.CreateDelegate>(); + }); + + return new ValueTask(dispatcher(domainEvent, _serviceProvider, cancellationToken)); + } + + /// + /// Dispatches the specified to all handlers registered for . + /// + /// The type of the domain event being dispatched. + /// The domain event to dispatch. + /// The provider used to resolve the domain event handlers. + /// Token to monitor for cancellation requests. + /// A task that represents the asynchronous operation. + private static async Task DispatchAsync(IDomainEvent domainEvent, IServiceProvider serviceProvider, CancellationToken cancellationToken) + where TDomainEvent : IDomainEvent + { + foreach (IDomainEventHandler handler in serviceProvider.GetServices>()) + await handler.HandleAsync((TDomainEvent)domainEvent, cancellationToken).ConfigureAwait(false); + } +} diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanDiffJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanDiffJob.cs index 8f99dab6..2b4d92cd 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanDiffJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanDiffJob.cs @@ -3,10 +3,10 @@ using ErrorOr; using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary; using Lumina.Application.Common.DataAccess.UoW; using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using Lumina.Domain.Common.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; -using Mediator; using Microsoft.Extensions.DependencyInjection; using System; using System.Threading; @@ -58,13 +58,13 @@ internal sealed class MediaLibraryScanDiffJob : MediaLibraryScanJob, IMediaLibra // see docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0001.md for details: await using AsyncServiceScope asyncServiceScope = _serviceScopeFactory.CreateAsyncScope(); IUnitOfWork unitOfWork = asyncServiceScope.ServiceProvider.GetService()!; - IPublisher publisher = asyncServiceScope.ServiceProvider.GetService()!; + IDomainEventPublisher domainEventPublisher = asyncServiceScope.ServiceProvider.GetService()!; ILibraryScanStagingResultsRepository stagingResultsRepository = unitOfWork.GetRepository(); MediaLibraryScanCompositeId compositeKey = MediaLibraryScanCompositeId.Create(ScanId, UserId); // set the initial progress of the scan job, it's a 1 step job - comparing the discovered files against the media library scan snapshot - ErrorOr publishJobProgressResult = await PublishJobProgress(publisher, compositeKey, 0, 1, cancellationToken).ConfigureAwait(false); + ErrorOr publishJobProgressResult = await PublishJobProgressAsync(domainEventPublisher, compositeKey, 0, 1, cancellationToken).ConfigureAwait(false); if (publishJobProgressResult.IsError) throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); @@ -74,12 +74,12 @@ internal sealed class MediaLibraryScanDiffJob : MediaLibraryScanJob, IMediaLibra throw new InvalidOperationException(markChangesResult.FirstError.Description); // increment the number of processed elements progress - publishJobProgressResult = await PublishJobProgress(publisher, compositeKey, 1, 1, cancellationToken).ConfigureAwait(false); + publishJobProgressResult = await PublishJobProgressAsync(domainEventPublisher, compositeKey, 1, 1, cancellationToken).ConfigureAwait(false); if (publishJobProgressResult.IsError) throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); // this job finished, increment the number of processed jobs progress - await publisher.Publish(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; // call each linked child with the obtained payload @@ -103,19 +103,19 @@ internal sealed class MediaLibraryScanDiffJob : MediaLibraryScanJob, IMediaLibra /// /// Publishes a job progress update. /// - /// The service used to publish the progress update. + /// The service used to publish the progress update. /// The composite unique identifier of a media library scan. /// The current job progress. /// The total job progress. /// Cancellation token that can be used to stop the execution. /// An representing either a successful operation, or an error. - private async Task> PublishJobProgress(IPublisher publisher, MediaLibraryScanCompositeId compositeKey, int currentProgress, int totalProgress, CancellationToken cancellationToken) + private async Task> PublishJobProgressAsync(IDomainEventPublisher domainEventPublisher, MediaLibraryScanCompositeId compositeKey, int currentProgress, int totalProgress, CancellationToken cancellationToken) { ErrorOr scanJobProgressResult = MediaLibraryScanJobProgress.Create(currentProgress, totalProgress, "ComparingFileHashes"); if (scanJobProgressResult.IsError) return scanJobProgressResult.Errors; - await publisher.Publish(new LibraryScanJobProgressChangedDomainEvent( + await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanHashJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanHashJob.cs index 4bb68c45..418be23c 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanHashJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanHashJob.cs @@ -4,10 +4,10 @@ using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary; using Lumina.Application.Common.DataAccess.UoW; using Lumina.Application.Common.Infrastructure.Security; using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using Lumina.Domain.Common.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; -using Mediator; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; @@ -62,7 +62,7 @@ internal sealed class MediaLibraryScanHashJob : MediaLibraryScanJob, IMediaLibra // see docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0001.md for details: await using AsyncServiceScope asyncServiceScope = _serviceScopeFactory.CreateAsyncScope(); IUnitOfWork unitOfWork = asyncServiceScope.ServiceProvider.GetService()!; - IPublisher publisher = asyncServiceScope.ServiceProvider.GetService()!; + IDomainEventPublisher domainEventPublisher = asyncServiceScope.ServiceProvider.GetService()!; ILibraryScanStagingResultsRepository stagingResultsRepository = unitOfWork.GetRepository(); IFileHashService fileHashService = asyncServiceScope.ServiceProvider.GetService()!; @@ -75,7 +75,7 @@ internal sealed class MediaLibraryScanHashJob : MediaLibraryScanJob, IMediaLibra int totalFilesToHash = getFilesToHashCountResult.Value; // set the initial progress of the scan job - ErrorOr publishJobProgressResult = await PublishJobProgress(publisher, compositeKey, 0, totalFilesToHash, cancellationToken).ConfigureAwait(false); + ErrorOr publishJobProgressResult = await PublishJobProgressAsync(domainEventPublisher, compositeKey, 0, totalFilesToHash, cancellationToken).ConfigureAwait(false); if (publishJobProgressResult.IsError) throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); @@ -104,7 +104,7 @@ internal sealed class MediaLibraryScanHashJob : MediaLibraryScanJob, IMediaLibra if ((now - lastUpdateTime).TotalMilliseconds >= minUpdateIntervalMs) { // increment the number of processed elements progress - publishJobProgressResult = await PublishJobProgress(publisher, compositeKey, Interlocked.Increment(ref processedFilesCount), totalFilesToHash, cancellationToken).ConfigureAwait(false); + publishJobProgressResult = await PublishJobProgressAsync(domainEventPublisher, compositeKey, Interlocked.Increment(ref processedFilesCount), totalFilesToHash, cancellationToken).ConfigureAwait(false); if (publishJobProgressResult.IsError) throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); lastUpdateTime = now; @@ -120,7 +120,7 @@ internal sealed class MediaLibraryScanHashJob : MediaLibraryScanJob, IMediaLibra } // this job finished, increment the number of processed jobs progress - await publisher.Publish(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; // call each linked child with the obtained payload @@ -144,19 +144,19 @@ internal sealed class MediaLibraryScanHashJob : MediaLibraryScanJob, IMediaLibra /// /// Publishes a job progress update. /// - /// The service used to publish the progress update. + /// The service used to publish the progress update. /// The composite unique identifier of a media library scan. /// The current job progress. /// The total job progress. /// Cancellation token that can be used to stop the execution. /// An representing either a successful operation, or an error. - private async Task> PublishJobProgress(IPublisher publisher, MediaLibraryScanCompositeId compositeKey, int currentProgress, int totalProgress, CancellationToken cancellationToken) + private async Task> PublishJobProgressAsync(IDomainEventPublisher domainEventPublisher, MediaLibraryScanCompositeId compositeKey, int currentProgress, int totalProgress, CancellationToken cancellationToken) { ErrorOr scanJobProgressResult = MediaLibraryScanJobProgress.Create(currentProgress, totalProgress, "HashingFileContents"); if (scanJobProgressResult.IsError) return scanJobProgressResult.Errors; - await publisher.Publish(new LibraryScanJobProgressChangedDomainEvent( + await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanMetadataEnrichmentJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanMetadataEnrichmentJob.cs index a134c27d..07fa670c 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanMetadataEnrichmentJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanMetadataEnrichmentJob.cs @@ -8,13 +8,13 @@ using Lumina.Application.Common.DataAccess.UoW; using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books; using Lumina.Contracts.DTO.Common; using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary; +using Lumina.Domain.Common.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate; using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Lumina.Plugins.Contracts.Core.Metadata; -using Mediator; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System; @@ -74,7 +74,7 @@ internal sealed class MediaLibraryScanMetadataEnrichmentJob : MediaLibraryScanJo // see docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0001.md for details: await using AsyncServiceScope asyncServiceScope = _serviceScopeFactory.CreateAsyncScope(); IUnitOfWork unitOfWork = asyncServiceScope.ServiceProvider.GetService()!; - IPublisher publisher = asyncServiceScope.ServiceProvider.GetService()!; + IDomainEventPublisher domainEventPublisher = asyncServiceScope.ServiceProvider.GetService()!; ILibraryMetadataProviderConfigurationRepository configurationRepository = unitOfWork.GetRepository(); IBookRepository bookRepository = unitOfWork.GetRepository(); @@ -102,7 +102,7 @@ internal sealed class MediaLibraryScanMetadataEnrichmentJob : MediaLibraryScanJo int totalBooksToEnrich = getBooksToEnrichCountResult.Value; // set the initial progress of the scan job - ErrorOr publishJobProgressResult = await PublishJobProgress(publisher, compositeKey, 0, totalBooksToEnrich, cancellationToken).ConfigureAwait(false); + ErrorOr publishJobProgressResult = await PublishJobProgressAsync(domainEventPublisher, compositeKey, 0, totalBooksToEnrich, cancellationToken).ConfigureAwait(false); if (publishJobProgressResult.IsError) throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); @@ -134,7 +134,7 @@ internal sealed class MediaLibraryScanMetadataEnrichmentJob : MediaLibraryScanJo if ((now - lastUpdateTime).TotalMilliseconds >= minUpdateIntervalMs) { // increment the number of processed elements progress - publishJobProgressResult = await PublishJobProgress(publisher, compositeKey, Interlocked.Increment(ref processedBooksCount), totalBooksToEnrich, cancellationToken).ConfigureAwait(false); + publishJobProgressResult = await PublishJobProgressAsync(domainEventPublisher, compositeKey, Interlocked.Increment(ref processedBooksCount), totalBooksToEnrich, cancellationToken).ConfigureAwait(false); if (publishJobProgressResult.IsError) throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); lastUpdateTime = now; @@ -148,7 +148,7 @@ internal sealed class MediaLibraryScanMetadataEnrichmentJob : MediaLibraryScanJo // this job finished, and it's the last in the chain, the scan is completed Status = LibraryScanJobStatus.Completed; - await publisher.Publish(new LibraryScanFinishedDomainEvent(Guid.NewGuid(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.NewGuid(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); // call each linked child with the obtained payload foreach (IMediaLibraryScanJob child in Children) @@ -242,19 +242,19 @@ internal sealed class MediaLibraryScanMetadataEnrichmentJob : MediaLibraryScanJo /// /// Publishes a job progress update. /// - /// The service used to publish the progress update. + /// The service used to publish the progress update. /// The composite unique identifier of a media library scan. /// The current job progress. /// The total job progress. /// Cancellation token that can be used to stop the execution. /// An representing either a successful operation, or an error. - private async Task> PublishJobProgress(IPublisher publisher, MediaLibraryScanCompositeId compositeKey, int currentProgress, int totalProgress, CancellationToken cancellationToken) + private async Task> PublishJobProgressAsync(IDomainEventPublisher domainEventPublisher, MediaLibraryScanCompositeId compositeKey, int currentProgress, int totalProgress, CancellationToken cancellationToken) { ErrorOr scanJobProgressResult = MediaLibraryScanJobProgress.Create(currentProgress, totalProgress, "EnrichingMetadata"); if (scanJobProgressResult.IsError) return scanJobProgressResult.Errors; - await publisher.Publish(new LibraryScanJobProgressChangedDomainEvent( + await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanResultsSaveJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanResultsSaveJob.cs index 2f8cc33a..1053b7ab 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanResultsSaveJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanResultsSaveJob.cs @@ -6,10 +6,10 @@ using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary; using Lumina.Application.Common.DataAccess.UoW; using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary; using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using Lumina.Domain.Common.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; -using Mediator; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; @@ -65,13 +65,13 @@ internal sealed class MediaLibraryScanResultsSaveJob : MediaLibraryScanJob, IMed // see docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0001.md for details: await using AsyncServiceScope asyncServiceScope = _serviceScopeFactory.CreateAsyncScope(); IUnitOfWork unitOfWork = asyncServiceScope.ServiceProvider.GetService()!; - IPublisher publisher = asyncServiceScope.ServiceProvider.GetService()!; + IDomainEventPublisher domainEventPublisher = asyncServiceScope.ServiceProvider.GetService()!; ILibraryScanSnapshotRepository libraryScanSnapshotRepository = unitOfWork.GetRepository(); MediaLibraryScanCompositeId compositeKey = MediaLibraryScanCompositeId.Create(ScanId, UserId); // set the initial progress of the scan job, it's a 1 step job - applying the scan results to the storage medium - ErrorOr publishJobProgressResult = await PublishJobProgress(publisher, compositeKey, 0, 1, cancellationToken).ConfigureAwait(false); + ErrorOr publishJobProgressResult = await PublishJobProgressAsync(domainEventPublisher, compositeKey, 0, 1, cancellationToken).ConfigureAwait(false); if (publishJobProgressResult.IsError) throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); @@ -89,7 +89,7 @@ internal sealed class MediaLibraryScanResultsSaveJob : MediaLibraryScanJob, IMed foreach (string deletedPath in getDeletedPathsResult.Value) { cancellationToken.ThrowIfCancellationRequested(); - await publisher.Publish(new LibraryMediaItemDeletedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, deletedPath, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryMediaItemDeletedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, deletedPath, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); } // materialize the books of the media library from the scan snapshot, so that they are browsable even without web metadata @@ -114,14 +114,14 @@ internal sealed class MediaLibraryScanResultsSaveJob : MediaLibraryScanJob, IMed await unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false); // increment the number of processed elements progress - publishJobProgressResult = await PublishJobProgress(publisher, compositeKey, 1, 1, cancellationToken).ConfigureAwait(false); + publishJobProgressResult = await PublishJobProgressAsync(domainEventPublisher, compositeKey, 1, 1, cancellationToken).ConfigureAwait(false); if (publishJobProgressResult.IsError) throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); Status = LibraryScanJobStatus.Completed; // when this job has no linked children, it's the last job in the directed acyclic job graph, and the scan is completed if (Children.Count == 0) - await publisher.Publish(new LibraryScanFinishedDomainEvent(Guid.NewGuid(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.NewGuid(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); // call each linked child with the obtained payload foreach (IMediaLibraryScanJob child in Children) @@ -144,19 +144,19 @@ internal sealed class MediaLibraryScanResultsSaveJob : MediaLibraryScanJob, IMed /// /// Publishes a job progress update. /// - /// The service used to publish the progress update. + /// The service used to publish the progress update. /// The composite unique identifier of a media library scan. /// The current job progress. /// The total job progress. /// Cancellation token that can be used to stop the execution. /// An representing either a successful operation, or an error. - private async Task> PublishJobProgress(IPublisher publisher, MediaLibraryScanCompositeId compositeKey, int currentProgress, int totalProgress, CancellationToken cancellationToken) + private async Task> PublishJobProgressAsync(IDomainEventPublisher domainEventPublisher, MediaLibraryScanCompositeId compositeKey, int currentProgress, int totalProgress, CancellationToken cancellationToken) { ErrorOr scanJobProgressResult = MediaLibraryScanJobProgress.Create(currentProgress, totalProgress, "SavingScanData"); if (scanJobProgressResult.IsError) return scanJobProgressResult.Errors; - await publisher.Publish(new LibraryScanJobProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; } diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/ScanFailurePublisher.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/ScanFailurePublisher.cs index 2ec45bda..cade5637 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/ScanFailurePublisher.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/ScanFailurePublisher.cs @@ -1,8 +1,8 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; -using Mediator; using Microsoft.Extensions.DependencyInjection; using System; using System.Threading; @@ -30,8 +30,8 @@ internal static class ScanFailurePublisher try { await using AsyncServiceScope asyncServiceScope = serviceScopeFactory.CreateAsyncScope(); - IPublisher publisher = asyncServiceScope.ServiceProvider.GetService()!; - await publisher.Publish(new LibraryScanFailedDomainEvent(Guid.NewGuid(), libraryId, compositeKey, DateTime.UtcNow, exception.Message), cancellationToken).ConfigureAwait(false); + IDomainEventPublisher domainEventPublisher = asyncServiceScope.ServiceProvider.GetService()!; + await domainEventPublisher.PublishAsync(new LibraryScanFailedDomainEvent(Guid.NewGuid(), libraryId, compositeKey, DateTime.UtcNow, exception.Message), cancellationToken).ConfigureAwait(false); } catch { diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksFileSystemDiscoveryJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksFileSystemDiscoveryJob.cs index afb13d77..cfe925dc 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksFileSystemDiscoveryJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksFileSystemDiscoveryJob.cs @@ -5,6 +5,7 @@ using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary; using Lumina.Application.Common.DataAccess.UoW; using Lumina.Application.Common.Mapping.MediaLibrary.Management; using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using Lumina.Domain.Common.Events; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events; @@ -12,7 +13,6 @@ using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.Library using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Jobs; using Lumina.Infrastructure.Core.MediaLibrary.Management.Scanning.Jobs.Common; -using Mediator; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; @@ -78,7 +78,7 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF // see docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0001.md for details: await using AsyncServiceScope asyncServiceScope = _serviceScopeFactory.CreateAsyncScope(); IUnitOfWork unitOfWork = asyncServiceScope.ServiceProvider.GetService()!; - IPublisher publisher = asyncServiceScope.ServiceProvider.GetService()!; + IDomainEventPublisher domainEventPublisher = asyncServiceScope.ServiceProvider.GetService()!; ILibraryRepository libraryRepository = unitOfWork.GetRepository()!; ILibraryScanStagingResultsRepository stagingResultsRepository = unitOfWork.GetRepository(); IDirectoryScanFingerprintRepository directoryScanFingerprintRepository = unitOfWork.GetRepository(); @@ -106,7 +106,7 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF } // set the initial progress of the scan job - ErrorOr publishJobProgressResult = await PublishJobProgress(publisher, compositeKey, 0, domainLibraryResult.Value.ContentLocations.Count, cancellationToken).ConfigureAwait(false); + ErrorOr publishJobProgressResult = await PublishJobProgressAsync(domainEventPublisher, compositeKey, 0, domainLibraryResult.Value.ContentLocations.Count, cancellationToken).ConfigureAwait(false); if (publishJobProgressResult.IsError) throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); @@ -137,8 +137,8 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF DateTime now = DateTime.UtcNow; if (now - lastHeartbeat >= heartbeatInterval) { - publishJobProgressResult = await PublishJobProgress( - publisher, compositeKey, processedContentLocations, domainLibraryResult.Value.ContentLocations.Count, cancellationToken).ConfigureAwait(false); + publishJobProgressResult = await PublishJobProgressAsync( + domainEventPublisher, compositeKey, processedContentLocations, domainLibraryResult.Value.ContentLocations.Count, cancellationToken).ConfigureAwait(false); if (publishJobProgressResult.IsError) throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); lastHeartbeat = now; @@ -160,7 +160,7 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF } // this job finished, increment the number of processed jobs progress - await publisher.Publish(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; // call each linked child with the obtained payload @@ -321,19 +321,19 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF /// /// Publishes a job progress update. /// - /// The service used to publish the progress update. + /// The service used to publish the progress update. /// The composite unique identifier of a media library scan. /// The current job progress. /// The total job progress. /// Cancellation token that can be used to stop the execution. /// An representing either a successful operation, or an error. - private async Task> PublishJobProgress(IPublisher publisher, MediaLibraryScanCompositeId compositeKey, int currentProgress, int totalProgress, CancellationToken cancellationToken) + private async Task> PublishJobProgressAsync(IDomainEventPublisher domainEventPublisher, MediaLibraryScanCompositeId compositeKey, int currentProgress, int totalProgress, CancellationToken cancellationToken) { ErrorOr scanJobProgressResult = MediaLibraryScanJobProgress.Create(currentProgress, totalProgress, "DiscoveringFiles"); if (scanJobProgressResult.IsError) return scanJobProgressResult.Errors; - await publisher.Publish(new LibraryScanJobProgressChangedDomainEvent( + await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; diff --git a/src/Lumina.Presentation.Api/Common/Middlewares/EventualConsistencyMiddleware.cs b/src/Lumina.Presentation.Api/Common/Middlewares/EventualConsistencyMiddleware.cs index 6d552c84..7f16b977 100644 --- a/src/Lumina.Presentation.Api/Common/Middlewares/EventualConsistencyMiddleware.cs +++ b/src/Lumina.Presentation.Api/Common/Middlewares/EventualConsistencyMiddleware.cs @@ -3,7 +3,6 @@ using Lumina.Application.Common.DomainEvents; using Lumina.DataAccess.Core.UoW; using Lumina.Domain.Common.Events; using Lumina.Domain.Common.Exceptions; -using Mediator; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.Logging; @@ -35,10 +34,10 @@ public class EventualConsistencyMiddleware /// Handles incoming HTTP requests and ensures that domain events are published and the database transaction is committed upon successful request completion. /// /// The current HTTP context. - /// The domain event publisher used to publish events. + /// The domain event publisher used to publish events. /// The database context used to manage the transaction. /// In memory queue containing the queued domain events. - public async Task InvokeAsync(HttpContext context, IPublisher publisher, LuminaDbContext dbContext, IDomainEventsQueue domainEventQueue) + public async Task InvokeAsync(HttpContext context, IDomainEventPublisher domainEventPublisher, LuminaDbContext dbContext, IDomainEventsQueue domainEventQueue) { // begin a new database transaction - this will wrap any database operations performed during this HTTP request in an atomic operation IDbContextTransaction transaction = await dbContext.Database.BeginTransactionAsync(context.RequestAborted).ConfigureAwait(false); @@ -59,7 +58,7 @@ public class EventualConsistencyMiddleware // check if domain events exist in the channel queue and publish them while (domainEventQueue.TryDequeue(out IDomainEvent? nextEvent)) - await publisher.Publish(nextEvent); + await domainEventPublisher.PublishAsync(nextEvent); } } catch (EventualConsistencyException ex) diff --git a/src/Lumina.Presentation.Api/Lumina.Presentation.Api.csproj b/src/Lumina.Presentation.Api/Lumina.Presentation.Api.csproj index 824a6c6f..a1a29f78 100644 --- a/src/Lumina.Presentation.Api/Lumina.Presentation.Api.csproj +++ b/src/Lumina.Presentation.Api/Lumina.Presentation.Api.csproj @@ -24,7 +24,6 @@ - diff --git a/src/Lumina.Presentation.Web/Lumina.Presentation.Web.csproj b/src/Lumina.Presentation.Web/Lumina.Presentation.Web.csproj index e6639816..1d093b6a 100644 --- a/src/Lumina.Presentation.Web/Lumina.Presentation.Web.csproj +++ b/src/Lumina.Presentation.Web/Lumina.Presentation.Web.csproj @@ -357,7 +357,6 @@ - $(NoWarn);TS6385 diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Common/CQRS/HandlersCallTheirValidatorsTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Common/CQRS/HandlersCallTheirValidatorsTests.cs index 72fb5b9f..0672be4a 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Common/CQRS/HandlersCallTheirValidatorsTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Common/CQRS/HandlersCallTheirValidatorsTests.cs @@ -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 s_opCodes = BuildOpCodeLookup(); /// /// 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; } + /// + /// Checks whether the IL of the specified contains a call to . + /// + /// The method whose IL is inspected. + /// The closed validator interface whose Validate method is being looked for. + /// if the method calls the validator, otherwise. 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.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.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; } + + /// + /// Builds a lookup table of all opcodes, keyed by their numeric value. + /// + /// The built lookup table. + private static Dictionary BuildOpCodeLookup() + { + Dictionary 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; + } + + /// + /// Gets the size in bytes of the operand of the specified . + /// + /// The opcode whose operand size is returned. + /// The size of the operand in bytes. + 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, + }; + } + + /// + /// Reads a 4-byte little-endian integer from the specified offset in the IL stream. + /// + /// The IL byte stream. + /// The offset at which to read the integer. + /// The read integer. + private static int ReadInt32(byte[] il, int offset) + { + return il[offset] | (il[offset + 1] << 8) | (il[offset + 2] << 16) | (il[offset + 3] << 24); + } } diff --git a/tests/UnitTests/Lumina.Infrastructure.UnitTests/Common/DomainEvents/DomainEventPublisherTests.cs b/tests/UnitTests/Lumina.Infrastructure.UnitTests/Common/DomainEvents/DomainEventPublisherTests.cs new file mode 100644 index 00000000..77250d85 --- /dev/null +++ b/tests/UnitTests/Lumina.Infrastructure.UnitTests/Common/DomainEvents/DomainEventPublisherTests.cs @@ -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; + +/// +/// Contains unit tests for the class. +/// +[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 + { + private readonly List _callLog; + private readonly string _handlerName; + + public RecordingDomainEventHandler(List callLog, string handlerName) + { + _callLog = callLog; + _handlerName = handlerName; + } + + public ValueTask HandleAsync(TestDomainEvent domainEvent, CancellationToken cancellationToken) + { + _callLog.Add(_handlerName); + return ValueTask.CompletedTask; + } + } + + /// + /// Creates a publisher wired to a fresh service provider, optionally registering additional services. + /// + /// Optional action used to register additional services into the provider. + /// A domain event publisher resolved from the created provider. + private static IDomainEventPublisher CreatePublisher(Action? configureServices = null) + { + IServiceCollection services = new ServiceCollection(); + services.AddScoped(); + configureServices?.Invoke(services); + ServiceProvider serviceProvider = services.BuildServiceProvider(); + return serviceProvider.GetRequiredService(); + } + + /// + /// Creates a valid instance of . + /// + /// The created domain event. + private static TestDomainEvent CreateTestDomainEvent() + { + return new TestDomainEvent(Guid.NewGuid(), DateTime.UtcNow); + } + + /// + /// Creates a valid instance of . + /// + /// The created domain event. + private static NestedTestDomainEvent CreateNestedTestDomainEvent() + { + return new NestedTestDomainEvent(Guid.NewGuid(), DateTime.UtcNow); + } + + [Fact] + public async Task Publish_WhenHandlersAreRegistered_ShouldInvokeAllHandlersInOrder() + { + // Arrange + TestDomainEvent domainEvent = CreateTestDomainEvent(); + List callLog = []; + IDomainEventPublisher publisher = CreatePublisher(services => + { + services.AddScoped>(_ => new RecordingDomainEventHandler(callLog, "first")); + services.AddScoped>(_ => 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 nestedHandler = Substitute.For>(); + IDomainEventPublisher publisher = CreatePublisher(services => services.AddScoped(_ => nestedHandler)); + + // Act + await publisher.PublishAsync(domainEvent, CancellationToken.None); + + // Assert + await nestedHandler.DidNotReceive().HandleAsync(Arg.Any(), Arg.Any()); + } + + [Fact] + public async Task Publish_WhenHandlerThrows_ShouldPropagateTheException() + { + // Arrange + TestDomainEvent domainEvent = CreateTestDomainEvent(); + InvalidOperationException expectedException = new("Test exception"); + IDomainEventHandler handler = Substitute.For>(); + handler.HandleAsync(Arg.Any(), Arg.Any()) + .Returns(callInfo => throw expectedException); + IDomainEventPublisher publisher = CreatePublisher(services => services.AddScoped>(_ => handler)); + + // Act + InvalidOperationException result = await Assert.ThrowsAsync( + () => 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 handler = Substitute.For>(); + IDomainEventHandler nestedHandler = Substitute.For>(); + IDomainEventPublisher publisher = CreatePublisher(services => + { + services.AddScoped(_ => handler); + services.AddScoped(_ => nestedHandler); + }); + handler.HandleAsync(domainEvent, Arg.Any()) + .Returns(callInfo => publisher.PublishAsync(nestedDomainEvent, callInfo.Arg())); + + // Act + await publisher.PublishAsync(domainEvent, CancellationToken.None); + + // Assert + await nestedHandler.Received(1).HandleAsync(nestedDomainEvent, Arg.Any()); + } + + [Fact] + public async Task Publish_WhenCancellationRequested_ShouldPassTokenToHandlers() + { + // Arrange + TestDomainEvent domainEvent = CreateTestDomainEvent(); + using CancellationTokenSource cancellationTokenSource = new(); + CancellationToken cancellationToken = cancellationTokenSource.Token; + IDomainEventHandler handler = Substitute.For>(); + 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(() => publisher.PublishAsync(null!, CancellationToken.None).AsTask()); + + // Assert + Assert.Equal("domainEvent", result.ParamName); + } +} diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Permissions/GetPermissions/GetPermissionsEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Permissions/GetPermissions/GetPermissionsEndpointTests.cs index 019b85bb..fec666db 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Permissions/GetPermissions/GetPermissionsEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Permissions/GetPermissions/GetPermissionsEndpointTests.cs @@ -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; diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/AddRole/AddRoleEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/AddRole/AddRoleEndpointTests.cs index 88dc40e0..b1cc0e5f 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/AddRole/AddRoleEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/AddRole/AddRoleEndpointTests.cs @@ -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()]); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/DeleteRole/DeleteRoleEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/DeleteRole/DeleteRoleEndpointTests.cs index 11bff369..20399910 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/DeleteRole/DeleteRoleEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/DeleteRole/DeleteRoleEndpointTests.cs @@ -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()); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/GetRolePermissions/GetRolePermissionsEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/GetRolePermissions/GetRolePermissionsEndpointTests.cs index 9cadf1c4..ed31a762 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/GetRolePermissions/GetRolePermissionsEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/GetRolePermissions/GetRolePermissionsEndpointTests.cs @@ -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()); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/GetRoles/GetRolesEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/GetRoles/GetRolesEndpointTests.cs index 1dec0f66..4d4059db 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/GetRoles/GetRolesEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/GetRoles/GetRolesEndpointTests.cs @@ -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; diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/UpdateRole/UpdateRoleEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/UpdateRole/UpdateRoleEndpointTests.cs index 0a032355..e36bc26c 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/UpdateRole/UpdateRoleEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Admin/Authorization/Roles/UpdateRole/UpdateRoleEndpointTests.cs @@ -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()]); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Directories/GetDirectoriesEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Directories/GetDirectoriesEndpointTests.cs index e577f527..d0403a76 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Directories/GetDirectoriesEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Directories/GetDirectoriesEndpointTests.cs @@ -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(); @@ -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(); @@ -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(); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Drives/GetDrivesEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Drives/GetDrivesEndpointTests.cs index e9e9b779..28c9223b 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Drives/GetDrivesEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Drives/GetDrivesEndpointTests.cs @@ -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; diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/FileSystem/GetTypeEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/FileSystem/GetTypeEndpointTests.cs index df170ab2..7a0d5075 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/FileSystem/GetTypeEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/FileSystem/GetTypeEndpointTests.cs @@ -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; diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Files/GetFilesEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Files/GetFilesEndpointTests.cs index f3053458..0e207562 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Files/GetFilesEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Files/GetFilesEndpointTests.cs @@ -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(); @@ -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(); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Files/GetTreeFilesEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Files/GetTreeFilesEndpointTests.cs index 41cee5d6..455ce8be 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Files/GetTreeFilesEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Files/GetTreeFilesEndpointTests.cs @@ -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(); @@ -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(); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/CheckPathExistsEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/CheckPathExistsEndpointTests.cs index ad359faa..86ade8a8 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/CheckPathExistsEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/CheckPathExistsEndpointTests.cs @@ -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); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/CombinePathEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/CombinePathEndpointTests.cs index f5979ee7..cbc83e0c 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/CombinePathEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/CombinePathEndpointTests.cs @@ -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"); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/GetPathParentEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/GetPathParentEndpointTests.cs index 63fe5b00..ec7c18f5 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/GetPathParentEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/GetPathParentEndpointTests.cs @@ -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"); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/GetPathRootEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/GetPathRootEndpointTests.cs index 69c8fd28..96ad81fb 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/GetPathRootEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/GetPathRootEndpointTests.cs @@ -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"); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/GetPathSeparatorEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/GetPathSeparatorEndpointTests.cs index 0390c563..39d4baf2 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/GetPathSeparatorEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/GetPathSeparatorEndpointTests.cs @@ -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; diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/SplitPathEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/SplitPathEndpointTests.cs index f5082467..3eadf322 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/SplitPathEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/SplitPathEndpointTests.cs @@ -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"); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/ValidatePathEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/ValidatePathEndpointTests.cs index 0eb9062f..3cd52a83 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/ValidatePathEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Path/ValidatePathEndpointTests.cs @@ -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"); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Thumbnails/GetThumbnailEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Thumbnails/GetThumbnailEndpointTests.cs index 7778f1c9..9fd3fcfd 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Thumbnails/GetThumbnailEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/FileSystemManagement/Thumbnails/GetThumbnailEndpointTests.cs @@ -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); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Maintenance/ApplicationSetup/CheckInitializationEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Maintenance/ApplicationSetup/CheckInitializationEndpointTests.cs index 04d038c1..53e94a62 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Maintenance/ApplicationSetup/CheckInitializationEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Maintenance/ApplicationSetup/CheckInitializationEndpointTests.cs @@ -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; diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Maintenance/ApplicationSetup/SetupApplicationEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Maintenance/ApplicationSetup/SetupApplicationEndpointTests.cs index 70ec7c6d..25381421 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Maintenance/ApplicationSetup/SetupApplicationEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/Maintenance/ApplicationSetup/SetupApplicationEndpointTests.cs @@ -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(); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/ChangePassword/ChangePasswordEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/ChangePassword/ChangePasswordEndpointTests.cs index 69cff8d3..c72a5ce6 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/ChangePassword/ChangePasswordEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/ChangePassword/ChangePasswordEndpointTests.cs @@ -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(); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/GetUsers/GetUsersEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/GetUsers/GetUsersEndpointTests.cs index ed1f4389..e366677f 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/GetUsers/GetUsersEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/GetUsers/GetUsersEndpointTests.cs @@ -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; diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/Login/LoginEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/Login/LoginEndpointTests.cs index 8168dcd7..06e08639 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/Login/LoginEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/Login/LoginEndpointTests.cs @@ -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(); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/RecoverPassword/RecoverPasswordEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/RecoverPassword/RecoverPasswordEndpointTests.cs index 66b276e8..51cfc579 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/RecoverPassword/RecoverPasswordEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/RecoverPassword/RecoverPasswordEndpointTests.cs @@ -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(); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/Register/RegisterEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/Register/RegisterEndpointTests.cs index c3727d3d..36a54655 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/Register/RegisterEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authentication/Register/RegisterEndpointTests.cs @@ -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(); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/GetAuthorization/GetAuthorizationEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/GetAuthorization/GetAuthorizationEndpointTests.cs index 009fb74e..11a20c0a 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/GetAuthorization/GetAuthorizationEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/GetAuthorization/GetAuthorizationEndpointTests.cs @@ -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(); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/GetUserPermissions/GetUserPermissionsEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/GetUserPermissions/GetUserPermissionsEndpointTests.cs index 90cff0dc..d44fca3f 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/GetUserPermissions/GetUserPermissionsEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/GetUserPermissions/GetUserPermissionsEndpointTests.cs @@ -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()); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/GetUserRole/GetUserRoleEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/GetUserRole/GetUserRoleEndpointTests.cs index 89985b68..dfc6627d 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/GetUserRole/GetUserRoleEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/GetUserRole/GetUserRoleEndpointTests.cs @@ -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()); diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/UpdateUserRoleAndPermissions/UpdateUserRoleAndPermissionsEndpointTests.cs b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/UpdateUserRoleAndPermissions/UpdateUserRoleAndPermissionsEndpointTests.cs index 1ebf4845..9b4235c7 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/UpdateUserRoleAndPermissions/UpdateUserRoleAndPermissionsEndpointTests.cs +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Core/Endpoints/UsersManagement/Authorization/UpdateUserRoleAndPermissions/UpdateUserRoleAndPermissionsEndpointTests.cs @@ -64,7 +64,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests } [Fact] - public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult() + public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult() { // Arrange UpdateUserRoleAndPermissionsRequest request = new(