From b883ebfd7d5741cf284c17941cd495e5f02618b1 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 5 Feb 2021 13:14:24 +1100 Subject: [PATCH] Fixing tests, created constants --- src/Umbraco.Core/Constants-Web.cs | 9 ++- .../Routing/BackOfficeAreaRoutesTests.cs | 23 +++--- .../EndpointRouteBuilderExtensionsTests.cs | 9 +-- .../Routing/InstallAreaRoutesTests.cs | 17 ++--- .../Routing/PreviewRoutesTests.cs | 5 +- .../Routing/ControllerActionSearcherTests.cs | 70 ++++++++----------- .../UmbracoRouteValueTransformerTests.cs | 9 +-- .../Trees/ApplicationTreeController.cs | 5 +- .../Macros/PartialViewMacroEngine.cs | 5 +- .../ActionResults/UmbracoPageResult.cs | 5 +- .../Routing/ControllerActionSearcher.cs | 7 +- .../Routing/UmbracoRouteValueTransformer.cs | 4 +- .../WebApi/NamespaceHttpControllerSelector.cs | 5 +- 13 files changed, 87 insertions(+), 86 deletions(-) diff --git a/src/Umbraco.Core/Constants-Web.cs b/src/Umbraco.Core/Constants-Web.cs index 6d98a86580..d63106daf6 100644 --- a/src/Umbraco.Core/Constants-Web.cs +++ b/src/Umbraco.Core/Constants-Web.cs @@ -11,8 +11,8 @@ namespace Umbraco.Core /// The preview cookie name /// public const string PreviewCookieName = "UMB_PREVIEW"; - /// + /// /// Client-side cookie that determines whether the user has accepted to be in Preview Mode when visiting the website. /// public const string AcceptPreviewCookieName = "UMB-WEBSITE-PREVIEW-ACCEPT"; @@ -52,6 +52,13 @@ namespace Umbraco.Core public const string BackOfficeApiArea = "UmbracoApi"; // Same name as v8 so all routing remains the same public const string BackOfficeTreeArea = "UmbracoTrees"; // Same name as v8 so all routing remains the same } + + public static class Routing + { + public const string ControllerToken = "controller"; + public const string ActionToken = "action"; + public const string AreaToken = "area"; + } } } } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/BackOfficeAreaRoutesTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/BackOfficeAreaRoutesTests.cs index e221e88dd1..f501305b67 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/BackOfficeAreaRoutesTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/BackOfficeAreaRoutesTests.cs @@ -17,6 +17,7 @@ using Umbraco.Web.Common.Attributes; using Umbraco.Web.Common.Controllers; using Umbraco.Web.WebApi; using Constants = Umbraco.Core.Constants; +using static Umbraco.Core.Constants.Web.Routing; namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing { @@ -65,27 +66,27 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing var endpoint4 = (RouteEndpoint)route.Endpoints[2]; string apiControllerName = ControllerExtensions.GetControllerName(); Assert.AreEqual($"umbraco/backoffice/api/{apiControllerName.ToLowerInvariant()}/{{action}}/{{id?}}", endpoint4.RoutePattern.RawText); - Assert.IsFalse(endpoint4.RoutePattern.Defaults.ContainsKey("area")); - Assert.IsFalse(endpoint4.RoutePattern.Defaults.ContainsKey("action")); - Assert.AreEqual(apiControllerName, endpoint4.RoutePattern.Defaults["controller"]); + Assert.IsFalse(endpoint4.RoutePattern.Defaults.ContainsKey(AreaToken)); + Assert.IsFalse(endpoint4.RoutePattern.Defaults.ContainsKey(ActionToken)); + Assert.AreEqual(apiControllerName, endpoint4.RoutePattern.Defaults[ControllerToken]); } private void AssertMinimalBackOfficeRoutes(EndpointDataSource route) { var endpoint1 = (RouteEndpoint)route.Endpoints[0]; Assert.AreEqual($"umbraco/{{action}}/{{id?}}", endpoint1.RoutePattern.RawText); - Assert.AreEqual(Constants.Web.Mvc.BackOfficeArea, endpoint1.RoutePattern.Defaults["area"]); - Assert.AreEqual("Default", endpoint1.RoutePattern.Defaults["action"]); - Assert.AreEqual(ControllerExtensions.GetControllerName(), endpoint1.RoutePattern.Defaults["controller"]); - Assert.AreEqual(endpoint1.RoutePattern.Defaults["area"], typeof(BackOfficeController).GetCustomAttribute(false).RouteValue); + Assert.AreEqual(Constants.Web.Mvc.BackOfficeArea, endpoint1.RoutePattern.Defaults[AreaToken]); + Assert.AreEqual("Default", endpoint1.RoutePattern.Defaults[ActionToken]); + Assert.AreEqual(ControllerExtensions.GetControllerName(), endpoint1.RoutePattern.Defaults[ControllerToken]); + Assert.AreEqual(endpoint1.RoutePattern.Defaults[AreaToken], typeof(BackOfficeController).GetCustomAttribute(false).RouteValue); var endpoint2 = (RouteEndpoint)route.Endpoints[1]; string controllerName = ControllerExtensions.GetControllerName(); Assert.AreEqual($"umbraco/backoffice/{Constants.Web.Mvc.BackOfficeApiArea.ToLowerInvariant()}/{controllerName.ToLowerInvariant()}/{{action}}/{{id?}}", endpoint2.RoutePattern.RawText); - Assert.AreEqual(Constants.Web.Mvc.BackOfficeApiArea, endpoint2.RoutePattern.Defaults["area"]); - Assert.IsFalse(endpoint2.RoutePattern.Defaults.ContainsKey("action")); - Assert.AreEqual(controllerName, endpoint2.RoutePattern.Defaults["controller"]); - Assert.AreEqual(endpoint1.RoutePattern.Defaults["area"], typeof(BackOfficeController).GetCustomAttribute(false).RouteValue); + Assert.AreEqual(Constants.Web.Mvc.BackOfficeApiArea, endpoint2.RoutePattern.Defaults[AreaToken]); + Assert.IsFalse(endpoint2.RoutePattern.Defaults.ContainsKey(ActionToken)); + Assert.AreEqual(controllerName, endpoint2.RoutePattern.Defaults[ControllerToken]); + Assert.AreEqual(endpoint1.RoutePattern.Defaults[AreaToken], typeof(BackOfficeController).GetCustomAttribute(false).RouteValue); } private BackOfficeAreaRoutes GetBackOfficeAreaRoutes(RuntimeLevel level) diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/EndpointRouteBuilderExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/EndpointRouteBuilderExtensionsTests.cs index 0990cb9d9a..062e0f079d 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/EndpointRouteBuilderExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/EndpointRouteBuilderExtensionsTests.cs @@ -9,6 +9,7 @@ using Umbraco.Core; using Umbraco.Extensions; using Umbraco.Web.Common.Extensions; using Constants = Umbraco.Core.Constants; +using static Umbraco.Core.Constants.Web.Routing; namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing { @@ -67,7 +68,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing if (!area.IsNullOrWhiteSpace()) { - Assert.AreEqual(area, endpoint.RoutePattern.Defaults["area"]); + Assert.AreEqual(area, endpoint.RoutePattern.Defaults[AreaToken]); } if (!defaultAction.IsNullOrWhiteSpace()) @@ -75,7 +76,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing Assert.AreEqual(defaultAction, endpoint.RoutePattern.Defaults["action"]); } - Assert.AreEqual(controllerName, endpoint.RoutePattern.Defaults["controller"]); + Assert.AreEqual(controllerName, endpoint.RoutePattern.Defaults[ControllerToken]); } [TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, true, null)] @@ -123,7 +124,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing if (!area.IsNullOrWhiteSpace()) { - Assert.AreEqual(area, endpoint.RoutePattern.Defaults["area"]); + Assert.AreEqual(area, endpoint.RoutePattern.Defaults[AreaToken]); } if (!defaultAction.IsNullOrWhiteSpace()) @@ -131,7 +132,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing Assert.AreEqual(defaultAction, endpoint.RoutePattern.Defaults["action"]); } - Assert.AreEqual(controllerName, endpoint.RoutePattern.Defaults["controller"]); + Assert.AreEqual(controllerName, endpoint.RoutePattern.Defaults[ControllerToken]); } private class Testing1Controller : ControllerBase diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/InstallAreaRoutesTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/InstallAreaRoutesTests.cs index 74671f819a..c32d54e072 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/InstallAreaRoutesTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/InstallAreaRoutesTests.cs @@ -10,6 +10,7 @@ using Umbraco.Core; using Umbraco.Core.Hosting; using Umbraco.Extensions; using Umbraco.Web.Common.Install; +using static Umbraco.Core.Constants.Web.Routing; namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing { @@ -42,17 +43,17 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing var endpoint1 = (RouteEndpoint)route.Endpoints[0]; Assert.AreEqual($"install/api/{{action}}/{{id?}}", endpoint1.RoutePattern.RawText); - Assert.AreEqual(Constants.Web.Mvc.InstallArea, endpoint1.RoutePattern.Defaults["area"]); - Assert.AreEqual("Index", endpoint1.RoutePattern.Defaults["action"]); - Assert.AreEqual(ControllerExtensions.GetControllerName(), endpoint1.RoutePattern.Defaults["controller"]); - Assert.AreEqual(endpoint1.RoutePattern.Defaults["area"], typeof(InstallApiController).GetCustomAttribute(false).RouteValue); + Assert.AreEqual(Constants.Web.Mvc.InstallArea, endpoint1.RoutePattern.Defaults[AreaToken]); + Assert.AreEqual("Index", endpoint1.RoutePattern.Defaults[ActionToken]); + Assert.AreEqual(ControllerExtensions.GetControllerName(), endpoint1.RoutePattern.Defaults[ControllerToken]); + Assert.AreEqual(endpoint1.RoutePattern.Defaults[AreaToken], typeof(InstallApiController).GetCustomAttribute(false).RouteValue); var endpoint2 = (RouteEndpoint)route.Endpoints[1]; Assert.AreEqual($"install/{{action}}/{{id?}}", endpoint2.RoutePattern.RawText); - Assert.AreEqual(Constants.Web.Mvc.InstallArea, endpoint2.RoutePattern.Defaults["area"]); - Assert.AreEqual("Index", endpoint2.RoutePattern.Defaults["action"]); - Assert.AreEqual(ControllerExtensions.GetControllerName(), endpoint2.RoutePattern.Defaults["controller"]); - Assert.AreEqual(endpoint2.RoutePattern.Defaults["area"], typeof(InstallController).GetCustomAttribute(false).RouteValue); + Assert.AreEqual(Constants.Web.Mvc.InstallArea, endpoint2.RoutePattern.Defaults[AreaToken]); + Assert.AreEqual("Index", endpoint2.RoutePattern.Defaults[ActionToken]); + Assert.AreEqual(ControllerExtensions.GetControllerName(), endpoint2.RoutePattern.Defaults[ControllerToken]); + Assert.AreEqual(endpoint2.RoutePattern.Defaults[AreaToken], typeof(InstallController).GetCustomAttribute(false).RouteValue); EndpointDataSource fallbackRoute = endpoints.DataSources.Last(); Assert.AreEqual(1, fallbackRoute.Endpoints.Count); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/PreviewRoutesTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/PreviewRoutesTests.cs index 32d4f41f8a..82e5628c3a 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/PreviewRoutesTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/PreviewRoutesTests.cs @@ -14,6 +14,7 @@ using Umbraco.Extensions; using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.BackOffice.Routing; using Constants = Umbraco.Core.Constants; +using static Umbraco.Core.Constants.Web.Routing; namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing { @@ -54,8 +55,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing var previewControllerName = ControllerExtensions.GetControllerName(); Assert.AreEqual($"umbraco/{previewControllerName.ToLowerInvariant()}/{{action}}/{{id?}}", endpoint3.RoutePattern.RawText); Assert.AreEqual(Constants.Web.Mvc.BackOfficeArea, endpoint3.RoutePattern.Defaults["area"]); - Assert.AreEqual("Index", endpoint3.RoutePattern.Defaults["action"]); - Assert.AreEqual(previewControllerName, endpoint3.RoutePattern.Defaults["controller"]); + Assert.AreEqual("Index", endpoint3.RoutePattern.Defaults[ActionToken]); + Assert.AreEqual(previewControllerName, endpoint3.RoutePattern.Defaults[ControllerToken]); Assert.AreEqual(endpoint3.RoutePattern.Defaults["area"], typeof(PreviewController).GetCustomAttribute(false).RouteValue); } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/ControllerActionSearcherTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/ControllerActionSearcherTests.cs index 3437091663..d5d3b3e26b 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/ControllerActionSearcherTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/ControllerActionSearcherTests.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ViewEngines; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -18,6 +19,7 @@ using Umbraco.Extensions; using Umbraco.Web; using Umbraco.Web.Common.Controllers; using Umbraco.Web.Website.Routing; +using static Umbraco.Core.Constants.Web.Routing; namespace Umbraco.Tests.UnitTests.Umbraco.Web.Website.Routing { @@ -25,45 +27,22 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Website.Routing [TestFixture] public class ControllerActionSearcherTests { - private class TestActionDescriptorCollectionProvider : ActionDescriptorCollectionProvider - { - private readonly IEnumerable _actions; - - public TestActionDescriptorCollectionProvider(IEnumerable actions) => _actions = actions; - - public override ActionDescriptorCollection ActionDescriptors => new ActionDescriptorCollection(_actions.ToList(), 1); - - public override IChangeToken GetChangeToken() => NullChangeToken.Singleton; - } - - private IActionDescriptorCollectionProvider GetActionDescriptors() => new TestActionDescriptorCollectionProvider( - new ActionDescriptor[] + private ControllerActionDescriptor GetDescriptor(string action) + => new ControllerActionDescriptor { - new ControllerActionDescriptor - { - ActionName = "Index", - ControllerName = ControllerExtensions.GetControllerName(), - ControllerTypeInfo = typeof(RenderController).GetTypeInfo() - }, - new ControllerActionDescriptor - { - ActionName = "Index", - ControllerName = ControllerExtensions.GetControllerName(), - ControllerTypeInfo = typeof(Render1Controller).GetTypeInfo() - }, - new ControllerActionDescriptor - { - ActionName = "Custom", - ControllerName = ControllerExtensions.GetControllerName(), - ControllerTypeInfo = typeof(Render1Controller).GetTypeInfo() - }, - new ControllerActionDescriptor - { - ActionName = "Index", - ControllerName = ControllerExtensions.GetControllerName(), - ControllerTypeInfo = typeof(Render2Controller).GetTypeInfo() - } - }); + ActionName = action, + ControllerName = ControllerExtensions.GetControllerName(), + ControllerTypeInfo = typeof(RenderController).GetTypeInfo(), + DisplayName = $"{ControllerExtensions.GetControllerName()}.{action}" + }; + + private IReadOnlyList GetActionDescriptors() => new List + { + GetDescriptor(nameof(RenderController.Index)), + GetDescriptor(nameof(Render1Controller.Index)), + GetDescriptor(nameof(Render1Controller.Custom)), + GetDescriptor(nameof(Render2Controller.Index)) + }; private class Render1Controller : ControllerBase, IRenderController { @@ -90,14 +69,21 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Website.Routing [TestCase("Custom", "Render1", nameof(Render1Controller.Custom), true)] public void Matches_Controller(string action, string controller, string resultAction, bool matches) { - IActionDescriptorCollectionProvider descriptors = GetActionDescriptors(); + IReadOnlyList descriptors = GetActionDescriptors(); - // TODO: Mock this more so that these tests work - IActionSelector actionSelector = Mock.Of(); + var actionSelector = new Mock(); + actionSelector.Setup(x => x.SelectCandidates(It.IsAny())) + .Returns((RouteContext r) => + { + // our own rudimentary search + var controller = r.RouteData.Values[ControllerToken].ToString(); + var action = r.RouteData.Values[ActionToken].ToString(); + return descriptors.Where(x => x.ControllerName.InvariantEquals(controller) && x.ActionName.InvariantEquals(action)).ToList(); + }); var query = new ControllerActionSearcher( new NullLogger(), - actionSelector); + actionSelector.Object); var httpContext = new DefaultHttpContext(); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformerTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformerTests.cs index 61918558ac..a47d3acb20 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformerTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformerTests.cs @@ -22,6 +22,7 @@ using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Website.Controllers; using Umbraco.Web.Website.Routing; +using static Umbraco.Core.Constants.Web.Routing; namespace Umbraco.Tests.UnitTests.Umbraco.Web.Website.Routing { @@ -129,8 +130,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Website.Routing RouteValueDictionary result = await transformer.TransformAsync(new DefaultHttpContext(), new RouteValueDictionary()); Assert.AreEqual(2, result.Count); - Assert.AreEqual(ControllerExtensions.GetControllerName(), result["controller"]); - Assert.AreEqual(nameof(RenderNoContentController.Index), result["action"]); + Assert.AreEqual(ControllerExtensions.GetControllerName(), result[ControllerToken]); + Assert.AreEqual(nameof(RenderNoContentController.Index), result[ActionToken]); } [Test] @@ -181,8 +182,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Website.Routing RouteValueDictionary result = await transformer.TransformAsync(new DefaultHttpContext(), new RouteValueDictionary()); - Assert.AreEqual(routeValues.ControllerName, result["controller"]); - Assert.AreEqual(routeValues.ActionName, result["action"]); + Assert.AreEqual(routeValues.ControllerName, result[ControllerToken]); + Assert.AreEqual(routeValues.ActionName, result[ActionToken]); } private class TestController : RenderController diff --git a/src/Umbraco.Web.BackOffice/Trees/ApplicationTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/ApplicationTreeController.cs index 22667f0c30..ec90965455 100644 --- a/src/Umbraco.Web.BackOffice/Trees/ApplicationTreeController.cs +++ b/src/Umbraco.Web.BackOffice/Trees/ApplicationTreeController.cs @@ -18,6 +18,7 @@ using Umbraco.Web.Common.ModelBinders; using Umbraco.Web.Models.Trees; using Umbraco.Web.Services; using Umbraco.Web.Trees; +using static Umbraco.Core.Constants.Web.Routing; namespace Umbraco.Web.BackOffice.Trees { @@ -302,8 +303,8 @@ namespace Umbraco.Web.BackOffice.Trees // create proxy route data specifying the action & controller to execute var routeData = new RouteData(new RouteValueDictionary() { - ["action"] = action, - ["controller"] = controllerName + [ActionToken] = action, + [ControllerToken] = controllerName }); if (!(querystring is null)) { diff --git a/src/Umbraco.Web.Common/Macros/PartialViewMacroEngine.cs b/src/Umbraco.Web.Common/Macros/PartialViewMacroEngine.cs index 790e437148..051f545293 100644 --- a/src/Umbraco.Web.Common/Macros/PartialViewMacroEngine.cs +++ b/src/Umbraco.Web.Common/Macros/PartialViewMacroEngine.cs @@ -17,6 +17,7 @@ using Umbraco.Core.Hosting; using Umbraco.Core.Models.PublishedContent; using Umbraco.Extensions; using Umbraco.Web.Macros; +using static Umbraco.Core.Constants.Web.Routing; namespace Umbraco.Web.Common.Macros { @@ -87,8 +88,8 @@ namespace Umbraco.Web.Common.Macros var httpContext = _httpContextAccessor.GetRequiredHttpContext(); //var umbCtx = _getUmbracoContext(); var routeVals = new RouteData(); - routeVals.Values.Add("controller", "PartialViewMacro"); - routeVals.Values.Add("action", "Index"); + routeVals.Values.Add(ControllerToken, "PartialViewMacro"); + routeVals.Values.Add(ActionToken, "Index"); //TODO: Was required for UmbracoViewPage need to figure out if we still need that, i really don't think this is necessary //routeVals.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx); diff --git a/src/Umbraco.Web.Website/ActionResults/UmbracoPageResult.cs b/src/Umbraco.Web.Website/ActionResults/UmbracoPageResult.cs index c2b3a1221b..90478c3c89 100644 --- a/src/Umbraco.Web.Website/ActionResults/UmbracoPageResult.cs +++ b/src/Umbraco.Web.Website/ActionResults/UmbracoPageResult.cs @@ -9,6 +9,7 @@ using Umbraco.Core.Logging; using Umbraco.Web.Common.Routing; using Umbraco.Web.Website.Controllers; using Umbraco.Web.Website.Routing; +using static Umbraco.Core.Constants.Web.Routing; namespace Umbraco.Web.Website.ActionResults { @@ -39,8 +40,8 @@ namespace Umbraco.Web.Website.ActionResults } // Change the route values back to the original request vals - context.RouteData.Values[UmbracoRouteValueTransformer.ControllerToken] = umbracoRouteValues.ControllerName; - context.RouteData.Values[UmbracoRouteValueTransformer.ActionToken] = umbracoRouteValues.ActionName; + context.RouteData.Values[ControllerToken] = umbracoRouteValues.ControllerName; + context.RouteData.Values[ActionToken] = umbracoRouteValues.ActionName; // Create a new context and excute the original controller... // Copy the action context - this also copies the ModelState diff --git a/src/Umbraco.Web.Website/Routing/ControllerActionSearcher.cs b/src/Umbraco.Web.Website/Routing/ControllerActionSearcher.cs index 81b09cf3a3..2af0e5362f 100644 --- a/src/Umbraco.Web.Website/Routing/ControllerActionSearcher.cs +++ b/src/Umbraco.Web.Website/Routing/ControllerActionSearcher.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Logging; using Umbraco.Core.Composing; using Umbraco.Web.Common.Controllers; +using static Umbraco.Core.Constants.Web.Routing; namespace Umbraco.Web.Website.Routing { @@ -58,8 +59,8 @@ namespace Umbraco.Web.Website.Routing // Use aspnetcore's IActionSelector to do the finding since it uses an optimized cache lookup var routeValues = new RouteValueDictionary { - [UmbracoRouteValueTransformer.ControllerToken] = customControllerName, - [UmbracoRouteValueTransformer.ActionToken] = customActionName, // first try to find the custom action + [ControllerToken] = customControllerName, + [ActionToken] = customActionName, // first try to find the custom action }; var routeData = new RouteData(routeValues); var routeContext = new RouteContext(httpContext) @@ -80,7 +81,7 @@ namespace Umbraco.Web.Website.Routing } // now find for the default action since we couldn't find the custom one - routeValues[UmbracoRouteValueTransformer.ActionToken] = defaultActionName; + routeValues[ActionToken] = defaultActionName; candidates = _actionSelector.SelectCandidates(routeContext) .Cast() .Where(x => TypeHelper.IsTypeAssignableFrom(x.ControllerTypeInfo)) diff --git a/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs b/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs index 2ee9288a60..7d0837b4eb 100644 --- a/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs +++ b/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs @@ -20,6 +20,7 @@ using Umbraco.Web.Common.Routing; using Umbraco.Web.Common.Security; using Umbraco.Web.Routing; using Umbraco.Web.Website.Controllers; +using static Umbraco.Core.Constants.Web.Routing; using RouteDirection = Umbraco.Web.Routing.RouteDirection; namespace Umbraco.Web.Website.Routing @@ -47,9 +48,6 @@ namespace Umbraco.Web.Website.Routing private readonly IDataProtectionProvider _dataProtectionProvider; private readonly IControllerActionSearcher _controllerActionSearcher; - internal const string ControllerToken = "controller"; - internal const string ActionToken = "action"; - /// /// Initializes a new instance of the class. /// diff --git a/src/Umbraco.Web/WebApi/NamespaceHttpControllerSelector.cs b/src/Umbraco.Web/WebApi/NamespaceHttpControllerSelector.cs index d27ec6e91f..b9539a0520 100644 --- a/src/Umbraco.Web/WebApi/NamespaceHttpControllerSelector.cs +++ b/src/Umbraco.Web/WebApi/NamespaceHttpControllerSelector.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; @@ -7,12 +7,13 @@ using System.Net.Http; using System.Web.Http; using System.Web.Http.Controllers; using System.Web.Http.Dispatcher; +using static Umbraco.Core.Constants.Web.Routing; namespace Umbraco.Web.WebApi { public class NamespaceHttpControllerSelector : DefaultHttpControllerSelector { - private const string ControllerKey = "controller"; + private const string ControllerKey = ControllerToken; private readonly HttpConfiguration _configuration; private readonly Lazy> _duplicateControllerTypes;