Skip to content

Commit 500ca09

Browse files
committed
Merge branch 'feature/CreateTopic-root' into develop
The `CreateTopic` and `MoveTopic` stored procedures now correctly handle null `@ParentID`s by placing the topic at the end of any existing root topic(s). Previously, this scenario wasn't accounted for, and it resulted in potentially corrupt hierarchy by inserting the topics overlapping with any existing root nodes. This isn't a typical scenario, and isn't recommended for most use cases, but we also want to make sure that there's no change of corrupting the hierarchy if it is attempted. While I was at it, I fixed the error handling in the `MoveTopic` stored procedure, and improved the cleanup in the SQL unit tests to compress the hierarchy once it's done, so there aren't gaps left over from deleted topics. (In normal practice, gaps shouldn't occur, but the unit tests take shortcuts to bulk delete topics instead of calling the `DeleteTopic` stored procedure for each one.)
2 parents e2c64d0 + 3e9f5c7 commit 500ca09

File tree

6 files changed

+185
-158
lines changed

6 files changed

+185
-158
lines changed

OnTopic.Data.Sql.Database.Tests/Functions.cs

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,20 @@ public void TestCleanup() {
3333
private void InitializeComponent() {
3434
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_GetExtendedAttributeTest_TestAction;
3535
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Functions));
36+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition getExtendedAttributeValue;
3637
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_GetParentIDTest_TestAction;
38+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition getParentIDValue;
3739
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_GetTopicIDTest_TestAction;
40+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition getIDTopicValue;
3841
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_GetUniqueKeyTest_TestAction;
42+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition getUniqueKeyValue;
3943
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_FindTopicIDsTest_TestAction;
4044
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition findTopicCount;
4145
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_GetAttributesTest_TestAction;
4246
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition getAttributeCount;
4347
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition getAttributeValue;
4448
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_GetChildTopicIDsTest_TestAction;
49+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition getChildTopicCount;
4550
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_GetAttributesTest_PretestAction;
4651
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition preGetAttributeCount;
4752
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_GetAttributesTest_PosttestAction;
@@ -52,13 +57,8 @@ private void InitializeComponent() {
5257
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition postFunctionTopicCount;
5358
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_FindTopicIDsTest_PretestAction;
5459
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition preFindAttributeCount;
55-
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition getChildTopicCount;
56-
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition getParentIDValue;
57-
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition getIDTopicValue;
58-
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition getUniqueKeyValue;
5960
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_GetExtendedAttributeTest_PretestAction;
6061
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition preGetExtendedAttributeCount;
61-
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition getExtendedAttributeValue;
6262
this.dbo_GetExtendedAttributeTestData = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions();
6363
this.dbo_GetParentIDTestData = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions();
6464
this.dbo_GetTopicIDTestData = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions();
@@ -67,15 +67,20 @@ private void InitializeComponent() {
6767
this.dbo_GetAttributesTestData = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions();
6868
this.dbo_GetChildTopicIDsTestData = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions();
6969
dbo_GetExtendedAttributeTest_TestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
70+
getExtendedAttributeValue = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition();
7071
dbo_GetParentIDTest_TestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
72+
getParentIDValue = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition();
7173
dbo_GetTopicIDTest_TestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
74+
getIDTopicValue = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition();
7275
dbo_GetUniqueKeyTest_TestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
76+
getUniqueKeyValue = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition();
7377
dbo_FindTopicIDsTest_TestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
7478
findTopicCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
7579
dbo_GetAttributesTest_TestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
7680
getAttributeCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
7781
getAttributeValue = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition();
7882
dbo_GetChildTopicIDsTest_TestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
83+
getChildTopicCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
7984
dbo_GetAttributesTest_PretestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
8085
preGetAttributeCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
8186
dbo_GetAttributesTest_PosttestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
@@ -86,34 +91,69 @@ private void InitializeComponent() {
8691
postFunctionTopicCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
8792
dbo_FindTopicIDsTest_PretestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
8893
preFindAttributeCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
89-
getChildTopicCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
90-
getParentIDValue = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition();
91-
getIDTopicValue = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition();
92-
getUniqueKeyValue = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition();
9394
dbo_GetExtendedAttributeTest_PretestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
9495
preGetExtendedAttributeCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
95-
getExtendedAttributeValue = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.ScalarValueCondition();
9696
//
9797
// dbo_GetExtendedAttributeTest_TestAction
9898
//
9999
dbo_GetExtendedAttributeTest_TestAction.Conditions.Add(getExtendedAttributeValue);
100100
resources.ApplyResources(dbo_GetExtendedAttributeTest_TestAction, "dbo_GetExtendedAttributeTest_TestAction");
101101
//
102+
// getExtendedAttributeValue
103+
//
104+
getExtendedAttributeValue.ColumnNumber = 1;
105+
getExtendedAttributeValue.Enabled = true;
106+
getExtendedAttributeValue.ExpectedValue = "Value2";
107+
getExtendedAttributeValue.Name = "getExtendedAttributeValue";
108+
getExtendedAttributeValue.NullExpected = false;
109+
getExtendedAttributeValue.ResultSet = 1;
110+
getExtendedAttributeValue.RowNumber = 1;
111+
//
102112
// dbo_GetParentIDTest_TestAction
103113
//
104114
dbo_GetParentIDTest_TestAction.Conditions.Add(getParentIDValue);
105115
resources.ApplyResources(dbo_GetParentIDTest_TestAction, "dbo_GetParentIDTest_TestAction");
106116
//
117+
// getParentIDValue
118+
//
119+
getParentIDValue.ColumnNumber = 1;
120+
getParentIDValue.Enabled = true;
121+
getParentIDValue.ExpectedValue = "0";
122+
getParentIDValue.Name = "getParentIDValue";
123+
getParentIDValue.NullExpected = false;
124+
getParentIDValue.ResultSet = 1;
125+
getParentIDValue.RowNumber = 1;
126+
//
107127
// dbo_GetTopicIDTest_TestAction
108128
//
109129
dbo_GetTopicIDTest_TestAction.Conditions.Add(getIDTopicValue);
110130
resources.ApplyResources(dbo_GetTopicIDTest_TestAction, "dbo_GetTopicIDTest_TestAction");
111131
//
132+
// getIDTopicValue
133+
//
134+
getIDTopicValue.ColumnNumber = 1;
135+
getIDTopicValue.Enabled = true;
136+
getIDTopicValue.ExpectedValue = "0";
137+
getIDTopicValue.Name = "getIDTopicValue";
138+
getIDTopicValue.NullExpected = false;
139+
getIDTopicValue.ResultSet = 1;
140+
getIDTopicValue.RowNumber = 1;
141+
//
112142
// dbo_GetUniqueKeyTest_TestAction
113143
//
114144
dbo_GetUniqueKeyTest_TestAction.Conditions.Add(getUniqueKeyValue);
115145
resources.ApplyResources(dbo_GetUniqueKeyTest_TestAction, "dbo_GetUniqueKeyTest_TestAction");
116146
//
147+
// getUniqueKeyValue
148+
//
149+
getUniqueKeyValue.ColumnNumber = 1;
150+
getUniqueKeyValue.Enabled = true;
151+
getUniqueKeyValue.ExpectedValue = "Root:FunctionTests:Topic_1:Topic_1_1:Topic_1_1_1:Topic_1_1_1_2";
152+
getUniqueKeyValue.Name = "getUniqueKeyValue";
153+
getUniqueKeyValue.NullExpected = false;
154+
getUniqueKeyValue.ResultSet = 1;
155+
getUniqueKeyValue.RowNumber = 1;
156+
//
117157
// dbo_FindTopicIDsTest_TestAction
118158
//
119159
dbo_FindTopicIDsTest_TestAction.Conditions.Add(findTopicCount);
@@ -154,6 +194,13 @@ private void InitializeComponent() {
154194
dbo_GetChildTopicIDsTest_TestAction.Conditions.Add(getChildTopicCount);
155195
resources.ApplyResources(dbo_GetChildTopicIDsTest_TestAction, "dbo_GetChildTopicIDsTest_TestAction");
156196
//
197+
// getChildTopicCount
198+
//
199+
getChildTopicCount.Enabled = true;
200+
getChildTopicCount.Name = "getChildTopicCount";
201+
getChildTopicCount.ResultSet = 1;
202+
getChildTopicCount.RowCount = 3;
203+
//
157204
// dbo_GetAttributesTest_PretestAction
158205
//
159206
dbo_GetAttributesTest_PretestAction.Conditions.Add(preGetAttributeCount);
@@ -214,6 +261,18 @@ private void InitializeComponent() {
214261
preFindAttributeCount.ResultSet = 1;
215262
preFindAttributeCount.RowCount = 3;
216263
//
264+
// dbo_GetExtendedAttributeTest_PretestAction
265+
//
266+
dbo_GetExtendedAttributeTest_PretestAction.Conditions.Add(preGetExtendedAttributeCount);
267+
resources.ApplyResources(dbo_GetExtendedAttributeTest_PretestAction, "dbo_GetExtendedAttributeTest_PretestAction");
268+
//
269+
// preGetExtendedAttributeCount
270+
//
271+
preGetExtendedAttributeCount.Enabled = true;
272+
preGetExtendedAttributeCount.Name = "preGetExtendedAttributeCount";
273+
preGetExtendedAttributeCount.ResultSet = 1;
274+
preGetExtendedAttributeCount.RowCount = 1;
275+
//
217276
// dbo_GetExtendedAttributeTestData
218277
//
219278
this.dbo_GetExtendedAttributeTestData.PosttestAction = null;
@@ -256,65 +315,6 @@ private void InitializeComponent() {
256315
this.dbo_GetChildTopicIDsTestData.PretestAction = null;
257316
this.dbo_GetChildTopicIDsTestData.TestAction = dbo_GetChildTopicIDsTest_TestAction;
258317
//
259-
// getChildTopicCount
260-
//
261-
getChildTopicCount.Enabled = true;
262-
getChildTopicCount.Name = "getChildTopicCount";
263-
getChildTopicCount.ResultSet = 1;
264-
getChildTopicCount.RowCount = 3;
265-
//
266-
// getParentIDValue
267-
//
268-
getParentIDValue.ColumnNumber = 1;
269-
getParentIDValue.Enabled = true;
270-
getParentIDValue.ExpectedValue = "0";
271-
getParentIDValue.Name = "getParentIDValue";
272-
getParentIDValue.NullExpected = false;
273-
getParentIDValue.ResultSet = 1;
274-
getParentIDValue.RowNumber = 1;
275-
//
276-
// getIDTopicValue
277-
//
278-
getIDTopicValue.ColumnNumber = 1;
279-
getIDTopicValue.Enabled = true;
280-
getIDTopicValue.ExpectedValue = "0";
281-
getIDTopicValue.Name = "getIDTopicValue";
282-
getIDTopicValue.NullExpected = false;
283-
getIDTopicValue.ResultSet = 1;
284-
getIDTopicValue.RowNumber = 1;
285-
//
286-
// getUniqueKeyValue
287-
//
288-
getUniqueKeyValue.ColumnNumber = 1;
289-
getUniqueKeyValue.Enabled = true;
290-
getUniqueKeyValue.ExpectedValue = "Root:FunctionTests:Topic_1:Topic_1_1:Topic_1_1_1:Topic_1_1_1_2";
291-
getUniqueKeyValue.Name = "getUniqueKeyValue";
292-
getUniqueKeyValue.NullExpected = false;
293-
getUniqueKeyValue.ResultSet = 1;
294-
getUniqueKeyValue.RowNumber = 1;
295-
//
296-
// dbo_GetExtendedAttributeTest_PretestAction
297-
//
298-
dbo_GetExtendedAttributeTest_PretestAction.Conditions.Add(preGetExtendedAttributeCount);
299-
resources.ApplyResources(dbo_GetExtendedAttributeTest_PretestAction, "dbo_GetExtendedAttributeTest_PretestAction");
300-
//
301-
// preGetExtendedAttributeCount
302-
//
303-
preGetExtendedAttributeCount.Enabled = true;
304-
preGetExtendedAttributeCount.Name = "preGetExtendedAttributeCount";
305-
preGetExtendedAttributeCount.ResultSet = 1;
306-
preGetExtendedAttributeCount.RowCount = 1;
307-
//
308-
// getExtendedAttributeValue
309-
//
310-
getExtendedAttributeValue.ColumnNumber = 1;
311-
getExtendedAttributeValue.Enabled = true;
312-
getExtendedAttributeValue.ExpectedValue = "Value2";
313-
getExtendedAttributeValue.Name = "getExtendedAttributeValue";
314-
getExtendedAttributeValue.NullExpected = false;
315-
getExtendedAttributeValue.ResultSet = 1;
316-
getExtendedAttributeValue.RowNumber = 1;
317-
//
318318
// Functions
319319
//
320320
this.TestCleanupAction = testCleanupAction;

OnTopic.Data.Sql.Database.Tests/Functions.resx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,11 @@ IF @RootTopicID IS NOT NULL
549549
EXECUTE [dbo].[DeleteTopic] @RootTopicID;
550550
END
551551

552+
--------------------------------------------------------------------------------------------------------------------------------
553+
-- COMPRESS HIERARCHY
554+
--------------------------------------------------------------------------------------------------------------------------------
555+
EXECUTE [Utilities].[CompressHierarchy]
556+
552557
--------------------------------------------------------------------------------------------------------------------------------
553558
-- VERIFY TEST DATA
554559
--------------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)