2 diff areas for the back office so views can be stored in a nice place, updates tests to verify controllers are attributed with correct areas
This commit is contained in:
@@ -53,8 +53,8 @@
|
||||
public static class Mvc
|
||||
{
|
||||
public const string InstallArea = "UmbracoInstall";
|
||||
|
||||
public const string BackOfficeArea = "UmbracoApi";
|
||||
public const string BackOfficeArea = "UmbracoBackOffice"; // Used for area routes of non-api controllers
|
||||
public const string BackOfficeApiArea = "UmbracoApi"; // Same name as v8 so all routing remains the same
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
@@ -63,6 +64,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing
|
||||
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(endpoint3.RoutePattern.Defaults["area"], typeof(PreviewController).GetCustomAttribute<AreaAttribute>(false).RouteValue);
|
||||
|
||||
var endpoint4 = (RouteEndpoint)route.Endpoints[3];
|
||||
var apiControllerName = ControllerExtensions.GetControllerName<Testing1Controller>();
|
||||
@@ -79,13 +81,15 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing
|
||||
Assert.AreEqual(Constants.Web.Mvc.BackOfficeArea, endpoint1.RoutePattern.Defaults["area"]);
|
||||
Assert.AreEqual("Default", endpoint1.RoutePattern.Defaults["action"]);
|
||||
Assert.AreEqual(ControllerExtensions.GetControllerName<BackOfficeController>(), endpoint1.RoutePattern.Defaults["controller"]);
|
||||
Assert.AreEqual(endpoint1.RoutePattern.Defaults["area"], typeof(BackOfficeController).GetCustomAttribute<AreaAttribute>(false).RouteValue);
|
||||
|
||||
var endpoint2 = (RouteEndpoint)route.Endpoints[1];
|
||||
var controllerName = ControllerExtensions.GetControllerName<AuthenticationController>();
|
||||
Assert.AreEqual($"umbraco/backoffice/{Constants.Web.Mvc.BackOfficeArea.ToLowerInvariant()}/{controllerName.ToLowerInvariant()}/{{action}}/{{id?}}", endpoint2.RoutePattern.RawText);
|
||||
Assert.AreEqual(Constants.Web.Mvc.BackOfficeArea, endpoint2.RoutePattern.Defaults["area"]);
|
||||
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<AreaAttribute>(false).RouteValue);
|
||||
}
|
||||
|
||||
private BackOfficeAreaRoutes GetBackOfficeAreaRoutes(RuntimeLevel level)
|
||||
|
||||
@@ -16,14 +16,14 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing
|
||||
[TestFixture]
|
||||
public class EndpointRouteBuilderExtensionsTests
|
||||
{
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeArea, "test", null, true)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeArea, "test", "GetStuff", true)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeArea, null, null, true)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeArea, null, "GetStuff", true)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeArea, "test", null, false)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeArea, "test", "GetStuff", false)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeArea, null, null, false)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeArea, null, "GetStuff", false)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, "test", null, true)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, "test", "GetStuff", true)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, null, null, true)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, null, "GetStuff", true)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, "test", null, false)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, "test", "GetStuff", false)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, null, null, false)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, null, "GetStuff", false)]
|
||||
[TestCase("umbraco", null, "test", null, true)]
|
||||
[TestCase("umbraco", null, "test", "GetStuff", true)]
|
||||
[TestCase("umbraco", null, null, null, true)]
|
||||
@@ -65,10 +65,10 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing
|
||||
Assert.AreEqual(controllerName, endpoint.RoutePattern.Defaults["controller"]);
|
||||
}
|
||||
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeArea, true, null)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeArea, true, "GetStuff")]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeArea, false, null)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeArea, false, "GetStuff")]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, true, null)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, true, "GetStuff")]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, false, null)]
|
||||
[TestCase("umbraco", Constants.Web.Mvc.BackOfficeApiArea, false, "GetStuff")]
|
||||
[TestCase("umbraco", null, true, null)]
|
||||
[TestCase("umbraco", null, true, "GetStuff")]
|
||||
[TestCase("umbraco", null, false, null)]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
@@ -41,12 +42,14 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common.Routing
|
||||
Assert.AreEqual(Constants.Web.Mvc.InstallArea, endpoint1.RoutePattern.Defaults["area"]);
|
||||
Assert.AreEqual("Index", endpoint1.RoutePattern.Defaults["action"]);
|
||||
Assert.AreEqual(ControllerExtensions.GetControllerName<InstallApiController>(), endpoint1.RoutePattern.Defaults["controller"]);
|
||||
Assert.AreEqual(endpoint1.RoutePattern.Defaults["area"], typeof(InstallApiController).GetCustomAttribute<AreaAttribute>(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<InstallController>(), endpoint2.RoutePattern.Defaults["controller"]);
|
||||
Assert.AreEqual(endpoint2.RoutePattern.Defaults["area"], typeof(InstallController).GetCustomAttribute<AreaAttribute>(false).RouteValue);
|
||||
|
||||
var fallbackRoute = endpoints.DataSources.Last();
|
||||
Assert.AreEqual(1, fallbackRoute.Endpoints.Count);
|
||||
|
||||
@@ -5,7 +5,7 @@ using Constants = Umbraco.Core.Constants;
|
||||
|
||||
namespace Umbraco.Web.BackOffice.Controllers
|
||||
{
|
||||
[PluginController(Constants.Web.Mvc.BackOfficeArea)] // TODO: Maybe this could be applied with our Application Model conventions
|
||||
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)] // TODO: Maybe this could be applied with our Application Model conventions
|
||||
//[ValidationFilter] // TODO: I don't actually think this is required with our custom Application Model conventions applied
|
||||
[TypeFilter(typeof(AngularJsonOnlyConfigurationAttribute))] // TODO: This could be applied with our Application Model conventions
|
||||
[IsBackOffice] // TODO: This could be applied with our Application Model conventions
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Umbraco.Web.BackOffice.Routing
|
||||
id = @"[a-zA-Z]*"
|
||||
});
|
||||
|
||||
endpoints.MapUmbracoApiRoute<AuthenticationController>(_umbracoPathSegment, Constants.Web.Mvc.BackOfficeArea, true, defaultAction: string.Empty);
|
||||
endpoints.MapUmbracoApiRoute<AuthenticationController>(_umbracoPathSegment, Constants.Web.Mvc.BackOfficeApiArea, true, defaultAction: string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Umbraco.Extensions
|
||||
return "/"; // this would indicate that the installer is installed without the back office
|
||||
}
|
||||
|
||||
return linkGenerator.GetPathByAction("Default", ControllerExtensions.GetControllerName(backOfficeControllerType), new { area = Constants.Web.Mvc.BackOfficeArea });
|
||||
return linkGenerator.GetPathByAction("Default", ControllerExtensions.GetControllerName(backOfficeControllerType), new { area = Constants.Web.Mvc.BackOfficeApiArea });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Umbraco.Extensions
|
||||
{
|
||||
var backOfficeControllerType = Type.GetType("Umbraco.Web.BackOffice.Controllers");
|
||||
if (backOfficeControllerType == null) return "/"; // this would indicate that the installer is installed without the back office
|
||||
return url.Action("Default", ControllerExtensions.GetControllerName(backOfficeControllerType), new { area = Constants.Web.Mvc.BackOfficeArea });
|
||||
return url.Action("Default", ControllerExtensions.GetControllerName(backOfficeControllerType), new { area = Constants.Web.Mvc.BackOfficeApiArea });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user