Files
Nicklas Kramer 2a6bb64c78 V17 - Properties and validators, removing obsoleted code (#19961)
* Removing obsoleted code from ApiMediaQueryService.cs

* Removing obsoleted code from ApiRichTextMarkupParserTests.cs

* Removing obsoleted code from ContentCacheRefresher.cs

* Removing obsoleted code from ContentFinderByUrlAlias.cs and adjusting its tests to use the new logic

* Removing obsoleted code from ContentFinderByUrl.cs & its dependencies

* Removing obsoleted code from ApiRichTextMarkupParserTests.cs

* Removing obsoleted code from DocumentCache.cs & its dependencies

* Removing obsoleted code from MediaCache.cs & its dependencies

* Removing obsoleted code from PublishedCacheBase.cs & its dependencies

* Removing obsoleted code from RenderNoContentController.cs and its tests

* Removing obsoleted code from UmbracoRouteValueTransformer.cs

* Removing obsoleted constructors from DefaultUrlProvider.cs

* Removing the RadioValueEditor.cs & RadioValueValidator.cs obsoleted classes.

* Removing obsolete constructor from MultipleValueValidator.cs

* Removing obsolete constructor from EmailValidator.cs

* Removing obsoleted code from DataValueReferenceFactoryCollection.cs

* Removing obsoleted code from ApiContentBuilderBase.cs

* Fixing constructor missing attribute

* Making use of the TryGet result

* Fixing use of obsoleted constructor

* Removing silly bookmark comment

* Fixing deleted code and restructuring to use new cache

* Making use of TryGetRootKeys bool, to return null if false.

* Extending code to use new constructor

* Updated PublishedContentQuery.cs to return empty array

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>

---------

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>
2025-08-26 11:31:27 +00:00

68 lines
2.5 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Tests.Common;
using Umbraco.Cms.Web.Website.Controllers;
using Umbraco.Cms.Web.Website.Models;
using Constants = Umbraco.Cms.Core.Constants;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Website.Controllers;
[TestFixture]
public class RenderNoContentControllerTests
{
[Test]
public void Redirects_To_Root_When_Content_Published()
{
var mockUrlService = new Mock<IDocumentUrlService>();
mockUrlService.Setup(x => x.HasAny()).Returns(true);
var mockHostingEnvironment = new Mock<IHostingEnvironment>();
var controller = new RenderNoContentController(
mockHostingEnvironment.Object,
new TestOptionsSnapshot<GlobalSettings>(new GlobalSettings()),
mockUrlService.Object);
var result = controller.Index() as RedirectResult;
Assert.IsNotNull(result);
Assert.AreEqual("~/", result.Url);
}
[Test]
public void Renders_View_When_No_Content_Published()
{
const string umbracoPathSetting = Constants.System.DefaultUmbracoPath;
const string umbracoPath = "/umbraco";
const string viewPath = "~/config/splashes/NoNodes.cshtml";
var mockUrlService = new Mock<IDocumentUrlService>();
mockUrlService.Setup(x => x.HasAny()).Returns(false);
var mockIOHelper = new Mock<IIOHelper>();
mockIOHelper.Setup(x => x.ResolveUrl(It.Is<string>(y => y == umbracoPathSetting))).Returns(umbracoPath);
var mockHostingEnvironment = new Mock<IHostingEnvironment>();
mockHostingEnvironment.Setup(x => x.ToAbsolute(It.Is<string>(y => y == umbracoPathSetting)))
.Returns(umbracoPath);
var globalSettings = new TestOptionsSnapshot<GlobalSettings>(new GlobalSettings
{
NoNodesViewPath = viewPath,
});
var controller = new RenderNoContentController(mockHostingEnvironment.Object, globalSettings, mockUrlService.Object);
var result = controller.Index() as ViewResult;
Assert.IsNotNull(result);
Assert.AreEqual(viewPath, result.ViewName);
var model = result.Model as NoNodesViewModel;
Assert.IsNotNull(model);
Assert.AreEqual(umbracoPath, model.UmbracoPath);
}
}