Skip to content

Commit 8d921a7

Browse files
committed
Merge branch 'release/4.6.0' into master
This update includes a few minor features, most notably improvements over routing and reporting for the ASP.NET Core `TopicController`. In addition, it upgrades the underlying code to C# 9.0 in order to take advantage of some new features such as improved pattern matching and implicitly typed initializers. Features - Updated `[ValidateTopic]` attribute to redirect to canonical URL to ensure consistency in analytics, indexes (0edab34) - Updated `Topic.Load(RouteData)` extension to return null if an invalid `Key` is submitted (b303f13); this results in the `TopicController` treating incorrect topic paths (e.g., `/Web/!@~/`) as 404s instead of exceptions - Added support for enabling (`IsIndexed`) and configuring (`IndexLabel`) an optional table of contents to the `ContentListTopicViewModel` (e9ccb06) Bug Fixes - Fixed issue with where the delegate is validated in the `HierarchicalTopicMappingService.GetViewModelAsnc()` method (69dff49) Improvements - Updated code to use C# 9.0 pattern matching and implicitly typed initializers (d63f2b5) - Updated to latest versions of internal packages, and implemented (4838da8) - Updated to latest version of Code Analysis and fixed most issues introduced with C# 9.0 (089c96a) Note: There are some Code Analysis false positives that remain with C# 9.0. Those are presumably fixed with the new `Microsoft.CodeAnalysis.NetAnalyzers` 5.0.0. There appears to be a bug in getting that to work with .NET 3.x projects, however, so it's not yet implemented.
2 parents 371f279 + 089c96a commit 8d921a7

86 files changed

Lines changed: 348 additions & 312 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

OnTopic.AspNetCore.Mvc.Host/OnTopic.AspNetCore.Mvc.Host.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<UserSecretsId>62eb85bf-f802-4afd-8bec-3d344e1cfc79</UserSecretsId>
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>

OnTopic.AspNetCore.Mvc.Host/Views/Layout/_Layout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<!-- /Page Header Area -->
2727

2828
<article itemscope itemtype="http://schema.org/WebPageElement" itemprop="mainContentOfPage" class="grid-container">
29-
<h1>@(Model.ContentType.Equals("PageGroup")? "Overview" : Model.Title)</h1>
29+
<h1>@(Model.ContentType == "PageGroup"? "Overview" : Model.Title)</h1>
3030
<p class="subtitle">@Model.Subtitle</p>
3131
<section class="body">
3232
<partial name="_TopicAttributes" />

OnTopic.AspNetCore.Mvc.Tests/OnTopic.AspNetCore.Mvc.Tests.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<IsPackable>false</IsPackable>
6+
<LangVersion>9.0</LangVersion>
67
</PropertyGroup>
78

89
<ItemGroup>
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
1011
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
1112
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
1213
</ItemGroup>

OnTopic.AspNetCore.Mvc.Tests/TopicControllerTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public TopicControllerTest() {
7373
RouteData = routes,
7474
ActionDescriptor = new ControllerActionDescriptor()
7575
};
76-
_context = new ControllerContext(actionContext);
76+
_context = new(actionContext);
7777

7878
}
7979

