From 364b443a230c75a64b3cae0474b1572194d02347 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Fri, 5 Jul 2024 15:02:03 +0200 Subject: [PATCH] tests: add decomposition tests --- .../Relationships/AcceptRelationshipTests.cs | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) 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..7006bc22ff 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 @@ -112,4 +112,87 @@ public void Raises_RelationshipStatusChangedDomainEvent() domainEvent.Initiator.Should().Be(relationship.LastModifiedBy); domainEvent.Peer.Should().Be(relationship.GetPeerOf(relationship.LastModifiedBy)); } + + [Fact] + public void P1_active_identity_P1_not_decomposed_P2_decomposed() + { + // Arrange + var existingRelationships = CreateRelationships(); + + existingRelationships.First().Terminate(IDENTITY_2, DEVICE_2); + existingRelationships.First().Decompose(IDENTITY_2, DEVICE_2); + + // Act + var newRelationship = new Relationship(RELATIONSHIP_TEMPLATE_OF_1, IDENTITY_2, DEVICE_2, null, existingRelationships); + + var acting = () => newRelationship.Accept(IDENTITY_1, DEVICE_1, [], existingRelationships); + + // Assert + acting.Should().Throw().WithError("error.platform.validation.relationshipRequest.oldRelationshipNotDecomposed"); + } + + [Fact] + public void P1_active_identity_P1_decomposed_P2_not_decomposed() + { + // Arrange + var existingRelationships = CreateRelationships(); + + existingRelationships.First().Terminate(IDENTITY_2, DEVICE_2); + existingRelationships.First().Decompose(IDENTITY_2, DEVICE_2); + + // Act + var newRelationship = new Relationship(RELATIONSHIP_TEMPLATE_OF_1, IDENTITY_2, DEVICE_2, null, existingRelationships); + + existingRelationships.First().Decompose(IDENTITY_1, DEVICE_1); + newRelationship.Accept(IDENTITY_1, DEVICE_1, [], existingRelationships); + + // Assert + newRelationship.Status.Should().Be(RelationshipStatus.Active); + } + + [Fact] + public void P2_active_identity_P1_not_decomposed_P2_decomposed() + { + // Arrange + var existingRelationships = CreateRelationships(); + + existingRelationships.First().Terminate(IDENTITY_1, DEVICE_1); + existingRelationships.First().Decompose(IDENTITY_1, DEVICE_1); + + // Act + var newRelationship = new Relationship(RELATIONSHIP_TEMPLATE_OF_2, IDENTITY_1, DEVICE_1, null, existingRelationships); + + var acting = () => newRelationship.Accept(IDENTITY_2, DEVICE_2, [], existingRelationships); + + // Assert + acting.Should().Throw().WithError("error.platform.validation.relationshipRequest.oldRelationshipNotDecomposed"); + } + + [Fact] + public void P2_active_identity_P1_decomposed_P2_not_decomposed() + { + // Arrange + var existingRelationships = CreateRelationships(); + + existingRelationships.First().Terminate(IDENTITY_1, DEVICE_1); + existingRelationships.First().Decompose(IDENTITY_1, DEVICE_1); + + // Act + var newRelationship = new Relationship(RELATIONSHIP_TEMPLATE_OF_2, IDENTITY_1, DEVICE_1, null, existingRelationships); + + existingRelationships.First().Decompose(IDENTITY_2, DEVICE_2); + newRelationship.Accept(IDENTITY_2, DEVICE_2, [], existingRelationships); + + // Assert + newRelationship.Status.Should().Be(RelationshipStatus.Active); + } + + private static List CreateRelationships() + { + var existingRelationships = new List + { + CreateActiveRelationship(IDENTITY_1, IDENTITY_2) + }; + return existingRelationships; + } }