Skip to content

Commit 476a695

Browse files
committed
CS8602: Dereference of a possibly null reference
With the tests migrated to .NET 6, we have improved nullability annotations on the core libraries, and thus the tests now recognize that `ViewData` can, potentially, be nullable. As a result, the tests are updated to account for this possibility.
1 parent 6b827de commit 476a695

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

OnTopic.AspNetCore.Mvc.Tests/TopicViewComponentTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public async Task Menu_Invoke_ReturnsNavigationViewModel() {
121121

122122
var result = await viewComponent.InvokeAsync().ConfigureAwait(false);
123123
var concreteResult = result as ViewViewComponentResult;
124-
var model = concreteResult?.ViewData.Model as NavigationViewModel<NavigationTopicViewModel>;
124+
var model = concreteResult?.ViewData?.Model as NavigationViewModel<NavigationTopicViewModel>;
125125

126126
Assert.NotNull(model);
127127
Assert.Equal(_topic.GetWebPath(), model?.CurrentWebPath);
@@ -147,7 +147,7 @@ public async Task Menu_Invoke_ReturnsConfiguredNavigationRoot() {
147147

148148
var result = await viewComponent.InvokeAsync().ConfigureAwait(false);
149149
var concreteResult = result as ViewViewComponentResult;
150-
var model = concreteResult?.ViewData.Model as NavigationViewModel<NavigationTopicViewModel>;
150+
var model = concreteResult?.ViewData?.Model as NavigationViewModel<NavigationTopicViewModel>;
151151

152152
Assert.NotNull(model);
153153
Assert.Equal(webPath, model?.CurrentWebPath);
@@ -194,7 +194,7 @@ public async Task PageLevelNavigation_Invoke_ReturnsNavigationViewModel() {
194194

195195
var result = await viewComponent.InvokeAsync().ConfigureAwait(false);
196196
var concreteResult = result as ViewViewComponentResult;
197-
var model = concreteResult?.ViewData.Model as NavigationViewModel<NavigationTopicViewModel>;
197+
var model = concreteResult?.ViewData?.Model as NavigationViewModel<NavigationTopicViewModel>;
198198

199199
Assert.NotNull(model);
200200
Assert.Equal(_topic.GetWebPath(), model?.CurrentWebPath);
@@ -222,7 +222,7 @@ public async Task PageLevelNavigation_Invoke_ReturnsNull() {
222222

223223
var result = await viewComponent.InvokeAsync().ConfigureAwait(false);
224224
var concreteResult = result as ViewViewComponentResult;
225-
var model = concreteResult?.ViewData.Model as NavigationViewModel<NavigationTopicViewModel>;
225+
var model = concreteResult?.ViewData?.Model as NavigationViewModel<NavigationTopicViewModel>;
226226

227227
Assert.NotNull(model);
228228
Assert.Equal(webPath, model?.CurrentWebPath);
@@ -250,7 +250,7 @@ public async Task PageLevelNavigation_InvokeWithNullTopic_ReturnsNull()
250250

251251
var result = await viewComponent.InvokeAsync().ConfigureAwait(false);
252252
var concreteResult = result as ViewViewComponentResult;
253-
var model = concreteResult?.ViewData.Model as NavigationViewModel<NavigationTopicViewModel>;
253+
var model = concreteResult?.ViewData?.Model as NavigationViewModel<NavigationTopicViewModel>;
254254

255255
Assert.NotNull(model);
256256
Assert.Equal(String.Empty, model?.CurrentWebPath);

0 commit comments

Comments
 (0)