* Update gitignore * Move csproj * Update project references * Update solutions * Update build scripts * Tests used to share editorconfig with projects in src * Fix broken tests. * Stop copying around .editorconfig merged root one with linting * csharp_style_expression_bodied -> suggestion * Move StyleCop rulesets to matching directories and update shared build properties * Remove legacy build files, update NuGet.cofig and solution files * Restore myget source * Clean up .gitignore * Update .gitignore * Move new test classes to tests after merge * Gitignore + nuget config * Move new test Co-authored-by: Ronald Barendse <ronald@barend.se>
97 lines
3.7 KiB
C#
97 lines
3.7 KiB
C#
using System;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.Cache;
|
|
using Umbraco.Cms.Core.Logging;
|
|
using Umbraco.Cms.Core.Routing;
|
|
using Umbraco.Cms.Core.Services;
|
|
using Umbraco.Cms.Core.Web;
|
|
using Umbraco.Cms.Infrastructure.Persistence;
|
|
using Umbraco.Cms.Tests.Integration.TestServerTest;
|
|
using Umbraco.Cms.Web.Common.Attributes;
|
|
using Umbraco.Cms.Web.Website.Controllers;
|
|
using Umbraco.Extensions;
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Web.Website.Routing
|
|
{
|
|
[TestFixture]
|
|
public class SurfaceControllerTests : UmbracoTestServerTestBase
|
|
{
|
|
[Test]
|
|
public async Task Auto_Routes_For_Default_Action()
|
|
{
|
|
string url = PrepareSurfaceControllerUrl<TestSurfaceController>(x => x.Index());
|
|
|
|
// Act
|
|
HttpResponseMessage response = await Client.GetAsync(url);
|
|
|
|
string body = await response.Content.ReadAsStringAsync();
|
|
|
|
// Assert
|
|
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Auto_Routes_For_Custom_Action()
|
|
{
|
|
string url = PrepareSurfaceControllerUrl<TestSurfaceController>(x => x.News());
|
|
|
|
// Act
|
|
HttpResponseMessage response = await Client.GetAsync(url);
|
|
|
|
string body = await response.Content.ReadAsStringAsync();
|
|
|
|
// Assert
|
|
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Plugin_Controller_Routes_By_Area()
|
|
{
|
|
// Create URL manually, because PrepareSurfaceController URl will prepare whatever the controller is routed as
|
|
Type controllerType = typeof(TestPluginController);
|
|
var pluginAttribute = CustomAttributeExtensions.GetCustomAttribute<PluginControllerAttribute>(controllerType, false);
|
|
var controllerName = ControllerExtensions.GetControllerName(controllerType);
|
|
string url = $"/umbraco/{pluginAttribute?.AreaName}/{controllerName}";
|
|
PrepareUrl(url);
|
|
|
|
HttpResponseMessage response = await Client.GetAsync(url);
|
|
|
|
string body = await response.Content.ReadAsStringAsync();
|
|
|
|
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
}
|
|
}
|
|
|
|
// Test controllers must be non-nested, else we need to jump through some hoops with custom
|
|
// IApplicationFeatureProvider<ControllerFeature>
|
|
// For future notes if we want this, some example code of this is here
|
|
// https://tpodolak.com/blog/2020/06/22/asp-net-core-adding-controllers-directly-integration-tests/
|
|
public class TestSurfaceController : SurfaceController
|
|
{
|
|
public TestSurfaceController(IUmbracoContextAccessor umbracoContextAccessor, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger, IPublishedUrlProvider publishedUrlProvider)
|
|
: base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider)
|
|
{
|
|
}
|
|
|
|
public IActionResult Index() => Ok();
|
|
|
|
public IActionResult News() => NoContent();
|
|
}
|
|
|
|
[PluginController("TestArea")]
|
|
public class TestPluginController : SurfaceController
|
|
{
|
|
public TestPluginController(IUmbracoContextAccessor umbracoContextAccessor, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger, IPublishedUrlProvider publishedUrlProvider) : base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider)
|
|
{
|
|
}
|
|
|
|
public IActionResult Index() => Ok();
|
|
}
|
|
}
|