Skip to content

Commit a48c3e7

Browse files
committed
Introduced test to validate deleting existing attribute
If a previous attribute is deleted, the database is expected to return a `null` value for that record. If the topic already exists in the `referenceTopic` with a valid attribute for that `attributeKey`, then that attribute should then be deleted. This test confirms that is true. (In fact, this test fails—but that's due to identifying an underlying bug. That bug will be fixed in a subsequent commit.)
1 parent ea96e8c commit a48c3e7

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
@@ -75,6 +75,35 @@ public void LoadTopicGraph_WithAttributes_ReturnsAttributes() {
7575

7676
}
7777

78+
/*==========================================================================================================================
79+
| TEST: LOAD TOPIC GRAPH: WITH NULL ATTRIBUTES: REMOVES ATTRIBUTE
80+
\-------------------------------------------------------------------------------------------------------------------------*/
81+
/// <summary>
82+
/// Calls <see cref="SqlDataReaderExtensions.LoadTopicGraph(IDataReader, Topic?, Boolean?, Boolean)"/> with an <see cref="
83+
/// AttributesDataTable"/> record representing a deleted attribute and confirms that an existing reference topic with that
84+
/// attribute has the value removed.
85+
/// </summary>
86+
[TestMethod]
87+
public void LoadTopicGraph_WithNullAttributes_RemovesAttribute() {
88+
89+
using var topics = new TopicsDataTable();
90+
using var attributes = new AttributesDataTable();
91+
92+
var topic = TopicFactory.Create("Root", "Container", 1);
93+
94+
topic.Attributes.SetValue("Test", "Initial Value");
95+
96+
topics.AddRow(1, "Root", "Container");
97+
attributes.AddRow(1, "Test", null);
98+
99+
using var tableReader = new DataTableReader(new DataTable[] { topics, attributes });
100+
101+
tableReader.LoadTopicGraph(topic);
102+
103+
Assert.IsNull(topic.Attributes.GetValue("Test"));
104+
105+
}
106+
78107
/*==========================================================================================================================
79108
| TEST: LOAD TOPIC GRAPH: WITH RELATIONSHIP: RETURNS RELATIONSHIP
80109
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)