Skip to content

Commit cfa8fd3

Browse files
committed
Established new TopicQueryingTests
Previously, unit tests for the `OnTopic.Querying.TopicExtensions` class were placed in the `TopicTest` class. This made good sense as we only had a single unit test and it related to the `Topic` class. As we prepare to expand the `TopicExtensions` class, however, there's value to separating these out so that the extension methods are independently validated from the main `Topic` class. To kick this off, the existing `FindAllByAttribute_ReturnsCorrectTopics` unit test is being moved from `TopicTest` to `TopicQueryingTest`. In the near future, additional tests will be introduced, as new features are introduced.
1 parent 2806a5f commit cfa8fd3

2 files changed

Lines changed: 48 additions & 31 deletions

File tree

OnTopic.Tests/TopicQueryingTest.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project Topics Library
5+
\=============================================================================================================================*/
6+
using System;
7+
using System.Linq;
8+
using Microsoft.VisualStudio.TestTools.UnitTesting;
9+
using OnTopic.Querying;
10+
11+
namespace OnTopic.Tests {
12+
13+
/*============================================================================================================================
14+
| CLASS: TOPIC QUERYING TEST
15+
\---------------------------------------------------------------------------------------------------------------------------*/
16+
/// <summary>
17+
/// Provides unit tests for the <see cref="TopicExtensions"/> class.
18+
/// </summary>
19+
[TestClass]
20+
public class TopicQueryingTest {
21+
22+
/*==========================================================================================================================
23+
| TEST: FIND ALL BY ATTRIBUTE: RETURNS CORRECT TOPICS
24+
\-------------------------------------------------------------------------------------------------------------------------*/
25+
/// <summary>
26+
/// Looks for a deeply nested child topic using only the attribute value.
27+
/// </summary>
28+
[TestMethod]
29+
public void FindAllByAttribute_ReturnsCorrectTopics() {
30+
31+
var parentTopic = TopicFactory.Create("ParentTopic", "Page", 1);
32+
var childTopic = TopicFactory.Create("ChildTopic", "Page", 5, parentTopic);
33+
var grandChildTopic = TopicFactory.Create("GrandChildTopic", "Page", 20, childTopic);
34+
var grandNieceTopic = TopicFactory.Create("GrandNieceTopic", "Page", 3, childTopic);
35+
var greatGrandChildTopic = TopicFactory.Create("GreatGrandChildTopic", "Page", 7, grandChildTopic);
36+
37+
grandChildTopic.Attributes.SetValue("Foo", "Baz");
38+
greatGrandChildTopic.Attributes.SetValue("Foo", "Bar");
39+
grandNieceTopic.Attributes.SetValue("Foo", "Bar");
40+
41+
Assert.ReferenceEquals(parentTopic.FindAllByAttribute("Foo", "Bar").First(), grandNieceTopic);
42+
Assert.AreEqual<int>(2, parentTopic.FindAllByAttribute("Foo", "Bar").Count);
43+
Assert.ReferenceEquals(parentTopic.FindAllByAttribute("Foo", "Baz").First(), grandChildTopic);
44+
45+
}
46+
47+
} //Class
48+
} //Namespace

OnTopic.Tests/TopicTest.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Globalization;
88
using System.Linq;
99
using OnTopic.Metadata;
10-
using OnTopic.Querying;
1110
using Microsoft.VisualStudio.TestTools.UnitTesting;
1211
using OnTopic.Collections;
1312

@@ -179,36 +178,6 @@ public void UniqueKey_ReturnsUniqueKey() {
179178

180179
}
181180

182-
/*==========================================================================================================================
183-
| TEST: FIND ALL BY ATTRIBUTE: RETURNS CORRECT TOPICS
184-
\-------------------------------------------------------------------------------------------------------------------------*/
185-
/// <summary>
186-
/// Looks for a deeply nested child topic using only the attribute value.
187-
/// </summary>
188-
[TestMethod]
189-
public void FindAllByAttribute_ReturnsCorrectTopics() {
190-
191-
var parentTopic = TopicFactory.Create("ParentTopic", "Page", 1);
192-
var childTopic = TopicFactory.Create("ChildTopic", "Page", 5);
193-
var grandChildTopic = TopicFactory.Create("GrandChildTopic", "Page", 20);
194-
var grandNieceTopic = TopicFactory.Create("GrandNieceTopic", "Page", 3);
195-
var greatGrandChildTopic = TopicFactory.Create("GreatGrandChildTopic", "Page", 7);
196-
197-
childTopic.Parent = parentTopic;
198-
grandChildTopic.Parent = childTopic;
199-
grandNieceTopic.Parent = childTopic;
200-
greatGrandChildTopic.Parent = grandChildTopic;
201-
202-
grandChildTopic.Attributes.SetValue("Foo", "Baz");
203-
greatGrandChildTopic.Attributes.SetValue("Foo", "Bar");
204-
grandNieceTopic.Attributes.SetValue("Foo", "Bar");
205-
206-
Assert.ReferenceEquals(parentTopic.FindAllByAttribute("Foo", "Bar").First(), grandNieceTopic);
207-
Assert.AreEqual<int>(2, parentTopic.FindAllByAttribute("Foo", "Bar").Count);
208-
Assert.ReferenceEquals(parentTopic.FindAllByAttribute("Foo", "Baz").First(), grandChildTopic);
209-
210-
}
211-
212181
/*==========================================================================================================================
213182
| TEST: IS VISIBLE: RETURNS EXPECTED VALUE
214183
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)