Skip to content

Commit a5df9b1

Browse files
committed
Merge branch 'feature/RecordDataCollection' into develop
With the introduction of `TopicData.References`, the `AttributeData` and `AttributeDataCollection` now support both `TopicData.Attributes` as well as `TopicData.References`. This maps to the implementation in the OnTopic Library, where `Topic.Attributes` and `Topic.References` both derive from a `TrackedRecordCollection<>`, which is a collection of `TrackedRecord<>` objects. Given this, the name `AttributeData` and `AttributeDataCollection` is confusing. To remedy this, while maintaining (some level of) consistency with the OnTopic Library implementation, these have been renamed to `RecordData` and `RecordDataCollection`, respectively. (The data interchange format isn't "tracked", but it does combine data and metadata, and thus "record" continues to make sense.) As part of this, I updated unit test names and variables previously associated with the `AttributeData` class.
2 parents 1fca90a + 85c234a commit a5df9b1

File tree

9 files changed

+61
-60
lines changed

9 files changed

+61
-60
lines changed

OnTopic.Data.Transfer.Tests/DeserializationTest.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ public void Deserialize_RelationshipData_ReturnsExpectedResults() {
123123
}
124124

125125
/*==========================================================================================================================
126-
| TEST: DESERIALIZE: ATTRIBUTE DATA: RETURNS EXPECTED RESULTS
126+
| TEST: DESERIALIZE: RECORD DATA: RETURNS EXPECTED RESULTS
127127
\-------------------------------------------------------------------------------------------------------------------------*/
128128
/// <summary>
129-
/// Creates a json string and attempts to deserialize it as a <see cref="AttributeData"/> class.
129+
/// Creates a json string and attempts to deserialize it as a <see cref="RecordData"/> class.
130130
/// </summary>
131131
[TestMethod]
132-
public void Deserialize_AttributeData_ReturnsExpectedResults() {
132+
public void Deserialize_RecordData_ReturnsExpectedResults() {
133133

134-
var sourceData = new AttributeData() {
134+
var sourceData = new RecordData() {
135135
Key = "Test",
136136
LastModified = DateTime.Now
137137
};
@@ -143,11 +143,11 @@ public void Deserialize_AttributeData_ReturnsExpectedResults() {
143143
$"}}";
144144

145145

146-
var attributeData = JsonSerializer.Deserialize<AttributeData>(json);
146+
var recordData = JsonSerializer.Deserialize<RecordData>(json);
147147

148-
Assert.AreEqual<string>(sourceData.Key, attributeData.Key);
149-
Assert.AreEqual<string>(sourceData.Value, attributeData.Value);
150-
Assert.AreEqual<DateTime>(sourceData.LastModified, attributeData.LastModified);
148+
Assert.AreEqual<string>(sourceData.Key, recordData.Key);
149+
Assert.AreEqual<string>(sourceData.Value, recordData.Value);
150+
Assert.AreEqual<DateTime>(sourceData.LastModified, recordData.LastModified);
151151

152152
}
153153

@@ -168,11 +168,11 @@ public void Deserialize_TopicGraph_ReturnsExpectedResults() {
168168
var sourceRelationshipData= new RelationshipData() {
169169
Key = "Test"
170170
};
171-
var sourceAttributeData = new AttributeData() {
171+
var sourceAttributeData = new RecordData() {
172172
Key = "Test",
173173
LastModified = DateTime.Now
174174
};
175-
var sourceReferenceData = new AttributeData() {
175+
var sourceReferenceData = new RecordData() {
176176
Key = "Test",
177177
Value = "Root:Reference",
178178
LastModified = DateTime.Now

OnTopic.Data.Transfer.Tests/SerializationTest.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,26 @@ public void Serialize_RelationshipData_ReturnsExpectedResults() {
7575
}
7676

7777
/*==========================================================================================================================
78-
| TEST: SERIALIZE: ATTRIBUTE DATA: RETURNS EXPECTED RESULTS
78+
| TEST: SERIALIZE: RECORD DATA: RETURNS EXPECTED RESULTS
7979
\-------------------------------------------------------------------------------------------------------------------------*/
8080
/// <summary>
81-
/// Creates a <see cref="AttributeData"/>, serializes it, and confirms the resulting JSON.
81+
/// Creates a <see cref="RecordData"/>, serializes it, and confirms the resulting JSON.
8282
/// </summary>
8383
[TestMethod]
84-
public void Serialize_AttributeData_ReturnsExpectedResults() {
84+
public void Serialize_RecordData_ReturnsExpectedResults() {
8585

86-
var attributeData = new AttributeData() {
86+
var recordData = new RecordData() {
8787
Key = "Test",
8888
LastModified = DateTime.Now
8989
};
9090

9191
var expected = $"{{" +
92-
$"\"Key\":\"{attributeData.Key}\"," +
92+
$"\"Key\":\"{recordData.Key}\"," +
9393
$"\"Value\":null," +
94-
$"\"LastModified\":\"{attributeData.LastModified:o}\"" +
94+
$"\"LastModified\":\"{recordData.LastModified:o}\"" +
9595
$"}}";
9696

97-
var json = JsonSerializer.Serialize(attributeData);
97+
var json = JsonSerializer.Serialize(recordData);
9898

9999
Assert.AreEqual<string>(expected, json);
100100

@@ -117,11 +117,11 @@ public void Serialize_TopicGraph_ReturnsExpectedResults() {
117117
var relationshipData = new RelationshipData() {
118118
Key = "Test"
119119
};
120-
var referenceData = new AttributeData() {
120+
var referenceData = new RecordData() {
121121
Key = "Test",
122122
LastModified = DateTime.Now
123123
};
124-
var attributeData = new AttributeData() {
124+
var attributeData = new RecordData() {
125125
Key = "Test",
126126
LastModified = DateTime.Now
127127
};

OnTopic.Data.Transfer.Tests/TopicExtensionsTest.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public void Export_BasicTopic_MapsProperties() {
4141
| TEST: EXPORT: BASE TOPIC: MAPS REFERENCE DATA
4242
\-------------------------------------------------------------------------------------------------------------------------*/
4343
/// <summary>
44-
/// Creates a <see cref="Topic"/> with a <see cref="Topic.BaseTopic"/> and ensures that a <see cref="AttributeData"/>
45-
/// item with a <see cref="AttributeData.Key"/> of <c>BasedTopic</c> is correctly set.
44+
/// Creates a <see cref="Topic"/> with a <see cref="Topic.BaseTopic"/> and ensures that a <see cref="RecordData"/> item
45+
/// with a <see cref="RecordData.Key"/> of <c>BasedTopic</c> is correctly set.
4646
/// </summary>
4747
[TestMethod]
4848
public void Export_BaseTopic_MapsReferenceData() {
@@ -375,7 +375,7 @@ public void Import_DerivedTopicKey_MapsDerivedTopic() {
375375
| TEST: IMPORT: BASE TOPIC: MAPS BASE TOPIC
376376
\-------------------------------------------------------------------------------------------------------------------------*/
377377
/// <summary>
378-
/// Creates a <see cref="TopicData"/> with a <see cref="AttributeData"/> with the <see cref="AttributeData.Key"/> of <c>
378+
/// Creates a <see cref="TopicData"/> with a <see cref="RecordData"/> with the <see cref="RecordData.Key"/> of <c>
379379
/// BaseTopic</c> in the <see cref="TopicData.References"/> collection, which references a topic in the topic graph.
380380
/// Ensures that it is correctly wired up.
381381
/// </summary>
@@ -392,7 +392,7 @@ public void Import_BaseTopic_MapsBaseTopic() {
392392
ContentType = topic.ContentType
393393
};
394394

395-
var referencedTopicData = new AttributeData() {
395+
var referencedTopicData = new RecordData() {
396396
Key = "BaseTopic",
397397
Value = $"{baseTopic.GetUniqueKey()}"
398398
};
@@ -410,7 +410,7 @@ public void Import_BaseTopic_MapsBaseTopic() {
410410
| TEST: IMPORT: BASE TOPIC: MAPS NEW BASE TOPIC
411411
\-------------------------------------------------------------------------------------------------------------------------*/
412412
/// <summary>
413-
/// Creates a <see cref="TopicData"/> with a <see cref="AttributeData"/> with the <see cref="AttributeData.Key"/> of <c>
413+
/// Creates a <see cref="TopicData"/> with a <see cref="RecordData"/> with the <see cref="RecordData.Key"/> of <c>
414414
/// BaseTopic</c> in the <see cref="TopicData.References"/> collection, which references a newly imported topic that
415415
/// occurs later in the tree, ensuring that the <see cref="Topic.BaseTopic"/> is set correctly.
416416
/// </summary>
@@ -438,7 +438,7 @@ public void Import_BaseTopic_MapsNewBaseTopic() {
438438
ContentType = "Container"
439439
};
440440

441-
var baseTopicReference = new AttributeData() {
441+
var baseTopicReference = new RecordData() {
442442
Key = "BaseTopic",
443443
Value = $"{topicData.UniqueKey}:BaseTopic"
444444
};
@@ -478,7 +478,7 @@ public void Import_InvalidBaseTopic_MaintainsExistingValue() {
478478
ContentType = topic.ContentType
479479
};
480480

481-
var baseTopicReference = new AttributeData() {
481+
var baseTopicReference = new RecordData() {
482482
Key = "BaseTopic",
483483
Value = $"{topicData.UniqueKey}:BaseTopic"
484484
};
@@ -672,12 +672,12 @@ public void Import_TopicDataWithReferences_MapsReferenceCollection() {
672672
UniqueKey = topic.GetUniqueKey(),
673673
ContentType = topic.ContentType
674674
};
675-
var referenData = new AttributeData() {
675+
var referenceData = new RecordData() {
676676
Key = "Referenced",
677677
Value = referencedTopic.GetUniqueKey()
678678
};
679679

680-
topicData.References.Add(referenData);
680+
topicData.References.Add(referenceData);
681681

682682
topic.Import(topicData);
683683

@@ -704,7 +704,7 @@ public void Import_TopicDataWithReferences_MaintainsExisting() {
704704
UniqueKey = topic.GetUniqueKey(),
705705
ContentType = topic.ContentType
706706
};
707-
var referenceData = new AttributeData() {
707+
var referenceData = new RecordData() {
708708
Key = "Referenced",
709709
Value = referencedTopic2.GetUniqueKey()
710710
};
@@ -824,8 +824,8 @@ public void Import_TopicDataWithChild_SkipsOrphanedChild() {
824824
| TEST: IMPORT: TOPIC DATA WITH LEGACY TOPIC REFERENCE: MAPS TOPIC ID
825825
\-------------------------------------------------------------------------------------------------------------------------*/
826826
/// <summary>
827-
/// Creates a <see cref="TopicData"/> with an arbitrary <see cref="AttributeData"/> that references another topic.
828-
/// Confirms that it is converted to a <see cref="Topic.Id"/> if valid, and otherwise left as is.
827+
/// Creates a <see cref="TopicData"/> with an arbitrary <see cref="RecordData"/> that references another topic. Confirms
828+
/// that it is converted to a <see cref="Topic.Id"/> if valid, and otherwise left as is.
829829
/// </summary>
830830
[TestMethod]
831831
public void Import_TopicDataWithLegacyTopicReference_MapsTopicID() {
@@ -857,7 +857,7 @@ public void Import_TopicDataWithLegacyTopicReference_MapsTopicID() {
857857
| TEST: IMPORT: TOPIC DATA WITH MISSING LEGACY TOPIC REFERENCE: SKIPS ATTRIBUTE
858858
\-------------------------------------------------------------------------------------------------------------------------*/
859859
/// <summary>
860-
/// Creates a <see cref="TopicData"/> with an arbitrary <see cref="AttributeData"/> that references to a missing topic.
860+
/// Creates a <see cref="TopicData"/> with an arbitrary <see cref="RecordData"/> that references to a missing topic.
861861
/// Confirms that the attribute is skipped.
862862
/// </summary>
863863
[TestMethod]
@@ -888,7 +888,7 @@ public void Import_TopicDataWithMissingLegacyTopicReference_SkipsAttribute() {
888888
| TEST: IMPORT: TOPIC DATA WITH INVALID LEGACY TOPIC REFERENCE: IMPORTS ORIGINAL VALUE
889889
\-------------------------------------------------------------------------------------------------------------------------*/
890890
/// <summary>
891-
/// Creates a <see cref="TopicData"/> with an arbitrary <see cref="AttributeData"/> that does not reference a topic key
891+
/// Creates a <see cref="TopicData"/> with an arbitrary <see cref="RecordData"/> that does not reference a topic key
892892
/// (i.e., it doesn't start with <c>Root</c>). Confirms that the original attribute value is imported.
893893
/// </summary>
894894
[TestMethod]

OnTopic.Data.Transfer/Interchange/ImportStrategy.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public enum ImportStrategy {
4444
| MERGE
4545
\-------------------------------------------------------------------------------------------------------------------------*/
4646
/// <summary>
47-
/// Imports all records <i>unless</i> the <see cref="AttributeData.LastModified"/> is <i>older</i> than the target <see
48-
/// cref="AttributeValue.LastModified"/>.
47+
/// Imports all records <i>unless</i> the <see cref="RecordData.LastModified"/> is <i>older</i> than the target <see cref=
48+
/// "AttributeValue.LastModified"/>.
4949
/// </summary>
5050
/// <remarks>
5151
/// This is generally the <i>preferred</i> import strategy. It imports all new topics, relationships, and attributes,
@@ -63,12 +63,12 @@ public enum ImportStrategy {
6363
| OVERWRITE
6464
\-------------------------------------------------------------------------------------------------------------------------*/
6565
/// <summary>
66-
/// Imports all records, <i>even if</i> the <see cref="AttributeData.LastModified"/> is <i>older</i> than the target <see
66+
/// Imports all records, <i>even if</i> the <see cref="RecordData.LastModified"/> is <i>older</i> than the target <see
6767
/// cref="AttributeValue.LastModified"/>.
6868
/// </summary>
6969
/// <remarks>
7070
/// This will effectively <i>overwrite</i> any attributes that already exist in the database, even if they were
71-
/// modified <i>after</i> the source <see cref="AttributeData"/>. For example, if the <see cref="TopicData"/> starts at
71+
/// modified <i>after</i> the source <see cref="RecordData"/>. For example, if the <see cref="TopicData"/> starts at
7272
/// <code>Root:Configuration</code>, any modifications to out-of-the-box titles, descriptions, visibility, sort order, &c.
7373
/// will be overwritten with the new values. Any attribute values that it overwrites will still be recoverable as part of
7474
/// the attribute versioning schema, with the exception of <see cref="Topic.ContentType"/>, which is excluded from

OnTopic.Data.Transfer/Interchange/LastModifiedImportStrategy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public enum LastModifiedImportStrategy {
3939
/// <remarks>
4040
/// When <see cref="Inherit"/> is chosen, existing values will be retained if <see cref="ImportStrategy.Add"/> is
4141
/// selected, overwritten if <see cref="ImportStrategy.Overwrite"/> or <see cref="ImportStrategy.Replace"/> are selected,
42-
/// and conditionally overwritten based on the <see cref="AttributeData.LastModified"/> date if <see
43-
/// cref="ImportStrategy.Merge"/> is selected.
42+
/// and conditionally overwritten based on the <see cref="RecordData.LastModified"/> date if <see cref="ImportStrategy.
43+
/// Merge"/> is selected.
4444
/// </remarks>
4545
Inherit = 1,
4646

OnTopic.Data.Transfer/Interchange/TopicExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ topic.ContentType is not "List" && options.DeleteUnmatchedChildren
463463
/*------------------------------------------------------------------------------------------------------------------------
464464
| Is custom merge rules?
465465
\-----------------------------------------------------------------------------------------------------------------------*/
466-
bool useCustomMergeRules(AttributeData attribute) =>
466+
bool useCustomMergeRules(RecordData attribute) =>
467467
(attribute.Key is "LastModified" && options!.LastModifiedStrategy is not LastModifiedImportStrategy.Inherit) ||
468468
(attribute.Key is "LastModifiedBy" && options!.LastModifiedByStrategy is not LastModifiedImportStrategy.Inherit);
469469

OnTopic.Data.Transfer/AttributeData.cs renamed to OnTopic.Data.Transfer/RecordData.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,29 @@
55
\=============================================================================================================================*/
66
using System;
77
using System.Diagnostics.CodeAnalysis;
8+
using OnTopic.Collections.Specialized;
89

910
namespace OnTopic.Data.Transfer {
1011

1112
/*============================================================================================================================
12-
| CLASS: ATTRIBUTE DATA
13+
| CLASS: RECORD DATA
1314
\---------------------------------------------------------------------------------------------------------------------------*/
1415
/// <summary>
15-
/// The <see cref="AttributeData"/> class provides an intermediary data transfer object for facilitating the interchange of
16-
/// <see cref="AttributeValue"/> objects with JSON data.
16+
/// The <see cref="RecordData"/> class provides an intermediary data transfer object for facilitating the interchange of
17+
/// <see cref="TrackedRecord{T}"/> objects with JSON data.
1718
/// </summary>
1819
/// <remarks>
1920
/// Having a separate class for this serializing topic data introduces some overhead in converting the topic graph to and
2021
/// from <see cref="TopicData"/> objects, but in turn greatly simplifies how the serialization process works, and provides
2122
/// necessary flexibility in the import process to better account for merging data and handling potential conflicts.
2223
/// </remarks>
23-
public class AttributeData {
24+
public class RecordData {
2425

2526
/*==========================================================================================================================
2627
| KEY
2728
\-------------------------------------------------------------------------------------------------------------------------*/
2829
/// <summary>
29-
/// Gets or sets the key of the attribute.
30+
/// Gets or sets the <see cref="Key"/> of the <see cref="RecordData"/>.
3031
/// </summary>
3132
[NotNull, DisallowNull]
3233
public string? Key { get; set; }
@@ -35,15 +36,15 @@ public class AttributeData {
3536
| PROPERTY: VALUE
3637
\-------------------------------------------------------------------------------------------------------------------------*/
3738
/// <summary>
38-
/// Gets the current value of the attribute.
39+
/// Gets or sets the <see cref="Value"/> of the <see cref="RecordData"/>.
3940
/// </summary>
4041
public string? Value { get; set; }
4142

4243
/*==========================================================================================================================
4344
| PROPERTY: LAST MODIFIED
4445
\-------------------------------------------------------------------------------------------------------------------------*/
4546
/// <summary>
46-
/// Gets or sets the the last time the <see cref="AttributeData"/> instance was updated.
47+
/// Gets or sets the the last time the <see cref="RecordData"/> instance was updated.
4748
/// </summary>
4849
public DateTime LastModified { get; set; } = DateTime.MinValue;
4950

OnTopic.Data.Transfer/AttributeDataCollection.cs renamed to OnTopic.Data.Transfer/RecordDataCollection.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@
99
namespace OnTopic.Data.Transfer {
1010

1111
/*============================================================================================================================
12-
| CLASS: ATTRIBUTE DATA COLLECTION
12+
| CLASS: RECORD DATA COLLECTION
1313
\---------------------------------------------------------------------------------------------------------------------------*/
1414
/// <summary>
15-
/// The <see cref="AttributeDataCollection"/> class provides a <see cref="KeyedCollection"/> of <see cref="AttributeData"/>
15+
/// The <see cref="RecordDataCollection"/> class provides a <see cref="KeyedCollection"/> of <see cref="RecordData"/>
1616
/// objects.
1717
/// </summary>
18-
public class AttributeDataCollection: KeyedCollection<string, AttributeData> {
18+
public class RecordDataCollection: KeyedCollection<string, RecordData> {
1919

2020
/*==========================================================================================================================
2121
| OVERRIDE: GET KEY FOR ITEM
2222
\-------------------------------------------------------------------------------------------------------------------------*/
2323
/// <summary>
24-
/// Method must be overridden for the <see cref="AttributeDataCollection"/> to identify the appropriate <see cref="Key"/>
25-
/// from each <see cref="AttributeData"/> object.
24+
/// Method must be overridden for the <see cref="RecordDataCollection"/> to identify the appropriate <see cref="Key"/>
25+
/// from each <see cref="RecordData"/> object.
2626
/// </summary>
27-
/// <param name="item">The <see cref="AttributeData"/> object from which to extract the key.</param>
27+
/// <param name="item">The <see cref="RecordData"/> object from which to extract the key.</param>
2828
/// <returns>The key for the specified collection item.</returns>
29-
protected override string GetKeyForItem(AttributeData item) {
29+
protected override string GetKeyForItem(RecordData item) {
3030
Contract.Requires(item, "The item must be available in order to derive its key.");
3131
return item.Key?? "";
3232
}

0 commit comments

Comments
 (0)