Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Web.Website/Routing/FrontEndRouteTests.cs
Sven Geusens c8e054baa2 V10/feature/pipeline test filters (#14766)
* Add configuration/code to not run certain tests based on variables/release builds

* Applied longrunning testAttribute to the worst offenders (>200ms on my machine)

* Fix yaml notation

* split up windows/non windows test runs

* Added supression for moved tests

* Fix yaml validation issues

* Change yaml string parameter null value to empty string

* Convert empty strings to whitespace strings

* Rename and cleanup some paramater to better reflect why we use them

* Nightly build test

* Change nightly build authentication type

* template paramater fix

* Update nightly pipeline name

---------

Co-authored-by: Sven Geusens <sge@umbraco.dk>
2023-09-12 14:16:27 +02:00

121 lines
3.7 KiB
C#

using System.Net;
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.Common.Attributes;
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()
{
var url = PrepareSurfaceControllerUrl<TestSurfaceController>(x => x.Index());
// Act
var response = await Client.GetAsync(url);
var body = await response.Content.ReadAsStringAsync();
// Assert
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
}
[Test]
public async Task Auto_Routes_For_Custom_Action()
{
var url = PrepareSurfaceControllerUrl<TestSurfaceController>(x => x.News());
// Act
var response = await Client.GetAsync(url);
var body = await response.Content.ReadAsStringAsync();
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[Test]
[LongRunning]
public async Task Plugin_Controller_Routes_By_Area()
{
// Create URL manually, because PrepareSurfaceController URl will prepare whatever the controller is routed as
var controllerType = typeof(TestPluginController);
var pluginAttribute =
CustomAttributeExtensions.GetCustomAttribute<PluginControllerAttribute>(controllerType, false);
var controllerName = ControllerExtensions.GetControllerName(controllerType);
var url = $"/umbraco/{pluginAttribute?.AreaName}/{controllerName}";
PrepareUrl(url);
var response = await Client.GetAsync(url);
var 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();
}