From ea16edcdab76de9064e471eae0a24b3a13467f8f Mon Sep 17 00:00:00 2001 From: Timo Notheisen <65653426+tnotheis@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:13:40 +0200 Subject: [PATCH] Relationship decompose route does not exist (#724) * chore: remove unused nuget packages * refactor: rename RelationshipStatusChangedDomainEvent.Status to NewStatus * fix: only create external event in case of RelationshipStatusChangedDomainEvent if new status is not "ReadyForDeletion" * feat: remove RelationshipDecomposedDomainEvent * feat: add missing ExternalEventType mappings to ExternalEventDTO * fix: add route --- AdminApi/src/AdminApi/AdminApi.csproj | 71 ++++++++-------- .../AdminApi.Tests.Integration.csproj | 1 - .../ConsumerApi.Tests.Integration.csproj | 45 +++++------ ConsumerApi/ConsumerApi.csproj | 81 +++++++++---------- .../Devices.AdminCli/Devices.AdminCli.csproj | 5 +- .../Files.Jobs.SanityCheck.csproj | 11 ++- .../Controllers/RelationshipsController.cs | 11 +++ .../RelationshipStatusChangedDomainEvent.cs | 4 +- .../Relationships/AcceptRelationshipTests.cs | 2 +- .../Relationships/CreateRelationshipTests.cs | 2 +- .../DecomposeRelationshipTests.cs | 2 +- .../Relationships/RejectRelationshipTests.cs | 2 +- .../Relationships/RevokeRelationshipTests.cs | 2 +- .../TerminateRelationshipTests.cs | 2 +- ...elationshipDecomposedDomainEventHandler.cs | 41 ---------- ...tionshipStatusChangedDomainEventHandler.cs | 6 ++ .../SyncRuns/DTOs/ExternalEventDTO.cs | 13 ++- .../RelationshipDecomposedDomainEvent.cs | 15 ---- .../RelationshipStatusChangedDomainEvent.cs | 1 + .../Entities/Sync/ExternalEvent.cs | 1 - ...onshipDecomposedDomainEventHandlerTests.cs | 43 ---------- ...hipStatusChangedDomainEventHandlerTests.cs | 39 ++++++++- 22 files changed, 176 insertions(+), 224 deletions(-) delete mode 100644 Modules/Synchronization/src/Synchronization.Application/DomainEvents/Incoming/RelationshipDecomposed/RelationshipDecomposedDomainEventHandler.cs delete mode 100644 Modules/Synchronization/src/Synchronization.Domain/DomainEvents/Incoming/RelationshipDecomposed/RelationshipDecomposedDomainEvent.cs delete mode 100644 Modules/Synchronization/test/Synchronization.Application.Tests/Tests/DomainEvents/RelationshipDecomposedDomainEventHandlerTests.cs diff --git a/AdminApi/src/AdminApi/AdminApi.csproj b/AdminApi/src/AdminApi/AdminApi.csproj index af2a8c89e9..c67d9a2709 100644 --- a/AdminApi/src/AdminApi/AdminApi.csproj +++ b/AdminApi/src/AdminApi/AdminApi.csproj @@ -8,74 +8,73 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + - - - + + + - - + + - + - - + + - - - - - - - - - - - + + + + + + + + + + + - - - + + + - + - + - - - + + + - - + + - + wwwroot\%(RecursiveDir)%(FileName)%(Extension) PreserveNewest diff --git a/AdminApi/test/AdminApi.Tests.Integration/AdminApi.Tests.Integration.csproj b/AdminApi/test/AdminApi.Tests.Integration/AdminApi.Tests.Integration.csproj index 8cd4f55b73..1d4a2a9502 100644 --- a/AdminApi/test/AdminApi.Tests.Integration/AdminApi.Tests.Integration.csproj +++ b/AdminApi/test/AdminApi.Tests.Integration/AdminApi.Tests.Integration.csproj @@ -15,7 +15,6 @@ - diff --git a/ConsumerApi.Tests.Integration/ConsumerApi.Tests.Integration.csproj b/ConsumerApi.Tests.Integration/ConsumerApi.Tests.Integration.csproj index 6aee665f69..e0ff8ce74f 100644 --- a/ConsumerApi.Tests.Integration/ConsumerApi.Tests.Integration.csproj +++ b/ConsumerApi.Tests.Integration/ConsumerApi.Tests.Integration.csproj @@ -3,24 +3,23 @@ false - + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -28,20 +27,20 @@ - - - + + + - Always + Always - Always + Always - Always + Always diff --git a/ConsumerApi/ConsumerApi.csproj b/ConsumerApi/ConsumerApi.csproj index 6396fa5a86..8132e79c47 100644 --- a/ConsumerApi/ConsumerApi.csproj +++ b/ConsumerApi/ConsumerApi.csproj @@ -1,48 +1,47 @@  - - f114fba8-95dd-4fee-8385-af8e8a343c68 - + + f114fba8-95dd-4fee-8385-af8e8a343c68 + - - - - - - - - - - - + + + + + + + + + + - all - runtime; build; native; contentfiles; analyzers; buildtransitive - true - - - - - - - - - - - - + all + runtime; build; native; contentfiles; analyzers; buildtransitive + true + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/Modules/Devices/src/Devices.AdminCli/Devices.AdminCli.csproj b/Modules/Devices/src/Devices.AdminCli/Devices.AdminCli.csproj index a978ebd426..0c2dfff8a7 100644 --- a/Modules/Devices/src/Devices.AdminCli/Devices.AdminCli.csproj +++ b/Modules/Devices/src/Devices.AdminCli/Devices.AdminCli.csproj @@ -10,12 +10,11 @@ - - + - + diff --git a/Modules/Files/src/Files.Jobs.SanityCheck/Files.Jobs.SanityCheck.csproj b/Modules/Files/src/Files.Jobs.SanityCheck/Files.Jobs.SanityCheck.csproj index 2b301c7447..aa8133e46b 100644 --- a/Modules/Files/src/Files.Jobs.SanityCheck/Files.Jobs.SanityCheck.csproj +++ b/Modules/Files/src/Files.Jobs.SanityCheck/Files.Jobs.SanityCheck.csproj @@ -6,15 +6,14 @@ - - - + + - - - + + + diff --git a/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs b/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs index 7c16a911d6..ac31312853 100644 --- a/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs +++ b/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs @@ -9,6 +9,7 @@ using Backbone.Modules.Relationships.Application.Relationships.Commands.AcceptRelationship; using Backbone.Modules.Relationships.Application.Relationships.Commands.AcceptRelationshipReactivation; using Backbone.Modules.Relationships.Application.Relationships.Commands.CreateRelationship; +using Backbone.Modules.Relationships.Application.Relationships.Commands.DecomposeRelationship; using Backbone.Modules.Relationships.Application.Relationships.Commands.RejectRelationship; using Backbone.Modules.Relationships.Application.Relationships.Commands.RejectRelationshipReactivation; using Backbone.Modules.Relationships.Application.Relationships.Commands.RequestRelationshipReactivation; @@ -184,6 +185,16 @@ public async Task RejectReactivationOfRelationship([FromRoute] st return Ok(response); } + [HttpPut("{id}/Decompose")] + [ProducesResponseType(typeof(HttpResponseEnvelopeResult), StatusCodes.Status200OK)] + [ProducesError(StatusCodes.Status400BadRequest)] + [ProducesError(StatusCodes.Status404NotFound)] + public async Task DecomposeRelationship([FromRoute] string id, CancellationToken cancellationToken) + { + var response = await _mediator.Send(new DecomposeRelationshipCommand { RelationshipId = id }, cancellationToken); + return Ok(response); + } + private async Task EnsurePeerIsNotToBeDeleted(string peerIdentityAddress, CancellationToken cancellationToken) { var peerIdentity = await _mediator.Send(new GetIdentityQuery(peerIdentityAddress), cancellationToken); diff --git a/Modules/Relationships/src/Relationships.Domain/DomainEvents/Outgoing/RelationshipStatusChangedDomainEvent.cs b/Modules/Relationships/src/Relationships.Domain/DomainEvents/Outgoing/RelationshipStatusChangedDomainEvent.cs index ccb65d9df7..c50aaff369 100644 --- a/Modules/Relationships/src/Relationships.Domain/DomainEvents/Outgoing/RelationshipStatusChangedDomainEvent.cs +++ b/Modules/Relationships/src/Relationships.Domain/DomainEvents/Outgoing/RelationshipStatusChangedDomainEvent.cs @@ -10,13 +10,13 @@ public RelationshipStatusChangedDomainEvent(Relationship relationship) : base( $"{relationship.Id}/StatusChanged/{relationship.AuditLog.OrderBy(a => a.CreatedAt).Last().CreatedAt.ToUniversalString()}") { RelationshipId = relationship.Id; - Status = relationship.Status.ToString(); + NewStatus = relationship.Status.ToString(); Initiator = relationship.LastModifiedBy; Peer = relationship.GetPeerOf(relationship.LastModifiedBy); } public string RelationshipId { get; set; } - public string Status { get; set; } + public string NewStatus { get; set; } public string Initiator { get; set; } public string Peer { get; set; } } diff --git a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/AcceptRelationshipTests.cs b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/AcceptRelationshipTests.cs index 0fb4759f9a..a1a7c4ef1a 100644 --- a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/AcceptRelationshipTests.cs +++ b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/AcceptRelationshipTests.cs @@ -108,7 +108,7 @@ public void Raises_RelationshipStatusChangedDomainEvent() // Assert var domainEvent = relationship.Should().HaveASingleDomainEvent(); domainEvent.RelationshipId.Should().Be(relationship.Id); - domainEvent.Status.Should().Be(relationship.Status.ToString()); + domainEvent.NewStatus.Should().Be(relationship.Status.ToString()); domainEvent.Initiator.Should().Be(relationship.LastModifiedBy); domainEvent.Peer.Should().Be(relationship.GetPeerOf(relationship.LastModifiedBy)); } diff --git a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/CreateRelationshipTests.cs b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/CreateRelationshipTests.cs index 174a7a07f8..b1185fd0d8 100644 --- a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/CreateRelationshipTests.cs +++ b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/CreateRelationshipTests.cs @@ -45,7 +45,7 @@ public void Raises_RelationshipStatusChangedDomainEvent() // Assert var domainEvent = relationship.Should().HaveASingleDomainEvent(); domainEvent.RelationshipId.Should().Be(relationship.Id); - domainEvent.Status.Should().Be("Pending"); + domainEvent.NewStatus.Should().Be("Pending"); domainEvent.Initiator.Should().Be(IDENTITY_1); domainEvent.Peer.Should().Be(IDENTITY_2); } diff --git a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/DecomposeRelationshipTests.cs b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/DecomposeRelationshipTests.cs index b6d1886505..bfb9e1c673 100644 --- a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/DecomposeRelationshipTests.cs +++ b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/DecomposeRelationshipTests.cs @@ -54,7 +54,7 @@ public void Raises_RelationshipStatusChangedDomainEvent() // Assert var domainEvent = relationship.Should().HaveASingleDomainEvent(); domainEvent.RelationshipId.Should().Be(relationship.Id); - domainEvent.Status.Should().Be(relationship.Status.ToString()); + domainEvent.NewStatus.Should().Be(relationship.Status.ToString()); domainEvent.Initiator.Should().Be(relationship.LastModifiedBy); domainEvent.Peer.Should().Be(relationship.GetPeerOf(relationship.LastModifiedBy)); } diff --git a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RejectRelationshipTests.cs b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RejectRelationshipTests.cs index da035436af..169f07aa08 100644 --- a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RejectRelationshipTests.cs +++ b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RejectRelationshipTests.cs @@ -64,7 +64,7 @@ public void Raises_RelationshipStatusChangedDomainEvent() // Assert var domainEvent = relationship.Should().HaveASingleDomainEvent(); domainEvent.RelationshipId.Should().Be(relationship.Id); - domainEvent.Status.Should().Be(relationship.Status.ToString()); + domainEvent.NewStatus.Should().Be(relationship.Status.ToString()); domainEvent.Initiator.Should().Be(relationship.LastModifiedBy); domainEvent.Peer.Should().Be(relationship.GetPeerOf(relationship.LastModifiedBy)); } diff --git a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RevokeRelationshipTests.cs b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RevokeRelationshipTests.cs index ae9551eeea..945e2c6fa2 100644 --- a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RevokeRelationshipTests.cs +++ b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RevokeRelationshipTests.cs @@ -64,7 +64,7 @@ public void Raises_RelationshipStatusChangedDomainEvent() // Assert var domainEvent = relationship.Should().HaveASingleDomainEvent(); domainEvent.RelationshipId.Should().Be(relationship.Id); - domainEvent.Status.Should().Be(relationship.Status.ToString()); + domainEvent.NewStatus.Should().Be(relationship.Status.ToString()); domainEvent.Initiator.Should().Be(relationship.LastModifiedBy); domainEvent.Peer.Should().Be(relationship.GetPeerOf(relationship.LastModifiedBy)); } diff --git a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/TerminateRelationshipTests.cs b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/TerminateRelationshipTests.cs index a8ff269e2b..3ba430478c 100644 --- a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/TerminateRelationshipTests.cs +++ b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/TerminateRelationshipTests.cs @@ -64,7 +64,7 @@ public void Raises_RelationshipStatusChangedDomainEvent() // Assert var domainEvent = relationship.Should().HaveASingleDomainEvent(); domainEvent.RelationshipId.Should().Be(relationship.Id); - domainEvent.Status.Should().Be(relationship.Status.ToString()); + domainEvent.NewStatus.Should().Be(relationship.Status.ToString()); domainEvent.Initiator.Should().Be(relationship.LastModifiedBy); domainEvent.Peer.Should().Be(relationship.GetPeerOf(relationship.LastModifiedBy)); } diff --git a/Modules/Synchronization/src/Synchronization.Application/DomainEvents/Incoming/RelationshipDecomposed/RelationshipDecomposedDomainEventHandler.cs b/Modules/Synchronization/src/Synchronization.Application/DomainEvents/Incoming/RelationshipDecomposed/RelationshipDecomposedDomainEventHandler.cs deleted file mode 100644 index 30a7d8bc97..0000000000 --- a/Modules/Synchronization/src/Synchronization.Application/DomainEvents/Incoming/RelationshipDecomposed/RelationshipDecomposedDomainEventHandler.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.EventBus; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Synchronization.Application.Infrastructure; -using Backbone.Modules.Synchronization.Domain.DomainEvents.Incoming.RelationshipDecomposed; -using Backbone.Modules.Synchronization.Domain.Entities.Sync; -using Microsoft.Extensions.Logging; - -namespace Backbone.Modules.Synchronization.Application.DomainEvents.Incoming.RelationshipDecomposed; - -public class RelationshipDecomposedDomainEventHandler : IDomainEventHandler -{ - private readonly ISynchronizationDbContext _dbContext; - private readonly ILogger _logger; - - public RelationshipDecomposedDomainEventHandler(ISynchronizationDbContext dbContext, ILogger logger) - { - _dbContext = dbContext; - _logger = logger; - } - - public async Task Handle(RelationshipDecomposedDomainEvent integrationEvent) - { - await CreateExternalEvents(integrationEvent); - } - - private async Task CreateExternalEvents(RelationshipDecomposedDomainEvent @event) - { -#pragma warning disable IDE0037 - var payload = new { RelationshipId = @event.RelationshipId }; -#pragma warning restore IDE0037 - try - { - await _dbContext.CreateExternalEvent(IdentityAddress.Parse(@event.Peer), ExternalEventType.RelationshipDecomposedByPeer, payload); - } - catch (Exception ex) - { - _logger.LogError(ex, "An error occured while processing an integration event."); - throw; - } - } -} diff --git a/Modules/Synchronization/src/Synchronization.Application/DomainEvents/Incoming/RelationshipStatusChanged/RelationshipStatusChangedDomainEventHandler.cs b/Modules/Synchronization/src/Synchronization.Application/DomainEvents/Incoming/RelationshipStatusChanged/RelationshipStatusChangedDomainEventHandler.cs index e4efe9799c..24b39c2d96 100644 --- a/Modules/Synchronization/src/Synchronization.Application/DomainEvents/Incoming/RelationshipStatusChanged/RelationshipStatusChangedDomainEventHandler.cs +++ b/Modules/Synchronization/src/Synchronization.Application/DomainEvents/Incoming/RelationshipStatusChanged/RelationshipStatusChangedDomainEventHandler.cs @@ -19,6 +19,12 @@ public RelationshipStatusChangedDomainEventHandler(ISynchronizationDbContext dbC public async Task Handle(RelationshipStatusChangedDomainEvent @event) { + // if the relationship is in status "ReadyForDeletion", the peer doesn't know anything about it; therefore we must not create an external event + if (@event.NewStatus == "ReadyForDeletion") + { + return; + } + #pragma warning disable IDE0037 var payload = new { RelationshipId = @event.RelationshipId }; #pragma warning restore IDE0037 diff --git a/Modules/Synchronization/src/Synchronization.Application/SyncRuns/DTOs/ExternalEventDTO.cs b/Modules/Synchronization/src/Synchronization.Application/SyncRuns/DTOs/ExternalEventDTO.cs index e00e57896c..d53d86d165 100644 --- a/Modules/Synchronization/src/Synchronization.Application/SyncRuns/DTOs/ExternalEventDTO.cs +++ b/Modules/Synchronization/src/Synchronization.Application/SyncRuns/DTOs/ExternalEventDTO.cs @@ -17,14 +17,19 @@ public void CreateMappings(Profile configuration) { configuration.CreateMap().ConvertUsing((externalEventType, _) => externalEventType switch { - ExternalEventType.MessageDelivered => "MessageDelivered", ExternalEventType.MessageReceived => "MessageReceived", + ExternalEventType.MessageDelivered => "MessageDelivered", + ExternalEventType.RelationshipStatusChanged => "RelationshipStatusChanged", - ExternalEventType.IdentityDeletionProcessStarted => "IdentityDeletionProcessStarted", - ExternalEventType.IdentityDeletionProcessStatusChanged => "IdentityDeletionProcessStatusChanged", ExternalEventType.RelationshipReactivationRequested => "RelationshipReactivationRequested", ExternalEventType.RelationshipReactivationCompleted => "RelationshipReactivationCompleted", - ExternalEventType.RelationshipDecomposedByPeer => "RelationshipDecomposedByPeer", + + ExternalEventType.IdentityDeletionProcessStarted => "IdentityDeletionProcessStarted", + ExternalEventType.IdentityDeletionProcessStatusChanged => "IdentityDeletionProcessStatusChanged", + ExternalEventType.PeerToBeDeleted => "PeerToBeDeleted", + ExternalEventType.PeerDeletionCancelled => "PeerDeletionCancelled", + ExternalEventType.PeerDeleted => "PeerDeleted", + _ => throw new ArgumentOutOfRangeException(nameof(externalEventType), externalEventType, null) }); configuration.CreateMap(); diff --git a/Modules/Synchronization/src/Synchronization.Domain/DomainEvents/Incoming/RelationshipDecomposed/RelationshipDecomposedDomainEvent.cs b/Modules/Synchronization/src/Synchronization.Domain/DomainEvents/Incoming/RelationshipDecomposed/RelationshipDecomposedDomainEvent.cs deleted file mode 100644 index 6885ed2def..0000000000 --- a/Modules/Synchronization/src/Synchronization.Domain/DomainEvents/Incoming/RelationshipDecomposed/RelationshipDecomposedDomainEvent.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Backbone.BuildingBlocks.Domain.Events; - -namespace Backbone.Modules.Synchronization.Domain.DomainEvents.Incoming.RelationshipDecomposed; - -public class RelationshipDecomposedDomainEvent : DomainEvent -{ - public RelationshipDecomposedDomainEvent(string relationshipId, string peer) : base($"{relationshipId}/Decompose") - { - RelationshipId = relationshipId; - Peer = peer; - } - - public string RelationshipId { get; } - public string Peer { get; } -} diff --git a/Modules/Synchronization/src/Synchronization.Domain/DomainEvents/Incoming/RelationshipStatusChanged/RelationshipStatusChangedDomainEvent.cs b/Modules/Synchronization/src/Synchronization.Domain/DomainEvents/Incoming/RelationshipStatusChanged/RelationshipStatusChangedDomainEvent.cs index cd1937ee1b..d902cf4ceb 100644 --- a/Modules/Synchronization/src/Synchronization.Domain/DomainEvents/Incoming/RelationshipStatusChanged/RelationshipStatusChangedDomainEvent.cs +++ b/Modules/Synchronization/src/Synchronization.Domain/DomainEvents/Incoming/RelationshipStatusChanged/RelationshipStatusChangedDomainEvent.cs @@ -6,4 +6,5 @@ public class RelationshipStatusChangedDomainEvent : DomainEvent { public required string RelationshipId { get; set; } public required string Peer { get; set; } + public required string NewStatus { 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 37335eb4ec..fce73a18d0 100644 --- a/Modules/Synchronization/src/Synchronization.Domain/Entities/Sync/ExternalEvent.cs +++ b/Modules/Synchronization/src/Synchronization.Domain/Entities/Sync/ExternalEvent.cs @@ -66,7 +66,6 @@ public enum ExternalEventType RelationshipStatusChanged = 10, RelationshipReactivationRequested = 12, RelationshipReactivationCompleted = 13, - RelationshipDecomposedByPeer = 14, IdentityDeletionProcessStarted = 20, IdentityDeletionProcessStatusChanged = 21, diff --git a/Modules/Synchronization/test/Synchronization.Application.Tests/Tests/DomainEvents/RelationshipDecomposedDomainEventHandlerTests.cs b/Modules/Synchronization/test/Synchronization.Application.Tests/Tests/DomainEvents/RelationshipDecomposedDomainEventHandlerTests.cs deleted file mode 100644 index 836b0560f0..0000000000 --- a/Modules/Synchronization/test/Synchronization.Application.Tests/Tests/DomainEvents/RelationshipDecomposedDomainEventHandlerTests.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Synchronization.Application.DomainEvents.Incoming.RelationshipDecomposed; -using Backbone.Modules.Synchronization.Application.Infrastructure; -using Backbone.Modules.Synchronization.Domain.DomainEvents.Incoming.RelationshipDecomposed; -using Backbone.Modules.Synchronization.Domain.Entities.Sync; -using Backbone.UnitTestTools.BaseClasses; -using FakeItEasy; -using Microsoft.Extensions.Logging; -using Xunit; - -namespace Backbone.Modules.Synchronization.Application.Tests.Tests.DomainEvents; - -public class RelationshipDecomposedDomainEventHandlerTests : AbstractTestsBase -{ - [Fact] - public async Task Creates_an_external_event() - { - // Arrange - var identityAddress = TestDataGenerator.CreateRandomIdentityAddress(); - var relationshipReactivationCompletedIntegrationEvent = new RelationshipDecomposedDomainEvent("someRelationshipId", identityAddress); - - var mockDbContext = A.Fake(); - - var externalEvent = new ExternalEvent(ExternalEventType.RelationshipDecomposedByPeer, IdentityAddress.Parse(identityAddress), 1, - new { relationshipReactivationCompletedIntegrationEvent.RelationshipId }); - - A.CallTo(() => mockDbContext.CreateExternalEvent( - identityAddress, - ExternalEventType.RelationshipDecomposedByPeer, - A._) - ).Returns(externalEvent); - - var handler = new RelationshipDecomposedDomainEventHandler(mockDbContext, - A.Fake>()); - - // Act - await handler.Handle(relationshipReactivationCompletedIntegrationEvent); - - // Assert - A.CallTo(() => mockDbContext.CreateExternalEvent(identityAddress, ExternalEventType.RelationshipDecomposedByPeer, A._)) - .MustHaveHappenedOnceExactly(); - } -} diff --git a/Modules/Synchronization/test/Synchronization.Application.Tests/Tests/DomainEvents/RelationshipStatusChangedDomainEventHandlerTests.cs b/Modules/Synchronization/test/Synchronization.Application.Tests/Tests/DomainEvents/RelationshipStatusChangedDomainEventHandlerTests.cs index 6fc8079b34..09d1a28127 100644 --- a/Modules/Synchronization/test/Synchronization.Application.Tests/Tests/DomainEvents/RelationshipStatusChangedDomainEventHandlerTests.cs +++ b/Modules/Synchronization/test/Synchronization.Application.Tests/Tests/DomainEvents/RelationshipStatusChangedDomainEventHandlerTests.cs @@ -1,4 +1,5 @@ -using Backbone.Modules.Synchronization.Application.DomainEvents.Incoming.RelationshipStatusChanged; +using Backbone.DevelopmentKit.Identity.ValueObjects; +using Backbone.Modules.Synchronization.Application.DomainEvents.Incoming.RelationshipStatusChanged; using Backbone.Modules.Synchronization.Application.Infrastructure; using Backbone.Modules.Synchronization.Domain.DomainEvents.Incoming.RelationshipStatusChanged; using Backbone.Modules.Synchronization.Domain.Entities.Sync; @@ -19,7 +20,8 @@ public async Task Creates_an_external_event() var @event = new RelationshipStatusChangedDomainEvent { RelationshipId = "REL1", - Peer = relationshipTo + Peer = relationshipTo, + NewStatus = "Pending" }; var mockDbContext = A.Fake(); @@ -43,6 +45,39 @@ public async Task Creates_an_external_event() .MustHaveHappenedOnceExactly(); } + [Fact] + public async Task Does_not_create_an_external_event_if_new_status_is_ReadyForDeletion() + { + // Arrange + var relationshipTo = TestDataGenerator.CreateRandomIdentityAddress(); + var @event = new RelationshipStatusChangedDomainEvent + { + RelationshipId = "REL1", + Peer = relationshipTo, + NewStatus = "ReadyForDeletion" + }; + + var mockDbContext = A.Fake(); + + var externalEvent = new ExternalEvent(ExternalEventType.RelationshipStatusChanged, relationshipTo, 1, + new { @event.RelationshipId }); + + A.CallTo(() => mockDbContext.CreateExternalEvent( + relationshipTo, + ExternalEventType.RelationshipStatusChanged, + A._) + ).Returns(externalEvent); + + var handler = CreateHandler(mockDbContext); + + // Act + await handler.Handle(@event); + + // Assert + A.CallTo(() => mockDbContext.CreateExternalEvent(A._, A._, A._)) + .MustNotHaveHappened(); + } + private RelationshipStatusChangedDomainEventHandler CreateHandler(ISynchronizationDbContext dbContext) { return new RelationshipStatusChangedDomainEventHandler(dbContext, A.Fake>());