diff --git a/Modules/Quotas/src/Quotas.Application/DomainEvents/Incoming/RelationshipCreated/RelationshipCreatedDomainEventHandler.cs b/Modules/Quotas/src/Quotas.Application/DomainEvents/Incoming/RelationshipCreated/RelationshipCreatedDomainEventHandler.cs deleted file mode 100644 index 021e9d7579..0000000000 --- a/Modules/Quotas/src/Quotas.Application/DomainEvents/Incoming/RelationshipCreated/RelationshipCreatedDomainEventHandler.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.EventBus; -using Backbone.Modules.Quotas.Application.Metrics; -using Backbone.Modules.Quotas.Domain.DomainEvents.Incoming.RelationshipCreated; -using MetricKey = Backbone.Modules.Quotas.Domain.Aggregates.Metrics.MetricKey; - -namespace Backbone.Modules.Quotas.Application.DomainEvents.Incoming.RelationshipCreated; - -public class RelationshipCreatedDomainEventHandler : IDomainEventHandler -{ - private readonly IMetricStatusesService _metricStatusesService; - - public RelationshipCreatedDomainEventHandler(IMetricStatusesService metricStatusesService) - { - _metricStatusesService = metricStatusesService; - } - - public async Task Handle(RelationshipCreatedDomainEvent @event) - { - var affectedIdentities = new List { @event.From }; - - await _metricStatusesService.RecalculateMetricStatuses(affectedIdentities, [MetricKey.NumberOfRelationships], CancellationToken.None); - } -} diff --git a/Modules/Quotas/src/Quotas.Application/Extensions/IEventBusExtensions.cs b/Modules/Quotas/src/Quotas.Application/Extensions/IEventBusExtensions.cs index bd47adcc00..ad836fbedd 100644 --- a/Modules/Quotas/src/Quotas.Application/Extensions/IEventBusExtensions.cs +++ b/Modules/Quotas/src/Quotas.Application/Extensions/IEventBusExtensions.cs @@ -3,7 +3,6 @@ using Backbone.Modules.Quotas.Application.DomainEvents.Incoming.IdentityCreated; using Backbone.Modules.Quotas.Application.DomainEvents.Incoming.MessageCreated; using Backbone.Modules.Quotas.Application.DomainEvents.Incoming.QuotaCreatedForTier; -using Backbone.Modules.Quotas.Application.DomainEvents.Incoming.RelationshipCreated; using Backbone.Modules.Quotas.Application.DomainEvents.Incoming.RelationshipStatusChanged; using Backbone.Modules.Quotas.Application.DomainEvents.Incoming.RelationshipTemplateCreated; using Backbone.Modules.Quotas.Application.DomainEvents.Incoming.TierCreated; @@ -14,7 +13,6 @@ using Backbone.Modules.Quotas.Domain.DomainEvents.Incoming.FileUploaded; using Backbone.Modules.Quotas.Domain.DomainEvents.Incoming.IdentityCreated; using Backbone.Modules.Quotas.Domain.DomainEvents.Incoming.MessageCreated; -using Backbone.Modules.Quotas.Domain.DomainEvents.Incoming.RelationshipCreated; using Backbone.Modules.Quotas.Domain.DomainEvents.Incoming.RelationshipStatusChanged; using Backbone.Modules.Quotas.Domain.DomainEvents.Incoming.RelationshipTemplateCreated; using Backbone.Modules.Quotas.Domain.DomainEvents.Incoming.TierCreated; @@ -41,7 +39,6 @@ private static void SubscribeToSynchronizationEvents(IEventBus eventBus) eventBus.Subscribe(); eventBus.Subscribe(); eventBus.Subscribe(); - eventBus.Subscribe(); eventBus.Subscribe(); eventBus.Subscribe(); eventBus.Subscribe(); diff --git a/Modules/Quotas/src/Quotas.Domain/DomainEvents/Incoming/RelationshipCreated/RelationshipCreatedDomainEvent.cs b/Modules/Quotas/src/Quotas.Domain/DomainEvents/Incoming/RelationshipCreated/RelationshipCreatedDomainEvent.cs deleted file mode 100644 index c8d5ab65ed..0000000000 --- a/Modules/Quotas/src/Quotas.Domain/DomainEvents/Incoming/RelationshipCreated/RelationshipCreatedDomainEvent.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Backbone.BuildingBlocks.Domain.Events; - -namespace Backbone.Modules.Quotas.Domain.DomainEvents.Incoming.RelationshipCreated; - -public class RelationshipCreatedDomainEvent : DomainEvent -{ - public required string RelationshipId { get; set; } - public required string From { get; set; } - public required string To { get; set; } -} diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/CreateRelationship/Handler.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/CreateRelationship/Handler.cs index 8c0a92c855..b798426500 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/CreateRelationship/Handler.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/CreateRelationship/Handler.cs @@ -2,10 +2,10 @@ using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.EventBus; using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.UserContext; using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Relationships.Application.DomainEvents.Outgoing; using Backbone.Modules.Relationships.Application.Infrastructure.Persistence.Repository; using Backbone.Modules.Relationships.Domain.Aggregates.Relationships; using Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates; +using Backbone.Modules.Relationships.Domain.DomainEvents.Outgoing; using MediatR; namespace Backbone.Modules.Relationships.Application.Relationships.Commands.CreateRelationship; @@ -78,6 +78,6 @@ private async Task CreateAndSaveRelationship() private void PublishDomainEvent() { - _eventBus.Publish(new RelationshipCreatedDomainEvent(_relationship)); + _eventBus.Publish(new RelationshipStatusChangedDomainEvent(_relationship)); } } diff --git a/Modules/Relationships/src/Relationships.Domain/DomainEvents/Outgoing/RelationshipCreatedDomainEvent.cs b/Modules/Relationships/src/Relationships.Domain/DomainEvents/Outgoing/RelationshipCreatedDomainEvent.cs deleted file mode 100644 index 11894d9d65..0000000000 --- a/Modules/Relationships/src/Relationships.Domain/DomainEvents/Outgoing/RelationshipCreatedDomainEvent.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Backbone.BuildingBlocks.Domain.Events; -using Backbone.Modules.Relationships.Domain.Aggregates.Relationships; - -namespace Backbone.Modules.Relationships.Application.DomainEvents.Outgoing; - -public class RelationshipCreatedDomainEvent : DomainEvent -{ - public RelationshipCreatedDomainEvent(Relationship relationship) : base($"{relationship.Id}/Created") - { - RelationshipId = relationship.Id; - From = relationship.From; - To = relationship.To; - } - - public string RelationshipId { get; set; } - public string From { get; } - public string To { get; } -} diff --git a/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/CreateRelationship/HandlerTests.cs b/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/CreateRelationship/HandlerTests.cs index 8f33d51e2b..719ecd90e9 100644 --- a/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/CreateRelationship/HandlerTests.cs +++ b/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/CreateRelationship/HandlerTests.cs @@ -2,11 +2,11 @@ using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.EventBus; using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.UserContext; using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Relationships.Application.DomainEvents.Outgoing; using Backbone.Modules.Relationships.Application.Infrastructure.Persistence.Repository; using Backbone.Modules.Relationships.Application.Relationships.Commands.CreateRelationship; using Backbone.Modules.Relationships.Domain.Aggregates.Relationships; using Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates; +using Backbone.Modules.Relationships.Domain.DomainEvents.Outgoing; using Backbone.Tooling; using Backbone.UnitTestTools.Data; using Backbone.UnitTestTools.Extensions; @@ -120,7 +120,7 @@ public void Throws_when_no_template_with_given_id_exists() } [Fact] - public async Task Publishes_RelationshipCreatedDomainEvent() + public async Task Publishes_RelationshipStatusChangedDomainEvent() { // Arrange SystemTime.Set("2020-01-01"); @@ -153,7 +153,7 @@ await handler.Handle(new CreateRelationshipCommand }, CancellationToken.None); // Assert - A.CallTo(() => mockEventBus.Publish(A.That.Matches(e => e.From == activeIdentity, relationshipTemplate.CreatedBy))).MustHaveHappenedOnceExactly(); + A.CallTo(() => mockEventBus.Publish(A.That.Matches(e => e.Initiator == activeIdentity, relationshipTemplate.CreatedBy))).MustHaveHappenedOnceExactly(); } private static Handler CreateHandler(IRelationshipTemplatesRepository relationshipTemplatesRepository) diff --git a/Modules/Synchronization/src/Synchronization.Application/DomainEvents/Incoming/RelationshipCreated/RelationshipCreatedDomainEventHandler.cs b/Modules/Synchronization/src/Synchronization.Application/DomainEvents/Incoming/RelationshipCreated/RelationshipCreatedDomainEventHandler.cs deleted file mode 100644 index fc0b59a5ce..0000000000 --- a/Modules/Synchronization/src/Synchronization.Application/DomainEvents/Incoming/RelationshipCreated/RelationshipCreatedDomainEventHandler.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.EventBus; -using Backbone.Modules.Synchronization.Application.DomainEvents.Outgoing; -using Backbone.Modules.Synchronization.Application.Infrastructure; -using Backbone.Modules.Synchronization.Domain.DomainEvents.Incoming.RelationshipCreated; -using Backbone.Modules.Synchronization.Domain.Entities.Sync; -using Microsoft.Extensions.Logging; - -namespace Backbone.Modules.Synchronization.Application.DomainEvents.Incoming.RelationshipCreated; - -public class RelationshipCreatedDomainEventHandler : IDomainEventHandler -{ - private readonly ISynchronizationDbContext _dbContext; - private readonly IEventBus _eventBus; - private readonly ILogger _logger; - - public RelationshipCreatedDomainEventHandler(ISynchronizationDbContext dbContext, IEventBus eventBus, ILogger logger) - { - _dbContext = dbContext; - _eventBus = eventBus; - _logger = logger; - } - - public async Task Handle(RelationshipCreatedDomainEvent @event) - { -#pragma warning disable IDE0037 - var payload = new { RelationshipId = @event.RelationshipId }; -#pragma warning restore IDE0037 - try - { - var externalEvent = await _dbContext.CreateExternalEvent(@event.To, ExternalEventType.RelationshipCreated, payload); - _eventBus.Publish(new ExternalEventCreatedDomainEvent(externalEvent)); - } - catch (Exception ex) - { - _logger.LogError(ex, "An error occured while processing an Domain event."); - throw; - } - } -} diff --git a/Modules/Synchronization/src/Synchronization.Application/Extensions/IEventBusExtensions.cs b/Modules/Synchronization/src/Synchronization.Application/Extensions/IEventBusExtensions.cs index 93c01428a6..4bb7bf11d9 100644 --- a/Modules/Synchronization/src/Synchronization.Application/Extensions/IEventBusExtensions.cs +++ b/Modules/Synchronization/src/Synchronization.Application/Extensions/IEventBusExtensions.cs @@ -2,12 +2,10 @@ using Backbone.Modules.Synchronization.Application.DomainEvents.Incoming.IdentityDeletionProcessStarted; using Backbone.Modules.Synchronization.Application.DomainEvents.Incoming.IdentityDeletionProcessStatusChanged; using Backbone.Modules.Synchronization.Application.DomainEvents.Incoming.MessageCreated; -using Backbone.Modules.Synchronization.Application.DomainEvents.Incoming.RelationshipCreated; using Backbone.Modules.Synchronization.Application.DomainEvents.Incoming.RelationshipStatusChanged; using Backbone.Modules.Synchronization.Domain.DomainEvents.Incoming.IdentityDeletionProcessStarted; using Backbone.Modules.Synchronization.Domain.DomainEvents.Incoming.IdentityDeletionProcessStatusChanged; using Backbone.Modules.Synchronization.Domain.DomainEvents.Incoming.MessageCreated; -using Backbone.Modules.Synchronization.Domain.DomainEvents.Incoming.RelationshipCreated; using Backbone.Modules.Synchronization.Domain.DomainEvents.Incoming.RelationshipStatusChanged; namespace Backbone.Modules.Synchronization.Application.Extensions; @@ -32,7 +30,6 @@ private static void SubscribeToMessagesEvents(IEventBus eventBus) private static void SubscribeToRelationshipsEvents(IEventBus eventBus) { - eventBus.Subscribe(); eventBus.Subscribe(); } } diff --git a/Modules/Synchronization/src/Synchronization.Application/SyncRuns/DTOs/ExternalEventDTO.cs b/Modules/Synchronization/src/Synchronization.Application/SyncRuns/DTOs/ExternalEventDTO.cs index 671a392474..133e51d069 100644 --- a/Modules/Synchronization/src/Synchronization.Application/SyncRuns/DTOs/ExternalEventDTO.cs +++ b/Modules/Synchronization/src/Synchronization.Application/SyncRuns/DTOs/ExternalEventDTO.cs @@ -19,7 +19,6 @@ public void CreateMappings(Profile configuration) { ExternalEventType.MessageDelivered => "MessageDelivered", ExternalEventType.MessageReceived => "MessageReceived", - ExternalEventType.RelationshipCreated => "RelationshipCreated", ExternalEventType.RelationshipStatusChanged => "RelationshipStatusChanged", _ => throw new ArgumentOutOfRangeException(nameof(externalEventType), externalEventType, null) }); diff --git a/Modules/Synchronization/src/Synchronization.Domain/DomainEvents/Incoming/RelationshipCreated/RelationshipCreatedDomainEvent.cs b/Modules/Synchronization/src/Synchronization.Domain/DomainEvents/Incoming/RelationshipCreated/RelationshipCreatedDomainEvent.cs deleted file mode 100644 index 0fd4e78351..0000000000 --- a/Modules/Synchronization/src/Synchronization.Domain/DomainEvents/Incoming/RelationshipCreated/RelationshipCreatedDomainEvent.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Backbone.BuildingBlocks.Domain.Events; - -namespace Backbone.Modules.Synchronization.Domain.DomainEvents.Incoming.RelationshipCreated; - -public class RelationshipCreatedDomainEvent : DomainEvent -{ - public required string RelationshipId { get; set; } - public required string From { get; set; } - public required string To { get; set; } -} diff --git a/Modules/Synchronization/src/Synchronization.Domain/Entities/Sync/ExternalEvent.cs b/Modules/Synchronization/src/Synchronization.Domain/Entities/Sync/ExternalEvent.cs index a3c7e2b98c..5ca2d7a0b9 100644 --- a/Modules/Synchronization/src/Synchronization.Domain/Entities/Sync/ExternalEvent.cs +++ b/Modules/Synchronization/src/Synchronization.Domain/Entities/Sync/ExternalEvent.cs @@ -58,8 +58,7 @@ public enum ExternalEventType { MessageReceived = 0, MessageDelivered = 1, - RelationshipCreated = 2, - RelationshipStatusChanged = 3, - IdentityDeletionProcessStarted = 4, - IdentityDeletionProcessStatusChanged = 5 + RelationshipStatusChanged = 2, + IdentityDeletionProcessStarted = 3, + IdentityDeletionProcessStatusChanged = 4 } diff --git a/Modules/Synchronization/test/Synchronization.Application.Tests/Tests/DomainEvents/RelationshipCreatedDomainEventHandlerTests.cs b/Modules/Synchronization/test/Synchronization.Application.Tests/Tests/DomainEvents/RelationshipCreatedDomainEventHandlerTests.cs deleted file mode 100644 index 73d14f5cb5..0000000000 --- a/Modules/Synchronization/test/Synchronization.Application.Tests/Tests/DomainEvents/RelationshipCreatedDomainEventHandlerTests.cs +++ /dev/null @@ -1,91 +0,0 @@ -using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.EventBus; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Synchronization.Application.DomainEvents.Incoming.RelationshipCreated; -using Backbone.Modules.Synchronization.Application.DomainEvents.Outgoing; -using Backbone.Modules.Synchronization.Application.Infrastructure; -using Backbone.Modules.Synchronization.Domain.DomainEvents.Incoming.RelationshipCreated; -using Backbone.Modules.Synchronization.Domain.Entities.Sync; -using FakeItEasy; -using Microsoft.Extensions.Logging; -using Xunit; - -namespace Backbone.Modules.Synchronization.Application.Tests.Tests.DomainEvents; - -public class RelationshipCreatedDomainEventHandlerTests -{ - [Fact] - public async Task Creates_an_external_event() - { - // Arrange - var relationshipFrom = TestDataGenerator.CreateRandomIdentityAddress(); - var relationshipTo = TestDataGenerator.CreateRandomIdentityAddress(); - var @event = new RelationshipCreatedDomainEvent - { - RelationshipId = "REL1", - From = relationshipFrom, - To = relationshipTo - }; - - var mockDbContext = A.Fake(); - - var externalEvent = new ExternalEvent(ExternalEventType.RelationshipCreated, relationshipTo, 1, - new { @event.RelationshipId }); - - A.CallTo(() => mockDbContext.CreateExternalEvent( - relationshipTo, - ExternalEventType.RelationshipCreated, - A._) - ).Returns(externalEvent); - - var handler = CreateHandler(mockDbContext); - - // Act - await handler.Handle(@event); - - // Assert - A.CallTo(() => mockDbContext.CreateExternalEvent(relationshipTo, ExternalEventType.RelationshipCreated, A._)) - .MustHaveHappenedOnceExactly(); - } - - [Fact] - public async Task Publishes_an_ExternalEventCreatedDomainEvent() - { - // Arrange - var relationshipFrom = TestDataGenerator.CreateRandomIdentityAddress(); - var relationshipTo = TestDataGenerator.CreateRandomIdentityAddress(); - var @event = new RelationshipCreatedDomainEvent - { - RelationshipId = "REL1", - From = relationshipFrom, - To = relationshipTo - }; - - var fakeDbContext = A.Fake(); - var mockEventBus = A.Fake(); - - var externalEvent = new ExternalEvent(ExternalEventType.IdentityDeletionProcessStarted, IdentityAddress.Parse(relationshipTo), 1, - new { @event.RelationshipId }); - - A.CallTo(() => fakeDbContext.CreateExternalEvent( - relationshipTo, - ExternalEventType.RelationshipCreated, - A._) - ).Returns(externalEvent); - - var handler = CreateHandler(fakeDbContext, mockEventBus); - - // Act - await handler.Handle(@event); - - // Assert - A.CallTo(() => mockEventBus.Publish( - A.That.Matches(e => e.Owner == relationshipTo)) - ).MustHaveHappenedOnceExactly(); - } - - private RelationshipCreatedDomainEventHandler CreateHandler(ISynchronizationDbContext dbContext, IEventBus? eventBus = null) - { - eventBus ??= A.Fake(); - return new RelationshipCreatedDomainEventHandler(dbContext, eventBus, A.Fake>()); - } -}