Skip to content

Commit 120c55e

Browse files
committed
Introduced unit tests for GetAttributes()
In a previous commit, we introduced a new `GetAttributes()` method to `TopicRepositoryBase` (6662f07), but neglected to include unit test coverage. As we prepare to extend this functionality, we're including the missing unit tests to ensure that we're not breaking existing functionality in the process. This includes a "proxy" method on `StubTopicRepository` to publicly expose the `protected` `GetAttributes()` method via a `GetAttributesProxy()` passthrough.
1 parent e824c9c commit 120c55e

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

OnTopic.TestDoubles/StubTopicRepository.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
| Project Topics Library
55
\=============================================================================================================================*/
66
using System;
7+
using System.Collections.Generic;
78
using System.Globalization;
89
using OnTopic.Attributes;
910
using OnTopic.Internal.Diagnostics;
@@ -163,6 +164,13 @@ public override void Move(Topic topic, Topic target, Topic? sibling) {
163164
/// <inheritdoc />
164165
public override void Delete(Topic topic, bool isRecursive = false) => base.Delete(topic, isRecursive);
165166

167+
/*==========================================================================================================================
168+
| METHOD: GET ATTRIBUTES (PROXY)
169+
\-------------------------------------------------------------------------------------------------------------------------*/
170+
/// <inheritdoc cref="TopicRepositoryBase.GetAttributes(Topic, Boolean?, Boolean?)" />
171+
public IEnumerable<AttributeValue> GetAttributesProxy(Topic topic, bool? isExtendedAttribute, bool? isDirty = null) =>
172+
base.GetAttributes(topic, isExtendedAttribute, isDirty);
173+
166174
/*==========================================================================================================================
167175
| METHOD: CREATE FAKE DATA
168176
\-------------------------------------------------------------------------------------------------------------------------*/

OnTopic.Tests/TopicRepositoryBaseTest.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,64 @@ public TopicRepositoryBaseTest() {
4848
_topicRepository = new StubTopicRepository();
4949
}
5050

51+
/*==========================================================================================================================
52+
| TEST: GET ATTRIBUTES: ANY ATTRIBUTES: RETURNS ALL ATTRIBUTES
53+
\-------------------------------------------------------------------------------------------------------------------------*/
54+
/// <summary>
55+
/// Retrieves a list of attributes from a topic, without any filtering by whether or not the attribute is an <see
56+
/// cref="AttributeDescriptor.IsExtendedAttribute"/>.
57+
/// </summary>
58+
[TestMethod]
59+
public void GetAttributes_AnyAttributes_ReturnsAllAttributes() {
60+
61+
var topic = TopicFactory.Create("Test", "ContentTypes");
62+
63+
topic.Attributes.SetValue("Title", "Title");
64+
65+
var attributes = _topicRepository.GetAttributesProxy(topic, null);
66+
67+
Assert.AreEqual<int>(3, attributes.Count());
68+
69+
}
70+
71+
/*==========================================================================================================================
72+
| TEST: GET ATTRIBUTES: INDEXED ATTRIBUTES: RETURNS INDEXED ATTRIBUTES
73+
\-------------------------------------------------------------------------------------------------------------------------*/
74+
/// <summary>
75+
/// Retrieves a list of attributes from a topic, filtering by <see cref="AttributeDescriptor.IsExtendedAttribute"/>.
76+
/// </summary>
77+
[TestMethod]
78+
public void GetAttributes_IndexedAttributes_ReturnsIndexedAttributes() {
79+
80+
var topic = TopicFactory.Create("Test", "ContentTypes");
81+
82+
topic.Attributes.SetValue("Title", "Title");
83+
84+
var attributes = _topicRepository.GetAttributesProxy(topic, false);
85+
86+
Assert.AreEqual<int>(2, attributes.Count());
87+
88+
}
89+
90+
/*==========================================================================================================================
91+
| TEST: GET ATTRIBUTES: EXTENDED ATTRIBUTES: RETURNS EXTENDED ATTRIBUTES
92+
\-------------------------------------------------------------------------------------------------------------------------*/
93+
/// <summary>
94+
/// Retrieves a list of attributes from a topic, filtering by <see cref="AttributeDescriptor.IsExtendedAttribute"/>.
95+
/// </summary>
96+
[TestMethod]
97+
public void GetAttributes_ExtendedAttributes_ReturnsExtendedAttributes() {
98+
99+
var topic = TopicFactory.Create("Test", "ContentTypes");
100+
101+
topic.Attributes.SetValue("Title", "Title");
102+
103+
var attributes = _topicRepository.GetAttributesProxy(topic, true);
104+
105+
Assert.AreEqual<int>(1, attributes.Count());
106+
107+
}
108+
51109
/*==========================================================================================================================
52110
| TEST: GET CONTENT TYPE DESCRIPTORS: RETURNS CONTENT TYPES
53111
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)