-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitTestStatusPageManager.cs
More file actions
211 lines (189 loc) · 10.4 KB
/
Copy pathUnitTestStatusPageManager.cs
File metadata and controls
211 lines (189 loc) · 10.4 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using WebExpress.WebCore.Test.Fixture;
using WebExpress.WebCore.WebComponent;
using WebExpress.WebCore.WebStatusPage;
namespace WebExpress.WebCore.Test.Manager
{
/// <summary>
/// Test the status page manager.
/// </summary>
[Collection("NonParallelTests")]
public class UnitTestStatusPageManager
{
/// <summary>
/// Test the register function of the status page manager.
/// </summary>
[Fact]
public void Register()
{
// arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
// act
Assert.Equal(12, componentHub.StatusPageManager.StatusPages.Count());
}
/// <summary>
/// Test the remove function of the status page manager.
/// </summary>
[Fact]
public void Remove()
{
// arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var plugin = componentHub.PluginManager.GetPlugin(typeof(TestPlugin));
var statusPageManager = componentHub.StatusPageManager as StatusPageManager;
// act
statusPageManager.Remove(plugin);
Assert.Empty(componentHub.StatusPageManager.StatusPages);
}
/// <summary>
/// Test the id property of the status page.
/// </summary>
[Theory]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage301), "webexpress.webcore.test.teststatuspage301")]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage400), "webexpress.webcore.test.teststatuspage400")]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage404), "webexpress.webcore.test.teststatuspage404")]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage500), "webexpress.webcore.test.teststatuspage500")]
public void Id(Type applicationType, Type statusPageType, string id)
{
// arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var statusPage = componentHub.StatusPageManager.GetStatusPage(application, statusPageType);
// act
Assert.Equal(id, statusPage.StatusPageId.ToString());
}
/// <summary>
/// Test the title property of the status page.
/// </summary>
[Theory]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage301), "webindex:homepage.label")]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage400), "webindex:homepage.label")]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage404), "webindex:homepage.label")]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage500), "webindex:homepage.label")]
[InlineData(typeof(TestApplicationB), typeof(TestStatusPage301), "webindex:homepage.label")]
[InlineData(typeof(TestApplicationB), typeof(TestStatusPage400), "webindex:homepage.label")]
[InlineData(typeof(TestApplicationB), typeof(TestStatusPage404), "webindex:homepage.label")]
[InlineData(typeof(TestApplicationB), typeof(TestStatusPage500), "webindex:homepage.label")]
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage301), "webindex:homepage.label")]
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage400), "webindex:homepage.label")]
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage404), "webindex:homepage.label")]
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage500), "webindex:homepage.label")]
public void Title(Type applicationType, Type resourceType, string title)
{
// arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var statusPage = componentHub.StatusPageManager.GetStatusPage(application, resourceType);
// act
Assert.Equal(title, statusPage.StatusTitle);
}
/// <summary>
/// Test the id property of the status page.
/// </summary>
[Theory]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage301), 301)]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage400), 400)]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage404), 404)]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage500), 500)]
[InlineData(typeof(TestApplicationB), typeof(TestStatusPage301), 301)]
[InlineData(typeof(TestApplicationB), typeof(TestStatusPage400), 400)]
[InlineData(typeof(TestApplicationB), typeof(TestStatusPage404), 404)]
[InlineData(typeof(TestApplicationB), typeof(TestStatusPage500), 500)]
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage301), 301)]
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage400), 400)]
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage404), 404)]
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage500), 500)]
public void Code(Type applicationType, Type statusPageType, int? code)
{
// arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var statusPage = componentHub.StatusPageManager.GetStatusPage(application, statusPageType);
// act
Assert.Equal(code, statusPage?.StatusCode);
}
/// <summary>
/// Test the icon property of the status page.
/// </summary>
[Theory]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage301), null)]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage400), "/server/appa/webexpress/icon.png")]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage404), "/server/appa/webexpress/icon.png")]
[InlineData(typeof(TestApplicationA), typeof(TestStatusPage500), "/server/appa/webexpress/icon.png")]
[InlineData(typeof(TestApplicationB), typeof(TestStatusPage301), null)]
[InlineData(typeof(TestApplicationB), typeof(TestStatusPage400), "/server/appb/webexpress/icon.png")]
[InlineData(typeof(TestApplicationB), typeof(TestStatusPage404), "/server/appb/webexpress/icon.png")]
[InlineData(typeof(TestApplicationB), typeof(TestStatusPage500), "/server/appb/webexpress/icon.png")]
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage301), null)]
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage400), "/server/webexpress/icon.png")]
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage404), "/server/webexpress/icon.png")]
[InlineData(typeof(TestApplicationC), typeof(TestStatusPage500), "/server/webexpress/icon.png")]
public void Icon(Type applicationType, Type statusPageType, string icon)
{
// arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var statusPage = componentHub.StatusPageManager.GetStatusPage(application, statusPageType);
// act
Assert.Equal(icon, statusPage?.StatusIcon?.ToString());
}
/// <summary>
/// Test the CreateStatusResponse function of the status page.
/// </summary>
[Theory]
[InlineData(typeof(TestApplicationA), 400, 400)]
[InlineData(typeof(TestApplicationA), 404, 404)]
[InlineData(typeof(TestApplicationB), 404, 404)]
[InlineData(typeof(TestApplicationB), 500, 500)]
[InlineData(typeof(TestApplicationA), 500, 500)]
public void CreateAndCheckCode(Type applicationType, int statusCode, int? expected)
{
// arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var statusResponse = componentHub.StatusPageManager.CreateStatusResponse("content", statusCode, application, UnitTestFixture.CreateHttpContextMock().Request);
// act
Assert.Equal(expected, statusResponse?.Status);
}
/// <summary>
/// Test the CreateStatusResponse function of the status page.
/// </summary>
[Theory]
[InlineData(typeof(TestApplicationA), 400, "content", "content", 72)]
[InlineData(typeof(TestApplicationA), 500, "content", "content", 72)]
public void CreateAndCheckMessage(Type applicationType, int statusCode, string content, string expected, int length)
{
// arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
var application = componentHub.ApplicationManager.GetApplications(applicationType).FirstOrDefault();
var statusResponse = componentHub.StatusPageManager.CreateStatusResponse(content, statusCode, application, UnitTestFixture.CreateHttpContextMock().Request);
// act
Assert.Contains(expected, statusResponse?.Content?.ToString());
Assert.Equal(length, statusResponse?.Header?.ContentLength);
}
/// <summary>
/// Tests whether the status page manager implements interface IComponentManager.
/// </summary>
[Fact]
public void IsIComponentManager()
{
// arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
// act
Assert.True(typeof(IComponentManager).IsAssignableFrom(componentHub.StatusPageManager.GetType()));
}
/// <summary>
/// Tests whether the status page context implements interface IContext.
/// </summary>
[Fact]
public void IsIContext()
{
// arrange
var componentHub = UnitTestFixture.CreateAndRegisterComponentHubMock();
// act
foreach (var application in componentHub.StatusPageManager.StatusPages)
{
Assert.True(typeof(IContext).IsAssignableFrom(application.GetType()), $"Page context {application.GetType().Name} does not implement IContext.");
}
}
}
}