Skip to content

Commit 9bc4c57

Browse files
committed
Introduced unit test for validating the IsDeleted handling
This unit test creates a `TopicsDataTable` and a `RelationshipsDataTable` and passes them to the `LoadTopicGraph()` extension method, ensuring that the (private) `SetRelationships()` extension method correctly utilizes the data tables to _delete_ the specified relationship on the new `Topic` entity, since it is marked as `IsDeleted`.
1 parent fc5bb9a commit 9bc4c57

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

OnTopic.Tests/SqlTopicRepositoryTest.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,34 @@ public void LoadTopicGraph_WithMissingReference_NotFullyLoaded() {
189189

190190
}
191191

192+
/*==========================================================================================================================
193+
| TEST: LOAD TOPIC GRAPH: WITH DELETED RELATIONSHIP: REMOVES RELATIONSHIP
194+
\-------------------------------------------------------------------------------------------------------------------------*/
195+
/// <summary>
196+
/// Calls <see cref="SqlDataReaderExtensions.LoadTopicGraph(IDataReader, Topic?, Boolean?, Boolean)"/> with a deleted <see
197+
/// cref="RelationshipsDataTable"/> record and confirms that it is deleted from the <c>referenceTopic</c> graph.
198+
/// </summary>
199+
[TestMethod]
200+
public void LoadTopicGraph_WithDeletedRelationship_RemovesRelationship() {
201+
202+
var topic = TopicFactory.Create("Test", "Container", 1);
203+
var child = TopicFactory.Create("Child", "Container", 2, topic);
204+
var related = TopicFactory.Create("Related", "Container", 3, topic);
205+
206+
child.Relationships.SetTopic("Test", related);
207+
208+
using var empty = new AttributesDataTable();
209+
using var relationships = new RelationshipsDataTable();
210+
211+
relationships.AddRow(2, "Test", 3, true);
212+
213+
using var tableReader = new DataTableReader(new DataTable[] { empty, empty, empty, relationships });
214+
215+
tableReader.LoadTopicGraph(related);
216+
217+
Assert.AreEqual<int>(0, topic.Relationships.GetTopics("Test").Count);
218+
219+
}
220+
192221
} //Class
193222
} //Namespace

0 commit comments

Comments
 (0)