Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Controllers/RenderNoContentControllerTests.cs
Nikolaj Geisle 7aeb400fce V10: fix build warnings in test projects (#12509)
* Run code cleanup

* Dotnet format benchmarks project

* Fix up Test.Common

* Run dotnet format + manual cleanup

* Run code cleanup for unit tests

* Run dotnet format

* Fix up errors

* Manual cleanup of Unit test project

* Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Fix according to review

* Fix after merge

* Fix errors

Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk>
Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
Co-authored-by: Zeegaan <nge@umbraco.dk>
2022-06-21 08:09:38 +02:00

67 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.Web;
using Umbraco.Cms.Tests.Common;
using Umbraco.Cms.Web.Website.Controllers;
using Umbraco.Cms.Web.Website.Models;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Website.Controllers;
[TestFixture]
public class RenderNoContentControllerTests
{
[Test]
public void Redirects_To_Root_When_Content_Published()
{
var mockUmbracoContext = new Mock<IUmbracoContext>();
mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(true);
var mockHostingEnvironment = new Mock<IHostingEnvironment>();
var controller = new RenderNoContentController(
new TestUmbracoContextAccessor(mockUmbracoContext.Object),
new TestOptionsSnapshot<GlobalSettings>(new GlobalSettings()),
mockHostingEnvironment.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 = "~/umbraco";
const string umbracoPath = "/umbraco";
const string viewPath = "~/config/splashes/NoNodes.cshtml";
var mockUmbracoContext = new Mock<IUmbracoContext>();
mockUmbracoContext.Setup(x => x.Content.HasContent()).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
{
UmbracoPath = umbracoPathSetting,
NoNodesViewPath = viewPath,
});
var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), globalSettings, mockHostingEnvironment.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);
}
}