@@ -131,11 +131,11 @@ public void SitemapController_Index_ReturnsSitemapXml() {
131131

132132
var actionContext = new ActionContext {
133133
HttpContext = new DefaultHttpContext(),
134-
RouteData = new RouteData(),
134+
RouteData = new(),
135135
ActionDescriptor = new ControllerActionDescriptor()
136136
};
137137
var controller = new SitemapController(_topicRepository) {
138-
ControllerContext = new ControllerContext(actionContext)
138+
ControllerContext = new(actionContext)
139139
};
140140
var result = controller.Index() as ContentResult;
141141
var model = result.Content as string;

OnTopic.AspNetCore.Mvc.Tests/ValidateTopicAttributeTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static ActionExecutingContext GetActionExecutingContext(Controller contro
4040

4141
var actionContext = new ActionContext(
4242
new DefaultHttpContext(),
43-
new RouteData(),
43+
new(),
4444
new ControllerActionDescriptor(),
4545
modelState
4646
);
@@ -63,10 +63,10 @@ public static ActionExecutingContext GetActionExecutingContext(Controller contro
6363
/// Generates a barebones <see cref="ControllerContext"/> for testing a controller.
6464
/// </summary>
6565
public static ControllerContext GetControllerContext() =>
66-
new ControllerContext(
67-
new ActionContext() {
66+
new(
67+
new() {
6868
HttpContext = new DefaultHttpContext(),
69-
RouteData = new RouteData(),
69+
RouteData = new(),
7070
ActionDescriptor = new ControllerActionDescriptor()
7171
}
7272
);
@@ -78,7 +78,7 @@ public static ControllerContext GetControllerContext() =>
7878
/// Generates a barebones <see cref="ControllerContext"/> for testing a controller.
7979
/// </summary>
8080
public static TopicController GetTopicController(Topic topic) =>
81-
new TopicController(
81+
new(
8282
new DummyTopicRepository(),
8383
new DummyTopicMappingService()
8484
) {

OnTopic.AspNetCore.Mvc/Components/MenuViewComponentBase{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ IHierarchicalTopicMappingService<T> hierarchicalTopicMappingService
102102
await HierarchicalTopicMappingService.GetRootViewModelAsync(
103103
navigationRootTopic!,
104104
3,
105-
t => t.ContentType != "PageGroup"
105+
t => t is not { ContentType: "List" } and not { Parent: { ContentType: "PageGroup" } }
106106
).ConfigureAwait(false);
107107

108108
/*==========================================================================================================================

OnTopic.AspNetCore.Mvc/Components/NavigationTopicViewComponentBase{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ IHierarchicalTopicMappingService<T> hierarchicalTopicMappingService
7777
/// <returns>The Topic associated with the current request.</returns>
7878
protected Topic? CurrentTopic {
7979
get {
80-
if (_currentTopic == null) {
80+
if (_currentTopic is null) {
8181
_currentTopic = TopicRepository.Load(RouteData);
8282
}
8383
return _currentTopic;

OnTopic.AspNetCore.Mvc/Components/PageLevelNavigationViewComponentBase{T}.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ IHierarchicalTopicMappingService<T> hierarchicalTopicMappingService
7474
/*------------------------------------------------------------------------------------------------------------------------
7575
| Identify navigation root
7676
\-----------------------------------------------------------------------------------------------------------------------*/
77-
if (navigationRootTopic != null) {
77+
if (navigationRootTopic is not null) {
7878
while (
79-
navigationRootTopic.Parent != null &&
80-
!navigationRootTopic.ContentType.Equals("PageGroup", StringComparison.InvariantCulture)
79+
navigationRootTopic is not null and not ({ Parent: null } or { ContentType: "PageGroup" })
8180
) {
8281
navigationRootTopic = navigationRootTopic.Parent;
8382
}
@@ -86,7 +85,7 @@ IHierarchicalTopicMappingService<T> hierarchicalTopicMappingService
8685
/*------------------------------------------------------------------------------------------------------------------------
8786
| Return root
8887
\-----------------------------------------------------------------------------------------------------------------------*/
89-
return navigationRootTopic?.Parent == null? null : navigationRootTopic;
88+
return navigationRootTopic?.Parent is null? null : navigationRootTopic;
9089

9190
}
9291

OnTopic.AspNetCore.Mvc/Controllers/RedirectController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public virtual ActionResult Redirect(int topicId) {
5959
/*------------------------------------------------------------------------------------------------------------------------
6060
| Provide error handling
6161
\-----------------------------------------------------------------------------------------------------------------------*/
62-
if (topic == null) {
62+
if (topic is null) {
6363
return NotFound("Invalid TopicID.");
6464
}
6565

OnTopic.AspNetCore.Mvc/Controllers/SitemapController.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public virtual ActionResult Index(bool indent = false, bool includeMetadata = fa
146146
/// <returns>A Sitemap.org sitemap.</returns>
147147
[Obsolete("The GenerateSitemap() method should not be public. It will be marked private in OnTopic Library 5.0.")]
148148
public virtual XDocument GenerateSitemap(Topic rootTopic, bool includeMetadata = false) =>
149-
new XDocument(
149+
new(
150150
new XElement(_sitemapNamespace + "urlset",
151151
from topic in rootTopic?.Children
152152
select AddTopic(topic, includeMetadata)
@@ -172,9 +172,9 @@ public IEnumerable<XElement> AddTopic(Topic topic, bool includeMetadata = false)
172172
/*------------------------------------------------------------------------------------------------------------------------
173173
| Validate topic
174174
\-----------------------------------------------------------------------------------------------------------------------*/
175-
if (topic == null) return topics;
176-
if (topic.Attributes.GetValue("NoIndex") == "1") return topics;
177-
if (topic.Attributes.GetValue("IsDisabled") == "1") return topics;
175+
if (topic is null) return topics;
176+
if (topic.Attributes.GetValue("NoIndex") is "1") return topics;
177+
if (topic.Attributes.GetValue("IsDisabled") is "1") return topics;
178178
if (ExcludeContentTypes.Any(c => topic.ContentType.Equals(c, StringComparison.InvariantCultureIgnoreCase))) return topics;
179179

180180
/*------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)