diff --git a/tests/CoreCraft.Tests/Features/CoW/CoWRelationTests.cs b/tests/CoreCraft.Tests/Features/CoW/CoWRelationTests.cs index 814c89e7..c2289627 100644 --- a/tests/CoreCraft.Tests/Features/CoW/CoWRelationTests.cs +++ b/tests/CoreCraft.Tests/Features/CoW/CoWRelationTests.cs @@ -104,6 +104,26 @@ public void RemoveWhenNotCopiedTest() .MustHaveHappenedOnceExactly(); } + [Test] + public void RemoveParentWhenNotCopiedTest() + { + var copy = A.Fake>(c => c + .Implements>()); + var inner = A.Fake>(c => c + .Implements>()); + var relation = new CoWRelation(inner); + + A.CallTo(() => inner.Copy()).Returns(copy); + + relation.Remove(new()); + + A.CallTo(() => inner.Copy()).MustHaveHappenedOnceExactly(); + A.CallTo(() => ((IMutableRelation)inner).Remove(A.Ignored)) + .MustNotHaveHappened(); + A.CallTo(() => ((IMutableRelation)copy).Remove(A.Ignored)) + .MustHaveHappenedOnceExactly(); + } + [Test] public void RemoveWhenCopiedTest() { diff --git a/tests/CoreCraft.Tests/Features/Tracking/TrackableRelationTests.cs b/tests/CoreCraft.Tests/Features/Tracking/TrackableRelationTests.cs index 62b1012d..89da05e8 100644 --- a/tests/CoreCraft.Tests/Features/Tracking/TrackableRelationTests.cs +++ b/tests/CoreCraft.Tests/Features/Tracking/TrackableRelationTests.cs @@ -57,6 +57,28 @@ public void TrackableRemoveFromRelationTest() Assert.That(_changes.Single().Child, Is.EqualTo(second)); } + [Test] + public void TrackableRemoveParentFromRelationTest() + { + var first = new FirstEntity(); + var second = new SecondEntity(); + var third = new SecondEntity(); + + A.CallTo(() => _relation.Children(first)).Returns([second, third]); + + _trackable!.Remove(first); + + Assert.That(_changes!.HasChanges(), Is.True); + Assert.That(_changes.First().Action, Is.EqualTo(RelationAction.Unlinked)); + Assert.That(_changes.First().Parent, Is.EqualTo(first)); + Assert.That(_changes.First().Child, Is.EqualTo(second)); + + Assert.That(_changes!.HasChanges(), Is.True); + Assert.That(_changes.Last().Action, Is.EqualTo(RelationAction.Unlinked)); + Assert.That(_changes.Last().Parent, Is.EqualTo(first)); + Assert.That(_changes.Last().Child, Is.EqualTo(third)); + } + [Test] public void TrackableRelationContainsParentTest() {