Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Routing/PreviewRoutesTests.cs
Nikolaj Geisle 595ee242aa V14: Remove old backoffice project. (#15752)
* Move magical route to management api

* Move auth around

* Remove "New" cookies, as they are no longer needed

* Move all installer related

* Remove BackOfficeServerVariables.cs and trees

* Move webhooks to management api

* Remove remainting controllers

* Remove last services

* Move preview to management api

* Remove mroe extensions

* Remove tours

* Remove old Auth handlers

* Remove server variables entirely

* Remove old backoffice controller

* Remove controllers namespace entirely

* Move rest of preview

* move last services

* Move language file extension

* Remove old backoffice entirely (Backoffice and Web.UI projects)

* Clean up unused security classes

* Fix up installer route

* Remove obsolete tests

* Fix up DI in integration test

* Add missing property mapping

* Move core mapping into core

* Add composers to integration test

* remove identity

* Fix up DI

* Outcomment failing test :)

* Fix up remaining test

* Update mapper

* Remove the actual project files

* Remove backoffice cs proj

* Remove old backoffice from yml

* Run belissima before login

* Remove caching

* Refactor file paths

* Remove belle from static assets

* Dont refer to old project in templates

* update gitignore

* Add missing files

* Remove install view as its no longer used

* Fix up failing test

* Remove outcommented code

* Update submodule to latest

* fix build

---------

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2024-02-27 12:40:30 +01:00

65 lines
2.2 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Options;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Api.Management.Controllers.Preview;
using Umbraco.Cms.Api.Management.Routing;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Services;
using Umbraco.Extensions;
using static Umbraco.Cms.Core.Constants.Web.Routing;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.Routing;
[TestFixture]
public class PreviewRoutesTests
{
[TestCase(RuntimeLevel.BootFailed)]
[TestCase(RuntimeLevel.Unknown)]
[TestCase(RuntimeLevel.Boot)]
public void RuntimeState_No_Routes(RuntimeLevel level)
{
var routes = GetRoutes(level);
var endpoints = new TestRouteBuilder();
routes.CreateRoutes(endpoints);
Assert.AreEqual(0, endpoints.DataSources.Count);
}
[TestCase(RuntimeLevel.Run)]
[TestCase(RuntimeLevel.Upgrade)]
[TestCase(RuntimeLevel.Install)]
public void RuntimeState_All_Routes(RuntimeLevel level)
{
var routes = GetRoutes(level);
var endpoints = new TestRouteBuilder();
routes.CreateRoutes(endpoints);
Assert.AreEqual(1, endpoints.DataSources.Count);
var route = endpoints.DataSources.First();
Assert.AreEqual(2, route.Endpoints.Count);
var endpoint0 = (RouteEndpoint)route.Endpoints[0];
Assert.AreEqual($"{routes.GetPreviewHubRoute()}/negotiate", endpoint0.RoutePattern.RawText);
var endpoint1 = (RouteEndpoint)route.Endpoints[1];
Assert.AreEqual($"{routes.GetPreviewHubRoute()}", endpoint1.RoutePattern.RawText);
}
private PreviewRoutes GetRoutes(RuntimeLevel level)
{
var globalSettings = new GlobalSettings();
var routes = new PreviewRoutes(
Options.Create(globalSettings),
Mock.Of<IHostingEnvironment>(x =>
x.ToAbsolute(It.IsAny<string>()) == "/umbraco" && x.ApplicationVirtualPath == string.Empty),
Mock.Of<IRuntimeState>(x => x.Level == level));
return routes;
}
}