Skip to content

Commit 6c33fb8

Browse files
committed
Merge branch 'feature/LegacyTopicReferences' into develop
Refactored support for legacy topic references—what was previously known as topic pointers—so that they are migrated to `Topic.References` on `Import()`. This continues to provide support for legacy JSON data that uses topic pointers, but ensures they are treated as `Topic.References` in OnTopic 5.0.0 database; this is consistent with the OnTopic 5.0.0 database migration process, which migrated topic references from `Attributes` to `TopicReferences`. As part of this, the following breaking changes were made to the interface in order to unify the nomenclature: - Renamed the `ExportOptions.IncludeExternalReferences` to `IncludeExternalAssociations` for consistency in nomenclature (a471a7e). - Renamed the `ExportOptions.TranslateTopicPointers` to `TrnaslateLegacyTopicReferences` for consistency in nomenclature (b67e87f).
2 parents 86528eb + 487768e commit 6c33fb8

File tree

4 files changed

+128
-109
lines changed

4 files changed

+128
-109
lines changed

OnTopic.Data.Transfer.Tests/ExportOptionsTest.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void ExportWithNestedTopic_TopicWithNestedTopics_IncludesNestedTopics() {
7676
\-------------------------------------------------------------------------------------------------------------------------*/
7777
/// <summary>
7878
/// Creates a <see cref="Topic"/> with several <see cref="Topic.Relationships"/> and ensures that the <see
79-
/// cref="TopicData.Relationships"/> collection does <i>not</i> include external references—i.e., relationships that point
79+
/// cref="TopicData.Relationships"/> collection does <i>not</i> include external references—i.e., relationships that refer
8080
/// to <see cref="Topic"/>s outside of the current export scope.
8181
/// </summary>
8282
[TestMethod]
@@ -96,23 +96,24 @@ public void Export_TopicWithRelationships_ExcludesExternalReferences() {
9696
}
9797

9898
/*==========================================================================================================================
99-
| TEST: EXPORT WITH TOPIC POINTERS: EXTERNAL TOPIC POINTER: EXPORTS UNIQUE KEY
99+
| TEST: EXPORT WITH LEGACY TOPIC REFERENCES: EXTERNAL TOPIC REFERENCE: EXPORTS UNIQUE KEY
100100
\-------------------------------------------------------------------------------------------------------------------------*/
101101
/// <summary>
102-
/// Creates a <see cref="Topic"/> with an arbitrary <see cref="AttributeValue"/> that points to another topic. Confirms
103-
/// that it is converted to a <c>UniqueKey</c> if valid, and otherwise left as is.
102+
/// Creates a <see cref="Topic"/> with an arbitrary <see cref="AttributeValue"/> that references another topic. Confirms
103+
/// that it is converted to a <see cref="Topic.GetUniqueKey"/> if valid, and is otherwise left as is.
104104
/// </summary>
105105
[TestMethod]
106-
public void ExportWithTopicPointers_ExternalTopicPointer_ExportsUniqueKey() {
106+
public void ExportWithLegacyTopicReferences_ExternalTopicReference_ExportsUniqueKey() {
107107

108108
var parentTopic = TopicFactory.Create("Root", "Container", 5);
109109
var topic = TopicFactory.Create("Topic", "Container", parentTopic);
110110

111111
topic.Attributes.SetValue("SomeId", "5");
112112

113-
var topicData = topic.Export(
113+
var topicData = topic.Export(
114114
new() {
115-
IncludeExternalReferences = true
115+
IncludeExternalAssociations = true,
116+
TranslateLegacyTopicReferences = true
116117
}
117118
);
118119

OnTopic.Data.Transfer.Tests/TopicExtensionsTest.cs

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ public void Export_TopicWithRelationships_MapsRelationshipDataCollection() {
113113
}
114114

115115
/*==========================================================================================================================
116-
| TEST: EXPORT WITH EXTERNAL REFERENCES: TOPIC WITH RELATIONSHIPS: INCLUDE EXTERNAL REFERENCES
116+
| TEST: EXPORT WITH EXTERNAL ASSOCIATIONS: TOPIC WITH RELATIONSHIPS: INCLUDE EXTERNAL REFERENCES
117117
\-------------------------------------------------------------------------------------------------------------------------*/
118118
/// <summary>
119-
/// Creates a <see cref="Topic"/> with several <see cref="Topic.Relationships"/> and ensures that the <see
120-
/// cref="TopicData.Relationships"/> collection <i>does</i> include external references—i.e., relationships that point
121-
/// to <see cref="Topic"/>s outside of the current export scope—when permitted with the <see
122-
/// cref="ExportOptions.IncludeExternalReferences"/> option.
119+
/// Creates a <see cref="Topic"/> with several <see cref="Topic.Relationships"/> and ensures that the <see cref="TopicData
120+
/// .Relationships"/> collection <i>does</i> include external associations—i.e., relationships that reference <see cref="
121+
/// Topic"/>s outside of the current export scope—when permitted with the <see cref="ExportOptions.
122+
/// IncludeExternalAssociations"/> option.
123123
/// </summary>
124124
[TestMethod]
125-
public void ExportWithExternalReferences_TopicWithRelationships_ExcludesExternalReferences() {
125+
public void ExportWithExternalAssociations_TopicWithRelationships_ExcludesExternalReferences() {
126126

127127
var rootTopic = TopicFactory.Create("Root", "Container");
128128
var topic = TopicFactory.Create("Test", "Container", rootTopic);
@@ -132,7 +132,7 @@ public void ExportWithExternalReferences_TopicWithRelationships_ExcludesExternal
132132

133133
var topicData = topic.Export(
134134
new() {
135-
IncludeExternalReferences = true
135+
IncludeExternalAssociations = true
136136
}
137137
);
138138

@@ -184,19 +184,21 @@ public void Export_ExcludesReservedAttributes() {
184184

185185
var topicData = topic.Export();
186186

187-
Assert.AreEqual<int>(0, topicData.Attributes.Count);
187+
Assert.AreEqual<int>(1, topicData.Attributes.Count);
188+
Assert.AreEqual<string>("8", topicData.Attributes.FirstOrDefault().Value);
188189

189190
}
190191

191192
/*==========================================================================================================================
192-
| TEST: EXPORT WITH TOPIC POINTERS: OUT OF SCOPE: SKIPS ATTRIBUTE
193+
| TEST: EXPORT WITH LEGACY TOPIC REFERENCES: OUT OF SCOPE: SKIPS REFERENCE
193194
\-------------------------------------------------------------------------------------------------------------------------*/
194195
/// <summary>
195-
/// Creates a <see cref="Topic"/> with an arbitrary <see cref="AttributeValue"/> that points to a topic outside of the
196-
/// <see cref="ExportOptions.ExportScope"/>. Confirms that it is ignored.
196+
/// Creates a <see cref="Topic"/> with an arbitrary <see cref="AttributeValue"/> that references a <see cref="Topic.Id"/>
197+
/// outside of the <see cref="ExportOptions.ExportScope"/>. Confirms that the reference is maintained as an attribute, but
198+
/// not added as a reference.
197199
/// </summary>
198200
[TestMethod]
199-
public void ExportWithTopicPointers_OutOfScope_SkipsAttribute() {
201+
public void ExportWithLegacyTopicReferences_OutOfScope_SkipsReference() {
200202

201203
var parentTopic = TopicFactory.Create("Root", "Container", 5);
202204
var topic = TopicFactory.Create("Topic", "Container", parentTopic);
@@ -206,20 +208,22 @@ public void ExportWithTopicPointers_OutOfScope_SkipsAttribute() {
206208
var topicData = topic.Export();
207209

208210
topicData.Attributes.TryGetValue("SomeId", out var someAttribute);
211+
topicData.References.TryGetValue("Some", out var someReference);
209212

210-
Assert.IsNull(someAttribute);
213+
Assert.IsNotNull(someAttribute);
214+
Assert.IsNull(someReference);
211215

212216
}
213217

214218
/*==========================================================================================================================
215-
| TEST: EXPORT WITH TOPIC POINTERS: MISSING TOPIC POINTER: SKIPS ATTRIBUTE
219+
| TEST: EXPORT WITH LEGACY TOPIC REFERENCES: MISSING TOPIC REFERENCE: SKIPS REFERENCE
216220
\-------------------------------------------------------------------------------------------------------------------------*/
217221
/// <summary>
218-
/// Creates a <see cref="Topic"/> with an arbitrary <see cref="AttributeValue"/> that points to a missing <see
219-
/// cref="Topic.Id"/>. Confirms that the attribute is skipped.
222+
/// Creates a <see cref="Topic"/> with an arbitrary <see cref="AttributeValue"/> that references a missing <see cref="
223+
/// Topic.Id"/>. Confirms that the reference is maintained as an attribute, but not added as a reference.
220224
/// </summary>
221225
[TestMethod]
222-
public void ExportWithTopicPointers_MissingTopicPointer_SkipsAttribute() {
226+
public void ExportWithLegacyTopicReferences_MissingTopicReference_SkipsReference() {
223227

224228
var topic = TopicFactory.Create("Topic", "Container");
225229

@@ -228,20 +232,24 @@ public void ExportWithTopicPointers_MissingTopicPointer_SkipsAttribute() {
228232
var topicData = topic.Export();
229233

230234
topicData.Attributes.TryGetValue("InitialBid", out var initialBidAttribute);
235+
topicData.References.TryGetValue("InitialB", out var initialBReference);
236+
topicData.References.TryGetValue("InitialB", out var initialBidReference);
231237

232-
Assert.IsNull(initialBidAttribute);
238+
Assert.IsNotNull(initialBidAttribute);
239+
Assert.IsNull(initialBReference);
240+
Assert.IsNull(initialBidReference);
233241

234242
}
235243

236244
/*==========================================================================================================================
237-
| TEST: EXPORT WITH TOPIC POINTERS: INVALID TOPIC POINTER: EXPORTS ORIGINAL VALUE
245+
| TEST: EXPORT WITH LEGACY TOPIC REFERENCES: INVALID TOPIC REFERENCE: EXPORTS ORIGINAL VALUE
238246
\-------------------------------------------------------------------------------------------------------------------------*/
239247
/// <summary>
240248
/// Creates a <see cref="Topic"/> with an arbitrary <see cref="AttributeValue"/> that that contains a non-numeric (i.e.,
241-
/// invalid) topic pointers. Confirms that the original value is exported.
249+
/// invalid) topic reference. Confirms that the original value is exported.
242250
/// </summary>
243251
[TestMethod]
244-
public void ExportWithTopicPointers_InvalidTopicPointer_ExportsOriginalValue() {
252+
public void ExportWithLegacyTopicReferences_InvalidTopicReference_ExportsOriginalValue() {
245253

246254
var topic = TopicFactory.Create("Topic", "Container");
247255

@@ -337,7 +345,7 @@ public void Import_DerivedTopicKey_MapsDerivedTopic() {
337345
\-------------------------------------------------------------------------------------------------------------------------*/
338346
/// <summary>
339347
/// Creates a <see cref="TopicData"/> with a <see cref="AttributeData"/> with the <see cref="AttributeData.Key"/> of <c>
340-
/// BaseTopic</c> in the <see cref="TopicData.References"/> collection, which points to a topic in the topic graph.
348+
/// BaseTopic</c> in the <see cref="TopicData.References"/> collection, which references a topic in the topic graph.
341349
/// Ensures that it is correctly wired up.
342350
/// </summary>
343351
[TestMethod]
@@ -372,8 +380,8 @@ public void Import_BaseTopic_MapsBaseTopic() {
372380
\-------------------------------------------------------------------------------------------------------------------------*/
373381
/// <summary>
374382
/// Creates a <see cref="TopicData"/> with a <see cref="AttributeData"/> with the <see cref="AttributeData.Key"/> of <c>
375-
/// BaseTopic</c> in the <see cref="TopicData.References"/> collection, which points to a newly imported topic that occurs
376-
/// later in the tree, ensuring that the <see cref="Topic.BaseTopic"/> is set correctly.
383+
/// BaseTopic</c> in the <see cref="TopicData.References"/> collection, which references a newly imported topic that
384+
/// occurs later in the tree, ensuring that the <see cref="Topic.BaseTopic"/> is set correctly.
377385
/// </summary>
378386
[TestMethod]
379387
public void Import_BaseTopic_MapsNewBaseTopic() {
@@ -717,14 +725,14 @@ public void Import_TopicDataWithChild_SkipsOrphanedChild() {
717725
}
718726

719727
/*==========================================================================================================================
720-
| TEST: IMPORT: TOPIC DATA WITH TOPIC POINTER: MAPS TOPIC ID
728+
| TEST: IMPORT: TOPIC DATA WITH LEGACY TOPIC REFERENCE: MAPS TOPIC ID
721729
\-------------------------------------------------------------------------------------------------------------------------*/
722730
/// <summary>
723-
/// Creates a <see cref="TopicData"/> with an arbitrary <see cref="AttributeData"/> that points to another topic. Confirms
724-
/// that it is converted to a <c>TopicID</c> if valid, and otherwise left as is.
731+
/// Creates a <see cref="TopicData"/> with an arbitrary <see cref="AttributeData"/> that references another topic.
732+
/// Confirms that it is converted to a <see cref="Topic.Id"/> if valid, and otherwise left as is.
725733
/// </summary>
726734
[TestMethod]
727-
public void Import_TopicDataWithTopicPointer_MapsTopicID() {
735+
public void Import_TopicDataWithLegacyTopicReference_MapsTopicID() {
728736

729737
var rootTopic = TopicFactory.Create("Root", "Container");
730738
var topic = TopicFactory.Create("Topic", "Container", rootTopic);
@@ -745,19 +753,19 @@ public void Import_TopicDataWithTopicPointer_MapsTopicID() {
745753

746754
topic.Import(topicData);
747755

748-
Assert.AreEqual<string>("5", topic.Attributes.GetValue("SomeId"));
756+
Assert.AreEqual<int>(5, topic.References.GetValue("Some")?.Id?? -1);
749757

750758
}
751759

752760
/*==========================================================================================================================
753-
| TEST: IMPORT: TOPIC DATA WITH MISSING TOPIC POINTER: SKIPS ATTRIBUTE
761+
| TEST: IMPORT: TOPIC DATA WITH MISSING LEGACY TOPIC REFERENCE: SKIPS ATTRIBUTE
754762
\-------------------------------------------------------------------------------------------------------------------------*/
755763
/// <summary>
756-
/// Creates a <see cref="TopicData"/> with an arbitrary <see cref="AttributeData"/> that points to a missing topic.
764+
/// Creates a <see cref="TopicData"/> with an arbitrary <see cref="AttributeData"/> that references to a missing topic.
757765
/// Confirms that the attribute is skipped.
758766
/// </summary>
759767
[TestMethod]
760-
public void Import_TopicDataWithMissingTopicPointer_SkipsAttribute() {
768+
public void Import_TopicDataWithMissingLegacyTopicReference_SkipsAttribute() {
761769

762770
var topic = TopicFactory.Create("Topic", "Container");
763771

@@ -770,7 +778,7 @@ public void Import_TopicDataWithMissingTopicPointer_SkipsAttribute() {
770778
topicData.Attributes.Add(
771779
new() {
772780
Key = "SomeId",
773-
Value = "Root:Missing:Topic:Pointer"
781+
Value = "Root:Missing:Legacy:Topic:Reference"
774782
}
775783
);
776784

@@ -781,14 +789,14 @@ public void Import_TopicDataWithMissingTopicPointer_SkipsAttribute() {
781789
}
782790

783791
/*==========================================================================================================================
784-
| TEST: IMPORT: TOPIC DATA WITH INVALID TOPIC POINTER: IMPORTS ORIGINAL VALUE
792+
| TEST: IMPORT: TOPIC DATA WITH INVALID LEGACY TOPIC REFERENCE: IMPORTS ORIGINAL VALUE
785793
\-------------------------------------------------------------------------------------------------------------------------*/
786794
/// <summary>
787795
/// Creates a <see cref="TopicData"/> with an arbitrary <see cref="AttributeData"/> that does not reference a topic key
788796
/// (i.e., it doesn't start with <c>Root</c>). Confirms that the original attribute value is imported.
789797
/// </summary>
790798
[TestMethod]
791-
public void Import_TopicDataWithInvalidTopicPointer_ImportsOriginalValue() {
799+
public void Import_TopicDataWithInvalidLegacyTopicReference_ImportsOriginalValue() {
792800

793801
var topic = TopicFactory.Create("Topic", "Container");
794802

@@ -811,6 +819,5 @@ public void Import_TopicDataWithInvalidTopicPointer_ImportsOriginalValue() {
811819

812820
}
813821

814-
815822
} //Class
816823
} //Namespace

0 commit comments

Comments
 (0)