Skip to content

Commit 7049cc9

Browse files
committed
Established test for TopicViewLocationExpander with topics
The `TopicViewLocationExpander` supports looking for views based on `Topic.ContentType` and an optional view (which can be specified via a number of locations, though we'll use the query string for the purpose of these tests). It evaluates views established as part of a previous commit (1160903). Each fallback location is given a unique view name so that we don't need to worry about competing views. Each view contains the path to the view so we can confirm the exact view expected was returned.
1 parent 5cf758a commit 7049cc9

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

OnTopic.AspNetCore.Mvc.IntegrationTests/TopicViewLocationExpanderTest.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,46 @@ public TopicViewLocationExpanderTest() {
3838
_factory = new WebApplicationFactory<Startup>();
3939
}
4040

41+
/*==========================================================================================================================
42+
| TEST: EXPAND VIEW LOCATIONS: VIEWS
43+
\-------------------------------------------------------------------------------------------------------------------------*/
44+
/// <summary>
45+
/// Evaluates multiple views to ensure they fallback to the appropriate locations as defined in <see cref="
46+
/// TopicViewLocationExpander.ViewLocations"/> and <see cref="TopicViewLocationExpander.AreaViewLocations"/>.
47+
/// </summary>
48+
[TestMethod]
49+
[DataRow( "AreaContentTypeView", "ContentType/AreaContentTypeView.cshtml")]
50+
[DataRow( "AreaContentTypeSharedView", "ContentType/Shared/AreaContentTypeSharedView.cshtml")]
51+
[DataRow( "AreaContentTypesView", "ContentTypes/ContentType.AreaContentTypesView.cshtml")]
52+
[DataRow( "AreaContentTypesSharedView", "ContentTypes/Shared/AreaContentTypesSharedView.cshtml")]
53+
[DataRow( "AreaContentTypesFallbackView", "ContentTypes/AreaContentTypesFallbackView.cshtml")]
54+
[DataRow( "AreaSharedView", "Shared/AreaSharedView.cshtml")]
55+
[DataRow( "ContentTypeView", "ContentType/ContentTypeView.cshtml")]
56+
[DataRow( "ContentTypeSharedView", "ContentType/Shared/ContentTypeSharedView.cshtml")]
57+
[DataRow( "ContentTypesView", "ContentTypes/ContentType.ContentTypesView.cshtml")]
58+
[DataRow( "ContentTypesSharedView", "ContentTypes/Shared/ContentTypesSharedView.cshtml")]
59+
[DataRow( "ContentTypesFallbackView", "ContentTypes/ContentTypesFallbackView.cshtml")]
60+
[DataRow( "SharedView", "Shared/SharedView.cshtml")]
61+
public async Task ExpandViewLocations_Views(string viewName, string viewLocation) {
62+
63+
if (viewName is not null && viewName.StartsWith("Area", StringComparison.OrdinalIgnoreCase)) {
64+
viewLocation = $"~/Areas/Area/Views/{viewLocation}";
65+
}
66+
else {
67+
viewLocation = $"~/Views/{viewLocation}";
68+
}
69+
70+
var client = _factory.CreateClient();
71+
var uri = new Uri($"/Area/?View={viewName}", UriKind.Relative);
72+
var response = await client.GetAsync(uri).ConfigureAwait(false);
73+
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
74+
75+
response.EnsureSuccessStatusCode();
76+
77+
Assert.AreEqual<string?>("text/html; charset=utf-8", response.Content.Headers.ContentType?.ToString());
78+
Assert.AreEqual<string?>(viewLocation, content);
79+
80+
}
81+
4182
}
4283
}

0 commit comments

Comments
 (0)