From 5e42cca2fab63c051be3a5c6104b8dce8add852c Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 18 Oct 2022 12:47:51 -0700 Subject: [PATCH] Improve MapGroup link generation test (#44562) --- src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsTest.cs | 3 ++- src/Mvc/test/Mvc.FunctionalTests/RoutingTestsBase.cs | 4 ++-- .../test/WebSites/RoutingWebSite/Pages/PageWithLinks.cshtml | 2 +- src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsTest.cs index f9bab6bd2ddd..ca737c206799 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsTest.cs @@ -46,8 +46,9 @@ public async Task MatchesPagesGroupAndGeneratesValidLink() var document = await response.GetHtmlDocumentAsync(); var editLink = document.RequiredQuerySelector("#editlink"); + var contactLink = document.RequiredQuerySelector("#contactlink"); Assert.Equal("/pages/Edit/10", editLink.GetAttribute("href")); - // TODO: Investigate why the #contactlink to the controller is empty. + Assert.Equal("/controllers/contoso/Home/Contact", contactLink.GetAttribute("href")); } private record RouteInfo(string RouteName, IDictionary RouteValues, string Link); diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingTestsBase.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingTestsBase.cs index 85ad64281b20..9b50c6e3485a 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingTestsBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingTestsBase.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; @@ -1554,7 +1554,7 @@ public async Task RazorPage_WithLinks_GeneratesLinksCorrectly() Assert.Equal("/Edit/10", editLink.GetAttribute("href")); var contactLink = document.RequiredQuerySelector("#contactlink"); - Assert.Equal("/Home/Contact", contactLink.GetAttribute("href")); + Assert.Equal("/Home/Contact?org=contoso", contactLink.GetAttribute("href")); } [Fact] diff --git a/src/Mvc/test/WebSites/RoutingWebSite/Pages/PageWithLinks.cshtml b/src/Mvc/test/WebSites/RoutingWebSite/Pages/PageWithLinks.cshtml index 660d9443f492..58ad2c424389 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/Pages/PageWithLinks.cshtml +++ b/src/Mvc/test/WebSites/RoutingWebSite/Pages/PageWithLinks.cshtml @@ -5,4 +5,4 @@ Edit
-Contact +Contact diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs index 24eb14cb90cc..889c18b40f7a 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs @@ -29,7 +29,7 @@ public virtual void Configure(IApplicationBuilder app) pagesGroup.MapRazorPages(); var controllerGroup = endpoints.MapGroup("/controllers/{org}"); - controllerGroup.MapControllers(); + controllerGroup.MapControllerRoute(name: "default", pattern: "{controller}/{action}/{id?}"); }); } }