Skip to content

Commit 0d9dcd5

Browse files
committed
Updated references to the Topic.Relationships class to new interface
The change from `RelatedTopicCollection` (which was a `KeyedCollection<string, NamedTopicCollection>`) to `TopicRelationshipMultiMap` (which is now an `IEnumerable<KeyValuesPair<string, ReadOnlyCollection<Topic>>>`) is broadly consistent in terms of primary entry points, but does change the interface some when dealing with iterators. This update resolves those breaking changes by e.g., changing the relationship `Name` key to `Key`, accessing the values from the new `Values` property, and working with `Topic` instead of `Topic.Key` (to account for the fact that it now allows duplicate key names). These are breaking changes that may need to be applied in implementors as well—though, the hope, is that most implementors will be relying on the higher-level interfaces and, thus, not be affected by this.
1 parent 8d610e3 commit 0d9dcd5

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

OnTopic.AspNetCore.Mvc/Controllers/SitemapController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ where topic.Attributes.GetValue(attribute.Key)?.Length < 256
236236
IEnumerable<XElement> getRelationships() =>
237237
from relationship in topic.Relationships
238238
select new XElement(_pagemapNamespace + "DataObject",
239-
new XAttribute("type", relationship.Name),
240-
from relatedTopic in topic.Relationships[relationship.Name]
239+
new XAttribute("type", relationship.Key),
240+
from relatedTopic in relationship.Values
241241
select new XElement(_pagemapNamespace + "Attribute",
242242
new XAttribute("name", "TopicKey"),
243243
new XText(relatedTopic.GetUniqueKey().Replace("Root:", "", StringComparison.InvariantCultureIgnoreCase))

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ SqlDateTime version
418418
\-----------------------------------------------------------------------------------------------------------------------*/
419419
if (
420420
isRecursive &&
421-
( topic.Relationships.Any(r => r.Any(t => t.Id < 0)) ||
421+
( topic.Relationships.Any(r => r.Values.Any(t => t.Id < 0)) ||
422422
topic.References.Values.Any(t => t.Id < 0)
423423
)
424424
) {
@@ -654,7 +654,7 @@ private static void PersistRelations(Topic topic, SqlConnection connection) {
654654

655655
//Reset isDirty, assuming there aren't any unresolved references
656656
if (savedTopics.Count() == relatedTopics.Count) {
657-
relatedTopics.MarkClean();
657+
topic.Relationships.MarkClean(key);
658658
}
659659

660660
}

OnTopic.Tests/RelatedTopicCollectionTest.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Linq;
88
using Microsoft.VisualStudio.TestTools.UnitTesting;
9+
using OnTopic.Collections;
910
using OnTopic.References;
1011

1112
namespace OnTopic.Tests {
@@ -68,7 +69,7 @@ public void RemoveTopic_RemovesRelationship() {
6869
var related = TopicFactory.Create("Related", "Page");
6970

7071
parent.Relationships.SetTopic("Friends", related);
71-
parent.Relationships.RemoveTopic("Friends", related.Key);
72+
parent.Relationships.RemoveTopic("Friends", related);
7273

7374
Assert.IsNull(parent.Relationships.GetTopics("Friends").FirstOrDefault());
7475

@@ -89,7 +90,7 @@ public void RemoveTopic_RemovesIncomingRelationship() {
8990
var relationships = new RelatedTopicCollection(parent);
9091

9192
relationships.SetTopic("Friends", related);
92-
relationships.RemoveTopic("Friends", related.Key);
93+
relationships.RemoveTopic("Friends", related);
9394

9495
Assert.IsNull(related.IncomingRelationships.GetTopics("Friends").FirstOrDefault());
9596

@@ -153,19 +154,19 @@ public void GetAllTopics_ReturnsAllTopics() {
153154

154155
Assert.AreEqual<int>(5, relationships.Count);
155156
Assert.AreEqual<string>("Related3", relationships.GetTopics("Relationship3").First().Key);
156-
Assert.AreEqual<int>(5, relationships.GetAllTopics().Count());
157+
Assert.AreEqual<int>(5, relationships.GetAllTopics().Count);
157158

158159
}
159160

160161
/*==========================================================================================================================
161-
| TEST: GET ALL CONTENT TYPES: RETURNS ALL CONTENT TYPES
162+
| TEST: GET ALL TOPICS: CONTENT TYPES: RETURNS ALL CONTENT TYPES
162163
\-------------------------------------------------------------------------------------------------------------------------*/
163164
/// <summary>
164165
/// Sets relationships in multiple namespaces, with different ContentTypes, then filters the results of
165-
/// <see cref="RelatedTopicCollection.GetAllTopics(String)"/> by content type.
166+
/// <see cref="ReadOnlyTopicMultiMap.GetAllTopics(String)"/> by content type.
166167
/// </summary>
167168
[TestMethod]
168-
public void GetAllContentTypes_ReturnsAllContentTypes() {
169+
public void GetAllTopics_ContentTypes_ReturnsAllContentTypes() {
169170

170171
var parent = TopicFactory.Create("Parent", "Page");
171172
var relationships = new RelatedTopicCollection(parent);
@@ -174,8 +175,8 @@ public void GetAllContentTypes_ReturnsAllContentTypes() {
174175
relationships.SetTopic("Relationship" + i, TopicFactory.Create("Related" + i, "ContentType" + i));
175176
}
176177

177-
Assert.AreEqual<int>(5, relationships.Count);
178-
Assert.AreEqual<int>(1, relationships.GetAllTopics("ContentType3").Count());
178+
Assert.AreEqual<int>(5, relationships.Keys.Count);
179+
Assert.AreEqual<int>(1, relationships.GetAllTopics("ContentType3").Count);
179180

180181
}
181182

OnTopic/Repositories/TopicRepositoryBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ public virtual void Delete([ValidatedNotNull]Topic topic, bool isRecursive) {
481481

482482
foreach (var descendantTopic in descendantTopics) {
483483
foreach (var relationship in descendantTopic.Relationships) {
484-
foreach (var relatedTopic in relationship.ToArray()) {
484+
foreach (var relatedTopic in relationship.Values.ToList()) {
485485
if (!descendantTopics.Contains(relatedTopic)) {
486-
descendantTopic.Relationships.RemoveTopic(relationship.Name, relatedTopic);
486+
descendantTopic.Relationships.RemoveTopic(relationship.Key, relatedTopic);
487487
}
488488
}
489489
}
@@ -494,9 +494,9 @@ public virtual void Delete([ValidatedNotNull]Topic topic, bool isRecursive) {
494494
\-----------------------------------------------------------------------------------------------------------------------*/
495495
foreach (var descendantTopic in descendantTopics) {
496496
foreach (var relationship in descendantTopic.IncomingRelationships) {
497-
foreach (var relatedTopic in relationship.ToArray()) {
497+
foreach (var relatedTopic in relationship.Values.ToList()) {
498498
if (!descendantTopics.Contains(relatedTopic)) {
499-
relatedTopic.Relationships.RemoveTopic(relationship.Name, descendantTopic.Key);
499+
relatedTopic.Relationships.RemoveTopic(relationship.Key, descendantTopic);
500500
}
501501
}
502502
}

0 commit comments

Comments
 (0)