Move test projects from src/ to tests/ (#11357)

* 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>
This commit is contained in:
Paul Johnson
2021-10-18 08:14:04 +01:00
committed by GitHub
parent c005673a96
commit 00133e880d
752 changed files with 650 additions and 1844 deletions

View File

@@ -0,0 +1,86 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.BackOffice.Install;
using Umbraco.Extensions;
using static Umbraco.Cms.Core.Constants.Web.Routing;
using Constants = Umbraco.Cms.Core.Constants;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.Routing
{
[TestFixture]
public class InstallAreaRoutesTests
{
[TestCase(RuntimeLevel.BootFailed)]
[TestCase(RuntimeLevel.Unknown)]
[TestCase(RuntimeLevel.Boot)]
public void RuntimeState_No_Routes(RuntimeLevel level)
{
InstallAreaRoutes routes = GetInstallAreaRoutes(level);
var endpoints = new TestRouteBuilder();
routes.CreateRoutes(endpoints);
Assert.AreEqual(0, endpoints.DataSources.Count);
}
[TestCase(RuntimeLevel.Install)]
[TestCase(RuntimeLevel.Upgrade)]
public void RuntimeState_Install(RuntimeLevel level)
{
InstallAreaRoutes routes = GetInstallAreaRoutes(level);
var endpoints = new TestRouteBuilder();
routes.CreateRoutes(endpoints);
Assert.AreEqual(2, endpoints.DataSources.Count);
EndpointDataSource route = endpoints.DataSources.First();
Assert.AreEqual(2, route.Endpoints.Count);
var endpoint1 = (RouteEndpoint)route.Endpoints[0];
Assert.AreEqual($"install/api/{{action}}/{{id?}}", endpoint1.RoutePattern.RawText);
Assert.AreEqual(Constants.Web.Mvc.InstallArea, endpoint1.RoutePattern.Defaults[AreaToken]);
Assert.AreEqual("Index", endpoint1.RoutePattern.Defaults[ActionToken]);
Assert.AreEqual(ControllerExtensions.GetControllerName<InstallApiController>(), endpoint1.RoutePattern.Defaults[ControllerToken]);
Assert.AreEqual(endpoint1.RoutePattern.Defaults[AreaToken], 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[AreaToken]);
Assert.AreEqual("Index", endpoint2.RoutePattern.Defaults[ActionToken]);
Assert.AreEqual(ControllerExtensions.GetControllerName<InstallController>(), endpoint2.RoutePattern.Defaults[ControllerToken]);
Assert.AreEqual(endpoint2.RoutePattern.Defaults[AreaToken], typeof(InstallController).GetCustomAttribute<AreaAttribute>(false).RouteValue);
EndpointDataSource fallbackRoute = endpoints.DataSources.Last();
Assert.AreEqual(1, fallbackRoute.Endpoints.Count);
Assert.AreEqual("Fallback {*path:nonfile}", fallbackRoute.Endpoints[0].ToString());
}
[Test]
public void RuntimeState_Run()
{
InstallAreaRoutes routes = GetInstallAreaRoutes(RuntimeLevel.Run);
var endpoints = new TestRouteBuilder();
routes.CreateRoutes(endpoints);
Assert.AreEqual(1, endpoints.DataSources.Count);
EndpointDataSource route = endpoints.DataSources.First();
Assert.AreEqual(1, route.Endpoints.Count);
Assert.AreEqual("install/{controller?}/{action?} HTTP: GET", route.Endpoints[0].ToString());
}
private InstallAreaRoutes GetInstallAreaRoutes(RuntimeLevel level) =>
new InstallAreaRoutes(
Mock.Of<IRuntimeState>(x => x.Level == level),
Mock.Of<IHostingEnvironment>(x => x.ToAbsolute(It.IsAny<string>()) == "/install" && x.ApplicationVirtualPath == string.Empty),
Mock.Of<LinkGenerator>());
}
}