-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTopicViewResultExecutorTest.cs
More file actions
166 lines (128 loc) · 8.25 KB
/
TopicViewResultExecutorTest.cs
File metadata and controls
166 lines (128 loc) · 8.25 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
/*==============================================================================================================================
| Author Ignia, LLC
| Client Ignia, LLC
| Project Topics Library
\=============================================================================================================================*/
using System.Net;
namespace OnTopic.AspNetCore.Mvc.IntegrationTests {
/*============================================================================================================================
| TEST: TOPIC VIEW RESULT EXECUTOR
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// The <see cref="TopicViewResultExecutor"/> is responsible for identifying the view based on a variety of sources,
/// including the query string, HTTP request headers, <see cref="Topic.View"/>, etc. This test evaluates those to ensure
/// that views are being correctly identified based on these criteria.
/// </summary>
[Collection("Web Application")]
public class TopicViewResultExecutorTest: IClassFixture<WebApplicationFactory<Startup>> {
/*==========================================================================================================================
| PRIVATE VARIABLES
\-------------------------------------------------------------------------------------------------------------------------*/
private readonly WebApplicationFactory<Startup> _factory;
/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new instance of the <see cref="TopicViewResultExecutorTest"/>.
/// </summary>
public TopicViewResultExecutorTest(WebApplicationFactory<Startup> factory) {
_factory = factory;
}
/*==========================================================================================================================
| TEST: QUERY STRING: RETURNS EXPECTED VIEW
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Constructs a test with a query string parameter to ensure that the expected view is returned.
/// </summary>
[Fact]
public async Task QueryString_ReturnsExpectedView() {
var client = _factory.CreateClient();
var uri = new Uri("/Web/ContentList/?View=Accordion", UriKind.Relative);
var response = await client.GetAsync(uri).ConfigureAwait(false);
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
response.EnsureSuccessStatusCode();
Assert.Equal("text/html; charset=utf-8", response.Content.Headers.ContentType?.ToString());
Assert.Equal("~/Views/ContentList/Accordion.cshtml", content);
}
/*==========================================================================================================================
| TEST: HEADER: RETURNS EXPECTED VIEW
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Constructs a test with a request header to ensure that the expected view is returned.
/// </summary>
[Fact]
public async Task Header_ReturnsExpectedView() {
var client = _factory.CreateClient();
client.DefaultRequestHeaders.Add("Accept", "application/json, string/Accordion;level=2;q=0.4, text/html");
var uri = new Uri("/Web/ContentList/", UriKind.Relative);
var response = await client.GetAsync(uri).ConfigureAwait(false);
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
response.EnsureSuccessStatusCode();
Assert.Equal("text/html; charset=utf-8", response.Content.Headers.ContentType?.ToString());
Assert.Equal("~/Views/ContentList/Accordion.cshtml", content);
}
/*==========================================================================================================================
| TEST: ACTION: RETURNS EXPECTED VIEW
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Constructs a test with a specified action to ensure that the expected view is returned.
/// </summary>
[Fact]
public async Task Action_ReturnsExpectedView() {
var client = _factory.CreateClient();
var uri = new Uri("/Area/Area/Accordion", UriKind.Relative);
var response = await client.GetAsync(uri).ConfigureAwait(false);
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
response.EnsureSuccessStatusCode();
Assert.Equal("text/html; charset=utf-8", response.Content.Headers.ContentType?.ToString());
Assert.Equal("~/Views/ContentList/Accordion.cshtml", content);
}
/*==========================================================================================================================
| TEST: TOPIC: RETURNS EXPECTED VIEW
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Constructs a test with a specified <see cref="Topic.View"/> to ensure that the expected view is returned.
/// </summary>
[Fact]
public async Task Topic_ReturnsExpectedView() {
var client = _factory.CreateClient();
var uri = new Uri("/Area/TopicWithView/", UriKind.Relative);
var response = await client.GetAsync(uri).ConfigureAwait(false);
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
response.EnsureSuccessStatusCode();
Assert.Equal("text/html; charset=utf-8", response.Content.Headers.ContentType?.ToString());
Assert.Equal("~/Views/ContentList/Accordion.cshtml", content);
}
/*==========================================================================================================================
| TEST: CONTENT TYPE: RETURNS EXPECTED VIEW
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Constructs a test with without a view specified to ensure that the expected default view is returned based on the <see
/// cref="Topic.ContentType"/>.
/// </summary>
[Fact]
public async Task ContentType_ReturnsExpectedView() {
var client = _factory.CreateClient();
var uri = new Uri("/Web/ContentList/", UriKind.Relative);
var response = await client.GetAsync(uri).ConfigureAwait(false);
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
response.EnsureSuccessStatusCode();
Assert.Equal("text/html; charset=utf-8", response.Content.Headers.ContentType?.ToString());
Assert.Equal("~/Views/ContentList/ContentList.cshtml", content);
}
/*==========================================================================================================================
| TEST: MISSING VIEW: RETURNS INTERNAL SERVER ERROR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Constructs a test without a view and without a default implementation for the <see cref="Topic.ContentType"/> and
/// ensures that an <see cref="HttpStatusCode.InternalServerError"/> is returned.
/// </summary>
[Fact]
public async Task MissingView_ReturnsInternalServerError() {
var client = _factory.CreateClient();
var uri = new Uri("/Web/MissingView/", UriKind.Relative);
var response = await client.GetAsync(uri).ConfigureAwait(false);
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
}
}
}