Skip to content

Commit 8fd4d80

Browse files
committed
Replace CurrentKey with CurrentWebPath
This is a more logical comparison since, in practice, navigation fundamentally operates against web paths. This includes updating the unit tests to compare against `GetWebPath()` instead of `GetUniqueKey()`.
1 parent 44f66bf commit 8fd4d80

4 files changed

Lines changed: 13 additions & 12 deletions

File tree

OnTopic.AspNetCore.Mvc.Tests/TopicViewComponentTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ public async Task Menu_Invoke_ReturnsNavigationViewModel() {
114114
var model = concreteResult?.ViewData.Model as NavigationViewModel<NavigationTopicViewModel>;
115115

116116
Assert.IsNotNull(model);
117-
Assert.AreEqual<string?>(_topic.GetUniqueKey(), model?.CurrentKey);
118-
Assert.AreEqual<string?>("Root:Web", model?.NavigationRoot?.UniqueKey);
117+
Assert.AreEqual<string?>(_topic.GetUniqueKey(), model?.CurrentWebPath);
118+
Assert.AreEqual<string?>("/Web/", model?.NavigationRoot?.WebPath);
119119
Assert.AreEqual<int?>(3, model?.NavigationRoot?.Children.Count);
120-
Assert.IsTrue(model?.NavigationRoot?.IsSelected(_topic.GetUniqueKey())?? false);
120+
Assert.IsTrue(model?.NavigationRoot?.IsSelected(_topic.GetWebPath())?? false);
121121

122122
}
123123

@@ -139,10 +139,10 @@ public async Task PageLevelNavigation_Invoke_ReturnsNavigationViewModel() {
139139
var model = concreteResult?.ViewData.Model as NavigationViewModel<NavigationTopicViewModel>;
140140

141141
Assert.IsNotNull(model);
142-
Assert.AreEqual<string?>(_topic.GetUniqueKey(), model?.CurrentKey);
143-
Assert.AreEqual<string?>("Root:Web:Web_3", model?.NavigationRoot?.UniqueKey);
142+
Assert.AreEqual<string?>(_topic.GetUniqueKey(), model?.CurrentWebPath);
143+
Assert.AreEqual<string?>("/Web/Web_3/", model?.NavigationRoot?.WebPath);
144144
Assert.AreEqual<int?>(2, model?.NavigationRoot?.Children.Count);
145-
Assert.IsTrue(model?.NavigationRoot?.IsSelected(_topic.GetUniqueKey())?? false);
145+
Assert.IsTrue(model?.NavigationRoot?.IsSelected(_topic.GetWebPath())?? false);
146146

147147
}
148148

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public async Task<IViewComponentResult> InvokeAsync() {
124124
\-----------------------------------------------------------------------------------------------------------------------*/
125125
var navigationViewModel = new NavigationViewModel<T>() {
126126
NavigationRoot = await MapNavigationTopicViewModels(navigationRootTopic).ConfigureAwait(true),
127-
CurrentKey = CurrentTopic?.GetUniqueKey()?? HttpContext.Request.Path
127+
CurrentWebPath = CurrentTopic?.GetUniqueKey()?? HttpContext.Request.Path
128128
};
129129

130130
/*------------------------------------------------------------------------------------------------------------------------

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public async Task<IViewComponentResult> InvokeAsync() {
119119
\-----------------------------------------------------------------------------------------------------------------------*/
120120
var navigationViewModel = new NavigationViewModel<T>() {
121121
NavigationRoot = await MapNavigationTopicViewModels(navigationRootTopic).ConfigureAwait(true),
122-
CurrentKey = CurrentTopic?.GetUniqueKey()?? HttpContext.Request.Path
122+
CurrentWebPath = CurrentTopic?.GetUniqueKey()?? HttpContext.Request.Path
123123
};
124124

125125
/*------------------------------------------------------------------------------------------------------------------------

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ public class NavigationViewModel<T> where T : class, INavigationTopicViewModel<T
4545
public T? NavigationRoot { get; set; }
4646

4747
/*==========================================================================================================================
48-
| CURRENT KEY
48+
| CURRENT WEB PATH
4949
\-------------------------------------------------------------------------------------------------------------------------*/
5050
/// <summary>
51-
/// The <see cref="Topic.GetUniqueKey()"/> representing the path to the current <see cref="Topic"/>.
51+
/// The <see cref="Topic.GetWebPath()"/> representing the path to the current <see cref="Topic"/>.
5252
/// </summary>
5353
/// <remarks>
5454
/// <para>
5555
/// In order to determine whether any given <see cref="INavigationTopicViewModel{T}.IsSelected(String)"/>, the views
56-
/// will need to know where in the hierarchy the user currently is. By storing this on the <see
57-
/// cref="NavigationViewModel{T}"/> used as the root view model for every navigation component, we ensure that the views
56+
/// will need to know where in the hierarchy the user currently is. By storing this on the <see cref="
57+
/// NavigationViewModel{T}"/> used as the root view model for every navigation component, we ensure that the views
5858
/// always have access to this information.
5959
/// </para>
6060
/// <para>
@@ -63,6 +63,7 @@ public class NavigationViewModel<T> where T : class, INavigationTopicViewModel<T
6363
/// and maintaining state exclusively in the <see cref="NavigationViewModel{T}"/> itself.
6464
/// </para>
6565
/// </remarks>
66+
public string CurrentWebPath { get; set; } = default!;
6667
public string CurrentKey { get; set; } = default!;
6768

6869
} //Class

0 commit comments

Comments
 (0)