-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTopicRepositoryExtensionsTest.cs
110 lines (87 loc) · 4.95 KB
/
TopicRepositoryExtensionsTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*==============================================================================================================================
| Author Ignia, LLC
| Client Ignia, LLC
| Project Topics Library
\=============================================================================================================================*/
using Microsoft.AspNetCore.Routing;
using OnTopic.AspNetCore.Mvc;
using OnTopic.Data.Caching;
using OnTopic.Repositories;
namespace OnTopic.Tests {
/*============================================================================================================================
| CLASS: TOPIC REPOSITORY EXTENSIONS TEST
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides unit tests for the <see cref="TopicRepositoryExtensions"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
[Collection("Data Tests")]
public class TopicRepositoryExtensionsTest: IClassFixture<StubTopicRepository> {
/*==========================================================================================================================
| PRIVATE VARIABLES
\-------------------------------------------------------------------------------------------------------------------------*/
readonly ITopicRepository _topicRepository;
/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new instance of the <see cref="TopicRepositoryExtensionsTest"/> with shared resources.
/// </summary>
/// <remarks>
/// This uses the <see cref="StubTopicRepository"/> to provide data, and then <see cref="CachedTopicRepository"/> to
/// manage the in-memory representation of the data. While this introduces some overhead to the tests, the latter is a
/// relatively lightweight façade to any <see cref="ITopicRepository"/>, and prevents the need to duplicate logic for
/// crawling the object graph.
/// </remarks>
public TopicRepositoryExtensionsTest(StubTopicRepository topicRepository) {
_topicRepository = new CachedTopicRepository(topicRepository);
}
/*==========================================================================================================================
| TEST: LOAD: BY ROUTE: RETURNS TOPIC
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes route data and ensures that a topic is correctly identified based on that route.
/// </summary>
[Fact]
public void Load_ByRoute_ReturnsTopic() {
var routes = new RouteData();
var topic = _topicRepository.Load("Root:Web:Web_0:Web_0_1:Web_0_1_1");
routes.Values.Add("rootTopic", "Web");
routes.Values.Add("path", "Web_0/Web_0_1/Web_0_1_1");
var currentTopic = _topicRepository.Load(routes);
Assert.NotNull(currentTopic);
Assert.Equal(topic, currentTopic);
Assert.Equal("Web_0_1_1", currentTopic?.Key);
}
/*==========================================================================================================================
| TEST: LOAD: BY ROUTE: RETURNS ROOT TOPIC
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes route data and ensures that the root topic is correctly identified based on that route.
/// </summary>
[Fact]
public void Load_ByRoute_ReturnsRootTopic() {
var routes = new RouteData();
var topic = _topicRepository.Load("Root");
routes.Values.Add("path", "Root/");
var currentTopic = _topicRepository.Load(routes);
Assert.NotNull(currentTopic);
Assert.Equal(topic, currentTopic);
Assert.Equal("Root", currentTopic?.Key);
}
/*==========================================================================================================================
| TEST: LOAD: BY ROUTE: SWALLOWS EXCEPTION
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Establishes route data with an invalid key and ensures that no result is returned, but no exception is thrown.
/// </summary>
[Fact]
public void Load_ByRoute_SwallowsException() {
var routes = new RouteData();
routes.Values.Add("rootTopic", "Web");
routes.Values.Add("path", "Web/~* &$#@");
var currentTopic = _topicRepository.Load(routes);
Assert.Null(currentTopic);
}
} //Class
} //Namespace