Skip to content

Commit 5eaa417

Browse files
committed
Merge branch 'improvement/C#-10' into develop
Upgraded the project to use both C# 10 as well as the associated .NET 6 code analyzers. Modified code to take advantage of natural types for generics; this was especially useful for XUNit's `Assert.Equal<>()` overloads, which no longer need the type parameter to be set in order to identify the correct overload. Updated type checking statements to prefer `is` and `is not` where practice. This replaced a handful of cases where we were previously using `Equals(typeof())` or even `IsAssignableFrom()`. Implemented new C# 10 constant string interpolation for `[Obsolete()]` attributes, which allows (most) class and member references to use `nameof()` instead of being hardcoded as strings. Fixed a handful of new issues identified by the new code analyzers while I was at it. This resolves Issue #96.
2 parents a82f7e6 + 427959b commit 5eaa417

76 files changed

Lines changed: 361 additions & 318 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.

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4-
<LangVersion>9.0</LangVersion>
4+
<LangVersion>10.0</LangVersion>
55
<Nullable>enable</Nullable>
66
<AnalysisLevel>latest</AnalysisLevel>
77
<AnalysisMode>AllEnabledByDefault</AnalysisMode>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
10+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1313
</PackageReference>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
9+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
1010
<PrivateAssets>all</PrivateAssets>
1111
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1212
</PackageReference>

OnTopic.AspNetCore.Mvc.IntegrationTests/OnTopic.AspNetCore.Mvc.IntegrationTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
9+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
1010
<PrivateAssets>all</PrivateAssets>
1111
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1212
</PackageReference>

OnTopic.AspNetCore.Mvc.IntegrationTests/TopicViewResultExecutorTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public async Task MissingView_ReturnsInternalServerError() {
163163
var uri = new Uri("/Web/MissingView/", UriKind.Relative);
164164
var response = await client.GetAsync(uri).ConfigureAwait(false);
165165

166-
Assert.Equal<HttpStatusCode?>(HttpStatusCode.InternalServerError, response.StatusCode);
166+
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
167167

168168
}
169169

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
9+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
1010
<PrivateAssets>all</PrivateAssets>
1111
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1212
</PackageReference>

OnTopic.AspNetCore.Mvc.Tests/TopicRepositoryExtensionsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void Load_ByRoute_ReturnsTopic() {
6262
var currentTopic = _topicRepository.Load(routes);
6363

6464
Assert.NotNull(currentTopic);
65-
Assert.Equal<Topic?>(topic, currentTopic);
65+
Assert.Equal(topic, currentTopic);
6666
Assert.Equal("Web_0_1_1", currentTopic?.Key);
6767

6868
}
@@ -84,7 +84,7 @@ public void Load_ByRoute_ReturnsRootTopic() {
8484
var currentTopic = _topicRepository.Load(routes);
8585

8686
Assert.NotNull(currentTopic);
87-
Assert.Equal<Topic?>(topic, currentTopic);
87+
Assert.Equal(topic, currentTopic);
8888
Assert.Equal("Root", currentTopic?.Key);
8989

9090
}

OnTopic.AspNetCore.Mvc.Tests/TopicViewComponentTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public async Task Menu_Invoke_ReturnsNavigationViewModel() {
131131
Assert.NotNull(model);
132132
Assert.Equal(_topic.GetWebPath(), model?.CurrentWebPath);
133133
Assert.Equal("/Web/", model?.NavigationRoot?.WebPath);
134-
Assert.Equal<int?>(3, model?.NavigationRoot?.Children.Count);
134+
Assert.Equal(3, model?.NavigationRoot?.Children.Count);
135135

136136
}
137137

@@ -204,7 +204,7 @@ public async Task PageLevelNavigation_Invoke_ReturnsNavigationViewModel() {
204204
Assert.NotNull(model);
205205
Assert.Equal(_topic.GetWebPath(), model?.CurrentWebPath);
206206
Assert.Equal("/Web/Web_3/", model?.NavigationRoot?.WebPath);
207-
Assert.Equal<int?>(2, model?.NavigationRoot?.Children.Count);
207+
Assert.Equal(2, model?.NavigationRoot?.Children.Count);
208208
Assert.True(model?.NavigationRoot?.IsSelected(_topic.GetWebPath())?? false);
209209

210210
}

OnTopic.AspNetCore.Mvc.Tests/ValidateTopicAttributeTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public void NestedTopic_List_Returns403() {
204204
var result = context.Result as StatusCodeResult;
205205

206206
Assert.NotNull(result);
207-
Assert.Equal<int?>(403, result?.StatusCode);
207+
Assert.Equal(403, result?.StatusCode);
208208

209209
}
210210

@@ -231,7 +231,7 @@ public void NestedTopic_Item_Returns403() {
231231
var result = context.Result as StatusCodeResult;
232232

233233
Assert.NotNull(result);
234-
Assert.Equal<int?>(403, result?.StatusCode);
234+
Assert.Equal(403, result?.StatusCode);
235235

236236
}
237237

@@ -257,7 +257,7 @@ public void Container_Returns403() {
257257
var result = context.Result as StatusCodeResult;
258258

259259
Assert.NotNull(result);
260-
Assert.Equal<int?>(403, result?.StatusCode);
260+
Assert.Equal(403, result?.StatusCode);
261261

262262
}
263263

@@ -309,7 +309,7 @@ public void PageGroupTopic_Empty_ReturnsRedirect() {
309309
var result = context.Result as StatusCodeResult;
310310

311311
Assert.NotNull(result);
312-
Assert.Equal<int?>(403, result?.StatusCode);
312+
Assert.Equal(403, result?.StatusCode);
313313

314314
}
315315

OnTopic.AspNetCore.Mvc/Models/NavigationViewModel{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class NavigationViewModel<T> where T : class, IHierarchicalTopicViewModel
7777
/// </summary>
7878
/// <inheritdoc cref="CurrentWebPath"/>
7979
[ExcludeFromCodeCoverage]
80-
[Obsolete("The CurrentKey property has been replaced in favor of CurrentWebPath.", true)]
80+
[Obsolete($"The {nameof(CurrentKey)} property has been replaced in favor of {nameof(CurrentWebPath)}.", true)]
8181
public string CurrentKey { get; set; } = default!;
8282

8383
} //Class

0 commit comments

Comments
 (0)