Skip to content

Commit

Permalink
added unit tests for Remove(Parent)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNav73 committed Jun 15, 2024
1 parent 52d73ca commit d1b67fd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/CoreCraft.Tests/Features/CoW/CoWRelationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ public void RemoveWhenNotCopiedTest()
.MustHaveHappenedOnceExactly();
}

[Test]
public void RemoveParentWhenNotCopiedTest()
{
var copy = A.Fake<IRelation<FirstEntity, SecondEntity>>(c => c
.Implements<IMutableRelation<FirstEntity, SecondEntity>>());
var inner = A.Fake<IRelation<FirstEntity, SecondEntity>>(c => c
.Implements<IMutableRelation<FirstEntity, SecondEntity>>());
var relation = new CoWRelation<FirstEntity, SecondEntity>(inner);

A.CallTo(() => inner.Copy()).Returns(copy);

relation.Remove(new());

A.CallTo(() => inner.Copy()).MustHaveHappenedOnceExactly();
A.CallTo(() => ((IMutableRelation<FirstEntity, SecondEntity>)inner).Remove(A<FirstEntity>.Ignored))
.MustNotHaveHappened();
A.CallTo(() => ((IMutableRelation<FirstEntity, SecondEntity>)copy).Remove(A<FirstEntity>.Ignored))
.MustHaveHappenedOnceExactly();
}

[Test]
public void RemoveWhenCopiedTest()
{
Expand Down
22 changes: 22 additions & 0 deletions tests/CoreCraft.Tests/Features/Tracking/TrackableRelationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit d1b67fd

Please sign in to comment.