Skip to content

Commit 477b628

Browse files
committed
Established new TopicRepositoryBaseTest
Previously, unit tests for the `OnTopic.Repositories.TopicRepositoryBase` class were placed in the `ITopicRepositoryTest` class. This made reasonable sense as the `TopicRepositoryBase` is an `abstract` class, and almost all of the functionality needs to be tested through a concrete implementation such as `StubTopicRepository` anyway. As we prepare to expand the `TopicRepositoryBase` class, however, there's value to separating these out so that the methods can be independently validated. These are still dependent on a concrete implementation, but that work can be done through simple pass-through methods. As some tests will still benefit from having prepackaged data to work with, we'll continue to operate against the `StubTopicRepository`—as opposed to the simpler `DummyTopicRepository`—though for many tests we'll just be relying on minimal pass-through methods. In fact, for most cases, we'll be exposing "proxy" methods to publicly expose the underlying `protected` methods with no intermediary business logic.
1 parent d18984d commit 477b628

2 files changed

Lines changed: 73 additions & 22 deletions

File tree

OnTopic.Tests/ITopicRepositoryTest.cs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
using System.Linq;
88
using OnTopic.Collections;
99
using OnTopic.Data.Caching;
10-
using OnTopic.Metadata;
1110
using OnTopic.Repositories;
1211
using OnTopic.TestDoubles;
1312
using Microsoft.VisualStudio.TestTools.UnitTesting;
1413

1514
namespace OnTopic.Tests {
1615

1716
/*============================================================================================================================
18-
| CLASS: ATTRIBUTE VALUE COLLECTION TEST
17+
| CLASS: TOPIC REPOSITORY TEST
1918
\---------------------------------------------------------------------------------------------------------------------------*/
2019
/// <summary>
2120
/// Provides unit tests for the <see cref="AttributeValueCollection"/> class.
@@ -30,7 +29,7 @@ public class ITopicRepositoryTest {
3029
/*==========================================================================================================================
3130
| PRIVATE VARIABLES
3231
\-------------------------------------------------------------------------------------------------------------------------*/
33-
readonly ITopicRepository _topicRepository;
32+
readonly ITopicRepository _topicRepository;
3433

3534
/*==========================================================================================================================
3635
| CONSTRUCTOR
@@ -225,24 +224,5 @@ public void Delete_Topic_Removed() {
225224

226225
}
227226

228-
/*==========================================================================================================================
229-
| TEST: GET CONTENT TYPE DESCRIPTORS: RETURNS TOPICS
230-
\-------------------------------------------------------------------------------------------------------------------------*/
231-
/// <summary>
232-
/// Retrieves a list of <see cref="ContentTypeDescriptor"/>s from the <see cref="ITopicRepository"/> and ensures that
233-
/// the expected number (2) are present.
234-
/// </summary>
235-
[TestMethod]
236-
public void GetContentTypeDescriptors_ReturnsTopics() {
237-
238-
var contentTypes = _topicRepository.GetContentTypeDescriptors();
239-
240-
Assert.AreEqual<int>(15, contentTypes.Count);
241-
Assert.IsNotNull(contentTypes.GetTopic("ContentTypeDescriptor"));
242-
Assert.IsNotNull(contentTypes.GetTopic("Page"));
243-
Assert.IsNotNull(contentTypes.GetTopic("LookupListItem"));
244-
245-
}
246-
247227
} //Class
248228
} //Namespace
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project Topics Library
5+
\=============================================================================================================================*/
6+
using System;
7+
using System.Linq;
8+
using OnTopic.Data.Caching;
9+
using OnTopic.Metadata;
10+
using OnTopic.Repositories;
11+
using OnTopic.TestDoubles;
12+
using Microsoft.VisualStudio.TestTools.UnitTesting;
13+
using OnTopic.Metadata.AttributeTypes;
14+
using OnTopic.Attributes;
15+
16+
namespace OnTopic.Tests {
17+
18+
/*============================================================================================================================
19+
| CLASS: TOPIC REPOSITORY BASE TESTS
20+
\---------------------------------------------------------------------------------------------------------------------------*/
21+
/// <summary>
22+
/// Provides unit tests for the <see cref="TopicRepositoryBase"/> class.
23+
/// </summary>
24+
/// <remarks>
25+
/// These tests evaluate features that are specific to the <see cref="TopicRepositoryBase"/> class.
26+
/// </remarks>
27+
[TestClass]
28+
public class TopicRepositoryBaseTest {
29+
30+
/*==========================================================================================================================
31+
| PRIVATE VARIABLES
32+
\-------------------------------------------------------------------------------------------------------------------------*/
33+
readonly StubTopicRepository _topicRepository;
34+
35+
/*==========================================================================================================================
36+
| CONSTRUCTOR
37+
\-------------------------------------------------------------------------------------------------------------------------*/
38+
/// <summary>
39+
/// Initializes a new instance of the <see cref="TopicRepositoryBaseTest"/> with shared resources.
40+
/// </summary>
41+
/// <remarks>
42+
/// This uses the <see cref="StubTopicRepository"/> to provide data, and then <see cref="CachedTopicRepository"/> to
43+
/// manage the in-memory representation of the data. While this introduces some overhead to the tests, the latter is a
44+
/// relatively lightweight façade to any <see cref="ITopicRepository"/>, and prevents the need to duplicate logic for
45+
/// crawling the object graph.
46+
/// </remarks>
47+
public TopicRepositoryBaseTest() {
48+
_topicRepository = new StubTopicRepository();
49+
}
50+
51+
/*==========================================================================================================================
52+
| TEST: GET CONTENT TYPE DESCRIPTORS: RETURNS CONTENT TYPES
53+
\-------------------------------------------------------------------------------------------------------------------------*/
54+
/// <summary>
55+
/// Retrieves a list of <see cref="ContentTypeDescriptor"/>s from the <see cref="ITopicRepository"/> and ensures that
56+
/// the expected number (2) are present.
57+
/// </summary>
58+
[TestMethod]
59+
public void GetContentTypeDescriptors_ReturnsContentTypes() {
60+
61+
var contentTypes = _topicRepository.GetContentTypeDescriptors();
62+
63+
Assert.AreEqual<int>(15, contentTypes.Count);
64+
Assert.IsNotNull(contentTypes.GetTopic("ContentTypeDescriptor"));
65+
Assert.IsNotNull(contentTypes.GetTopic("Page"));
66+
Assert.IsNotNull(contentTypes.GetTopic("LookupListItem"));
67+
68+
}
69+
70+
} //Class
71+
} //Namespace

0 commit comments

Comments
 (0)