Skip to content

Commit 2adef58

Browse files
committed
Introduced IsDirty() method to RelatedTopicCollection
The `IsDirty()` method simply evaluates the `NamedTopicCollection.IsDirty` flag from each child collection (4762694) and returns `true` if _any_ of them are `true`. This allows callers to quickly assess whether or not any relationships have changed.
1 parent 4762694 commit 2adef58

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

OnTopic.Tests/RelatedTopicCollectionTest.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace OnTopic.Tests {
1414
| CLASS: RELATED TOPIC COLLECTION TEST
1515
\---------------------------------------------------------------------------------------------------------------------------*/
1616
/// <summary>
17-
/// Provides unit tests for the <see cref="AttributeValueCollection"/> class.
17+
/// Provides unit tests for the <see cref="RelatedTopicCollection"/> class.
1818
/// </summary>
1919
[TestClass]
2020
public class RelatedTopicCollectionTest {
@@ -37,6 +37,24 @@ public void SetTopic_CreatesRelationship() {
3737

3838
}
3939

40+
/*==========================================================================================================================
41+
| TEST: SET TOPIC: IS DIRTY
42+
\-------------------------------------------------------------------------------------------------------------------------*/
43+
/// <summary>
44+
/// Sets a relationship and confirms that the <see cref="RelatedTopicCollection.IsDirty"/> returns true.
45+
/// </summary>
46+
[TestMethod]
47+
public void SetTopic_IsDirty() {
48+
49+
var parent = TopicFactory.Create("Parent", "Page");
50+
var related = TopicFactory.Create("Related", "Page");
51+
52+
parent.Relationships.SetTopic("Friends", related);
53+
54+
Assert.IsTrue(parent.Relationships.IsDirty());
55+
56+
}
57+
4058
/*==========================================================================================================================
4159
| TEST: SET TOPIC: CREATES INCOMING RELATIONSHIP
4260
\-------------------------------------------------------------------------------------------------------------------------*/

OnTopic/Collections/RelatedTopicCollection.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Collections.ObjectModel;
88
using System.Linq;
9+
using System.Xml.Serialization;
910
using OnTopic.Internal.Diagnostics;
1011

1112
namespace OnTopic.Collections {
@@ -223,6 +224,15 @@ public void SetTopic(string relationshipKey, Topic topic, bool isIncoming) {
223224

224225
}
225226

227+
/*==========================================================================================================================
228+
| METHOD: IS DIRTY?
229+
\-------------------------------------------------------------------------------------------------------------------------*/
230+
/// <summary>
231+
/// Evaluates each of the child <see cref="NamedTopicCollection"/>s to determine if any of them are set to <see
232+
/// cref="NamedTopicCollection.IsDirty"/>. If they are, returns <c>true</c>.
233+
/// </summary>
234+
public bool IsDirty() => Items.Any(r => r.IsDirty);
235+
226236
/*==========================================================================================================================
227237
| OVERRIDE: INSERT ITEM
228238
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)