-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTopicViewLocationExpanderTest.cs
116 lines (99 loc) · 6.99 KB
/
TopicViewLocationExpanderTest.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
111
112
113
114
115
116
/*==============================================================================================================================
| Author Ignia, LLC
| Client Ignia, LLC
| Project Topics Library
\=============================================================================================================================*/
using OnTopic.AspNetCore.Mvc.IntegrationTests.Areas.Area.Controllers;
namespace OnTopic.AspNetCore.Mvc.IntegrationTests {
/*============================================================================================================================
| TEST: TOPIC VIEW LOCATION EXPANDER
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// The <see cref="TopicViewLocationExpander"/> is responsible for locating whether a view exists based on a set of file
/// path conventions. This test evaluates those to ensure that view locations are being correctly evaluated based on those
/// conventions.
/// </summary>
[Collection("Web Application")]
public class TopicViewLocationExpanderTest: IClassFixture<WebApplicationFactory<Startup>> {
/*==========================================================================================================================
| PRIVATE VARIABLES
\-------------------------------------------------------------------------------------------------------------------------*/
private readonly WebApplicationFactory<Startup> _factory;
/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new instance of the <see cref="TopicViewLocationExpanderTest"/>.
/// </summary>
public TopicViewLocationExpanderTest(WebApplicationFactory<Startup> factory) {
_factory = factory;
}
/*==========================================================================================================================
| TEST: EXPAND VIEW LOCATIONS: VIEWS
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Evaluates multiple views to ensure they fallback to the appropriate locations as defined in <see cref="
/// TopicViewLocationExpander.ViewLocations"/> and <see cref="TopicViewLocationExpander.AreaViewLocations"/>.
/// </summary>
[Theory]
[InlineData( "AreaContentTypeView", "ContentType/AreaContentTypeView.cshtml")]
[InlineData( "AreaContentTypeSharedView", "ContentType/Shared/AreaContentTypeSharedView.cshtml")]
[InlineData( "AreaContentTypesView", "ContentTypes/ContentType.AreaContentTypesView.cshtml")]
[InlineData( "AreaContentTypesSharedView", "ContentTypes/Shared/AreaContentTypesSharedView.cshtml")]
[InlineData( "AreaContentTypesFallbackView", "ContentTypes/AreaContentTypesFallbackView.cshtml")]
[InlineData( "AreaSharedView", "Shared/AreaSharedView.cshtml")]
[InlineData( "ContentTypeView", "ContentType/ContentTypeView.cshtml")]
[InlineData( "ContentTypeSharedView", "ContentType/Shared/ContentTypeSharedView.cshtml")]
[InlineData( "ContentTypesView", "ContentTypes/ContentType.ContentTypesView.cshtml")]
[InlineData( "ContentTypesSharedView", "ContentTypes/Shared/ContentTypesSharedView.cshtml")]
[InlineData( "ContentTypesFallbackView", "ContentTypes/ContentTypesFallbackView.cshtml")]
[InlineData( "SharedView", "Shared/SharedView.cshtml")]
public async Task ExpandViewLocations_Views(string viewName, string viewLocation) {
if (viewName is not null && viewName.StartsWith("Area", StringComparison.OrdinalIgnoreCase)) {
viewLocation = $"~/Areas/Area/Views/{viewLocation}";
}
else {
viewLocation = $"~/Views/{viewLocation}";
}
var client = _factory.CreateClient();
var uri = new Uri($"/Area/?View={viewName}", 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(viewLocation, content);
}
/*==========================================================================================================================
| TEST: EXPAND VIEW LOCATIONS: ACTIONS
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Evaluates multiple actions off of the <see cref="ControllerController"/> to ensure they fallback to the appropriate
/// locations as defined in <see cref="TopicViewLocationExpander.ViewLocations"/> and <see cref="TopicViewLocationExpander
/// .AreaViewLocations"/>.
/// </summary>
[Theory]
[InlineData( "AreaAction", "Controller/AreaAction.cshtml")]
[InlineData( "AreaFallbackAction", "AreaFallbackAction.cshtml")]
[InlineData( "AreaSharedAction", "Controller/Shared/AreaSharedAction.cshtml")]
[InlineData( "AreaSharedFallbackAction", "Shared/AreaSharedFallbackAction.cshtml")]
[InlineData( "Action", "Controller/Action.cshtml")]
[InlineData( "FallbackAction", "FallbackAction.cshtml")]
[InlineData( "SharedAction", "Controller/Shared/SharedAction.cshtml")]
[InlineData( "SharedFallbackAction", "Shared/SharedFallbackAction.cshtml")]
public async Task ExpandViewLocations_Actions(string viewName, string viewLocation) {
if (viewName is not null && viewName.StartsWith("Area", StringComparison.OrdinalIgnoreCase)) {
viewLocation = $"~/Areas/Area/Views/{viewLocation}";
}
else {
viewLocation = $"~/Views/{viewLocation}";
}
var client = _factory.CreateClient();
var uri = new Uri($"/Area/Controller/{viewName}/", 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(viewLocation, content);
}
}
}